time.mktime(tuple)とすると、ローカルタイムで解釈されるので、9時間ずれる。。。 色々ググって
calendar.timegm(tuple)とするといいということがわかった。これはGMTで解釈してくれるので大丈夫、とのこと。 しかし、なんだかなあ。。Javaのように、epochからのミリ秒表現をコアにするほうが合理的だと おもうのだが。
技術系の備忘録.基本的に自分だけのためのものなので,詳しく書きません.検索でいらした方、すみません.
time.mktime(tuple)とすると、ローカルタイムで解釈されるので、9時間ずれる。。。 色々ググって
calendar.timegm(tuple)とするといいということがわかった。これはGMTで解釈してくれるので大丈夫、とのこと。 しかし、なんだかなあ。。Javaのように、epochからのミリ秒表現をコアにするほうが合理的だと おもうのだが。
sudo route add 192.168.1.0/24 -interface vmnet8とかやればいい。 恒久的に変更するには、
sudo mkdir /Library/StartupItems/AddRouteここに二つファイルをつくる。
{
Description = \"Add static routing tables\";
Provides = (\"AddRoutes\");
Requires = (\"Network\");
OrderPreference = \"None\";
}
#!/bin/sh
. /etc/rc.common
StartService ()
{
ConsoleMessage "Adding Static Routing Tables"
sudo route add 192.168.1.0/24 -interface vmnet8
}
StopService ()
{
return 0
}
RestartService ()
{
return 0
}
RunService "$1"
これに実行権限を与えておく。
sudo chmod +x /Library/StartupItems/AddRoute/AddRoutes
# -*- coding: utf-8 -*-
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate
import getpass
def create_message(from_addr, to_addr, subject, body, encoding):
msg = MIMEText(body, 'plain', encoding)
msg['Subject'] = Header(subject, encoding)
msg['From'] = from_addr
msg['To'] = to_addr
msg['Date'] = formatdate()
return msg
def send_via_gmail(from_addr, to_addr, msg, passwd):
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(from_addr, passwd)
s.sendmail(from_addr, [to_addr], msg.as_string())
s.close()
if __name__ == '__main__':
from_addr = 'hoge@gmail.com'
to_addr = 'target@example.com'
passwd=getpass.getpass("password for %s:" % (from_addr))
msg = create_message(from_addr, to_addr, u'テスト', u'本文', 'ISO-2022-JP')
send_via_gmail(from_addr, to_addr, msg, passwd)
create keyspace usertable
with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options = {replication_factor:1};
use usertable;
create column family data;
このようなファイルをsetup.cas として用意しておいて
> cassandra-cli -h localhost -p 9160 -f setup.casとすればよい。
#!/bin/sh ffmpeg -i $1 -s 480x270 -vcodec libx264 -b 100k -strict experimental -acodec aac -ac 2 -ar 48000 -ab 64k -coder 0 -level 13 -nr 50 -threads 2 $2-b が動画ビットレート、-ab が音声ビットレート。これは、某レクチャーを見るためなので極端に低くしている。普通の映画とかならもっと高めにしないと駄目。
import signal
import time
class timer():
def __init__(self):
self.flag = True
def _handler(self, x, y):
self.flag = False
def set(self, sec):
signal.signal(signal.SIGALRM, self._handler)
signal.alarm(sec)
def check(self):
return self.flag
if __name__ == "__main__":
tmr = timer()
tmr.set(3)
while tmr.check():
time.sleep(100)
> bin/hadoop namenode -format > bin/start-all.shでOK. namenode のフォーマットをしないでstart-allするとnamenodeが起動しないので要注意。
> jps 6724 17758 DataNode 17969 Jps 17958 TaskTracker 17833 SecondaryNameNode 17683 NameNode 17885 JobTrackerとかなって、4つのデーモンが全部立ってればOK.
$ sudo systemsetup -setkernelbootarchitecture x86_64
$ sudo systemsetup -setkernelbootarchitecture i386
xxx.class = yyy;という表現がパースエラーになっていた。
xxx["class"] = yyy;ならOK。'class'がキーワードになってるとか? わけわからん。 ちなみにSafariのDevelop メニューを出すにはコンソールで次のようにする。
defaults write com.apple.Safari IncludeDebugMenu 1
# -*- coding: utf-8 -*-
import gdata.photos.service
import gdata.media
import gdata.geo
import getpass
import sys
email="YOUR_GMAIL_ADDRESS"
#
password=getpass.getpass("password for %s:" % (email))
albumname = sys.argv[1]
gd_client = gdata.photos.service.PhotosService()
gd_client.email = email
gd_client.password = password
gd_client.source = 'exampleCo-exampleApp-1'
gd_client.ProgrammaticLogin()
username=email
albumid = ""
albums = gd_client.GetUserFeed(user=username)
for album in albums.entry:
if album.title.text == albumname:
albumid = album.gphoto_id.text
photos = gd_client.GetFeed(
'/data/feed/api/user/%s/albumid/%s?kind=photo' % (
username, albumid))
for photo in photos.entry:
print '<tr><td><a href="%s"><img src="%s"/></a></td><td>' % (photo.content.src, photo.media.thumbnail[-1].url)
print '%s\n</td></tr>' % (photo.summary.text)
http://komugi.net/archives/2010/08/04212446で、こちらを参考に2.3を導入。
http://rhp.ninja-x.jp/review/Gingerbread/install.htmlありがたいことだなあ。
static private int getPid() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder();
pb.command("/bin/sh", "-c", "echo $PPID");
Process p = pb.start();
p.waitFor();
String str = (new LineNumberReader(new InputStreamReader(p.getInputStream()))).readLine();
return Integer.parseInt(str);
}
$ e2label /dev/sdb1 /repo/etc/fstab でそれを参照。
LABEL=/repo /repo ext2 defaults 1 2
LANG=C xdg-user-dirs-gtk-update
$ sbt Project does not exist, create new project? (y/N/s) s Getting Scala 2.7.7 ... :: retrieving :: org.scala-tools.sbt#boot-scala confs: [default] 2 artifacts copied, 0 already retrieved (9911kB/281ms) Getting org.scala-tools.sbt sbt_2.7.7 0.7.4 ... :: retrieving :: org.scala-tools.sbt#boot-app confs: [default] 15 artifacts copied, 0 already retrieved (4096kB/385ms)
> set.scala.versions 2.8.1 > reloadこうすると2.8.1のコンパイラをとりに行ってくれる。べんりー。
import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) {
val scalaTest = "org.scalatest" % "scalatest" % "1.3"
}
で、reload, update とやる。
> reload [info] Recompiling project definition... [info] Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed. [info] Building project test 1.0 against Scala 2.8.1 [info] using MyProject with sbt 0.7.4 and Scala 2.7.7 > update [info] [info] == update == [info] downloading http://scala-tools.org/repo-releases/org/scalatest/scalatest/1.3/scalatest-1.3.jar ... [info] [SUCCESSFUL ] org.scalatest#scalatest;1.3!scalatest.jar (4751ms) [info] :: retrieving :: test#test_2.8.1 [sync] [info] confs: [compile, runtime, test, provided, system, optional, sources, javadoc] [info] 1 artifacts copied, 0 already retrieved (1755kB/116ms) [info] == update == [success] Successful. [info] [info] Total time: 8 s, completed Mar 21, 2011 10:41:05 PMレポジトリから自動的にライブラリをダウンロードしている。すごいなー。
import gdata.photos.service
import gdata.media
import gdata.geo
email=xxxxx
password=xxxx
gd_client = gdata.photos.service.PhotosService()
gd_client.email = email
gd_client.password = password
gd_client.source = 'exampleCo-exampleApp-1'
gd_client.ProgrammaticLogin()
username="tohoku.anpi"
albums = gd_client.GetUserFeed(user=username)
for album in albums.entry:
print 'title: %s, number of photos: %s, id: %s' % (album.title.text,
album.numphotos.text, album.gphoto_id.text)
photos = gd_client.GetFeed(
'/data/feed/api/user/%s/albumid/%s?kind=photo' % (
username, album.gphoto_id.text))
for photo in photos.entry:
comments = gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s/photoid/%s?kind=comment&max-results=10' % (username, album.gphoto_id.text, photo.gphoto_id.text))
if len(comments.entry) < 2:
print 'Photo title:', photo.title.text, len(comments.entry)
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create("hdfs://localhost:9000/"), conf);
for (FileStatus status: fs.listStatus(new Path(dirname), filter)) {
InputStream is = fs.open(status.getPath());
ObjectInputStream ois = new ObjectInputStream(is);
Object o = ois.readObject();
System.out.println(o);
}
filter はこんな風に取得。filePrefix に指定した文字を含むファイルを選ぶ。この実装だとprefix になってないけど。
static PathFilter getPathFilter(final String filePrefix){
PathFilter filter = new PathFilter() {
public boolean accept(Path path) {
return path.getName().contains(filePrefix);
}
};
return filter;
}
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create("hdfs://localhost:9000/"), conf);
for (FileStatus status: fs.listStatus(new Path(dirname), filter)) {
SequenceFile.Reader reader = new SequenceFile.Reader(fs, status.getPath(), conf);
Text key = new Text();
Text value = new Text();
while (reader.next(key, value){
....
}
}
この読み方は、ValueがWritableの時にしか使えない。Serializable の場合はつぎのようにする。
nextでkeyだけ読んで、getCurrentValueでvalueを読む。このときにconfにJavaSerializationを追加しておかないと、エラーになるので注意。
Configuration conf = new Configuration();
conf.set("io.serializations",
JavaSerialization.class.getName() + "," +
WritableSerialization.class.getName());
FileSystem fs = FileSystem.get(URI.create("hdfs://localhost:9000/"), conf);
for (FileStatus status: fs.listStatus(new Path(dirname), filter)) {
SequenceFile.Reader reader = new SequenceFile.Reader(fs, status.getPath(), conf);
Text key = new Text();
while (reader.next(key)){
System.out.println(key.toString());
ChlacTest.Result res = new ChlacTest.Result();
res = (Result) reader.getCurrentValue(res);
System.out.println(String.format("%d %d %f", res.rx, res.time_frame, res.alpha));
}
}
$ curl "http://maps.google.com/maps/geo?q=千代田区外神田"
{
"name": "千代田区外神田",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Japan, Tokyo Chiyoda外神田",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "東京都",
"Locality" : {
"DependentLocality" : {
"DependentLocalityName" : "外神田"
},
"LocalityName" : "千代田区"
}
},
"CountryName" : "日本",
"CountryNameCode" : "JP"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 35.7100074,
"south": 35.6918852,
"east": 139.7856097,
"west": 139.7215803
}
},
"Point": {
"coordinates": [ 139.7535951, 35.6940027, 0 ]
}
} ]
}
public static class R1 extends Reducer{ public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { context.write(key, values.iterator().next()); Path path = FileOutputFormat.getWorkOutputPath(context); Path fpath = new Path(path, "sidefile" + key.toString()); OutputStream os = fpath.getFileSystem(context.getConfiguration()).create(fpath); PrintWriter pw = new PrintWriter(new OutputStreamWriter(os)); pw.println("hello"); pw.flush(); pw.close(); os.close(); } }
escape ^z^z
Configuration conf = new Configuration();
conf.set("io.serializations",
org.apache.hadoop.io.serializer.JavaSerialization.class.getName() + "," +
org.apache.hadoop.io.serializer.WritableSerialization.class.getName());
要するにSerialization クラスをカンマで区切って、
io.serializations にセットするのだけど、JavaSerialization だけだと、Textとかが
デコードできなくなっちゃうので、デフォルトのWritableSerialization も書いておくこと。