header

2013年3月31日日曜日

node.jsでEmacsからjavascriptを実行するelispを書いてみた。

node.jsの本を読んでいてふとEmacsからnode.jsでjavascriptを実行できたら便利と思いelispを書いてみました。popwin.elが必要です。それとv8-optionをhelmで表示するようにしたのでhelmもあると便利かもしれません。

インストール

el-getを利用していれば以下のコードでel-get-installできると思います。
もし利用していなければ、git cloneでクローンしてロードパスを通してください。

(app-to-list 'el-get-sources
(:name node-console
:type git
:url "https://github.com/yuutayamada/node-console"
:load-path "./"))


ロードパスを通したら、以下のコードを.emacsなどに設定します。
js2-modeの部分は利用しているjavascript-modeのメジャーモード名に変えてください。
またキーバインドも好きなものに変えてください。

(require 'node-console)
(eval-after-load "js2-mode"
'(progn
(define-key js2-mode-map (kbd "C-c C-c") 'node-console)))

利用法

node-consoleコマンド

nodeで-eオプションでコマンドの実行ができるので、Emacsで範囲選択している場合、
その範囲を実行します。
範囲選択していない場合は、そのバッファが.jsで終わる名前かnode-console-javascript-modeで指定したmajar-mode名の場合そのファイルをnodeで実行します。

C-uを押したあとnode-consoleコマンドを実行すると

helmで指定できるv8-optionsを表示します。
node-console-v8-optionsで何かしていれば色が変わります。
アクションを実行するとそのoptionのつけはずしができます。
helmでなんかやってみたかっただけなので、ちょっと微妙です。
optionを見るのにはいいかも。。。

TODO

NODE_ENVとかNODE_PATHとか読み込んだほうがいいのか迷い中。
http://d.hatena.ne.jp/Jxck/20120410/1334071898 このサイト見るとpackage.jsonの
中のscriptに書く場合もあるもよう。
node.jsやjavascriptの習慣に疎いので、よくわからにゃい。。。


2013年3月26日火曜日

google readerからEmacs Newstickerに移行

google readerが7月から使えなくなるそうなので,とりあえずデータの
エクスポートとEmacsのnewstickerで利用できるようにしてみました。

google readerの購読しているサイトのエクスポート

google readerのサイトから,設定(歯車マーク)を選んでから
inport/exportみたいなタブをクリックしてデータをエクスポートします。

Emacsの設定ファイルに書込み

ダウンロードしたデータはunzipコマンドで解凍します。
解凍したファイルの中の
"~/Downloads/your gmail address-takeout/Reader/subscriptions.xml"
のようなxmlファイルからURLのリストを作成します。
次のコードをスクラッチに貼り付けするなどして評価してください。

(defun my/create-url-list (choice file)
(interactive)
(let* ((all (xml-parse-file file))
(body (xml-get-children (car all) 'body))
(outlines (loop for attr in (cddar body)
if (listp attr)
collect attr)))
(loop with dq = (if (eq choice :string)
"\\\\\""
"\"")
for atr in outlines
for title = (replace-regexp-in-string
"\"" dq (xml-get-attribute atr 'title))
for xmlurl = (xml-get-attribute atr 'xmlUrl)
for htmlurl = (xml-get-attribute atr 'htmlUrl)
for url = (or xmlurl htmlurl)
for result = (list title url)
if (string< "" url)
collect (case choice
(:list result)
(:string
(concat "(" "\"" title "\"" "\n"
"\"" url "\"" ")"))))))


次にあなたのsubscriptions.xmlの置いてあるところに変更して
下のコードを評価してください

(setq newsticker-url-list
(my/create-url-list :list
"~/Downloads/YOUR-ADDRESS@gmail.com-takeout/Reader/subscriptions.xml"))

newstickerの起動

newsticker-url-listにURLが反映されたら、
M-x newsticker-treeveiwコマンドを実行すると追加したフィードが反映され
newstickerが起動すると思います。
もし、文字列でほしい場合は下のコードを利用すると文字列を挿入できます。

(defun my/url-insert (pairs)
(interactive)
(loop for title-and-url in pairs
do (insert (concat title-and-url "\n"))))

(my/url-insert
(my/create-url-list :string "/path/to/subscriptions.xml"))

emacsclientを使い始めました

最近emacsclientを使い出しました。
いい感じに動くようになったのでその時のメモ。

.bashrcや.zshrcに起動用の関数とaliasを登録

-q なしでも最初は動いていたのですが、ある日
"back to top level"というメッセージが表示されつづける不具合が出て
emacsclient難民になっていましたが、ここから 同じ問題になったときは
-q をつけるようにしてeval-bufferを使えというのをみました。
–evalオプションしても同じと思い、自分の設定ファイルを読みこむようにしました。
読み込むファイルはお好みで変えてください。

myemacsclient() {
local sexp='(load "~/.emacs.d/init")'
local emacsclient='emacsclient' #24.3.5: emacsclient.emacs-snapshot
local lang='LANG=ja_JP.UTF-8 '
local daemon='emacs --reverse --daemon -q' #24.3.5: emacs-snapshot
if ! pgrep -lf ${daemon} >/dev/null 2>&1; then
echo "start emacs daemon"
eval ${lang}${daemon} && ${emacsclient} -n -c --eval ${sexp}
else
if [ "$*" != "" ]; then
${emacsclient} -n -c $*
else
${emacsclient} -n -c
fi
fi
}

alias c="myemacsclient"

使用感

元々Emacsは起ち上げっぱなしがおおかったので、特に便利になったという感じではないのですが一度立ち上げておけば次回の起動はほぼ一瞬なので俺のEmacs超速いと錯覚できます。僕は"C-x C-c"をemacsclient用に少し変更しました。C-x C-cでEmacsを終了するけどdaemonは残す、C-u C-x C-cでEmacsとdaemonも終了するようにしました。

(when (daemonp)
(defalias 'exit 'save-buffers-kill-emacs)
(global-set-key (kbd "C-x c") 'suspend-frame)
(global-set-key (kbd "C-x C-c") '(lambda ()
(interactive)
(if current-prefix-arg
(save-buffers-kill-emacs)
(save-buffers-kill-terminal))))
;;emacsclient -cでアクセス時の設定
(add-hook 'server-visit-hook
(lambda ()
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8))))

2013年3月22日金曜日

Adult School 3/21

Lesson of Adult school on March 21.

Dictation

Dictate from teacher's spoken sentence and create question sentence from underline sentence.(D=dictated sentence, Q=question sentence)

  1. D: Sally went to Hawaii to visit a friend.
    Q: Where did Sally go to visit a friend?
  2. D: Jason grew corn and tomatoes in his garden last year.
    Q: What did grow Jason in his garden last year?
  3. D: I will hang my certificate on the living room wall.
    Q: Where will you hang certificate?
  4. D: We're going to have a party tomorrow.
    Q: When are you going to have a party?
  5. D: That baseball player hasn't hit a ball recently.
    Q: What hasn't that baseball player done recently?
  6. D: I haven't held my friend's puppy yet.
    Q: What haven't you held yet?
  7. D: Robert's back harts because he was lifting heavy boxes.
    Q: Why does Robert's back hart?
  8. D: Maria knows how to make tamales.
    Q: What does Maria know how to do?
    (tamale: it's Mexican traditional food)
  9. D: We are leaving for the train station now.
    Q: Where are you leaving for now?
  10. D: They are letting us have some free time today.
    Q: What are they letting you have today?

Ask each other

Ask each other about below sentences.
(-> equal my answer)

  1. What do you want to do today?
    -> I want to make diner today.(but it's lie)
  2. What did you go last weekend?
    -> I went to Santa Monica beach.(but actually it's two weeks ago)
  3. What did you see there?
    -> I saw many performer in the place. For example mocked Mickey Mouse, singer and rice painter etc..
  4. Did you like it there?
    -> Yes I did.
  5. What are you going to do on the vacation?
    -> I'm going to cook curry.
  6. Have you ever gone to go SOMEPLACE?
    (SOMEPLACE is changed to Las Vegas or Mexico etc. when I ask other students)
    -> Yes, I have, I went to SOMEPLACE.
    -> No, I haven't, I haven't ever gone SOMEPLACE
    I was asked other student "Have you ever gone to carnival in Brazil?".
    Of course I said "No, I haven't, …"
    ※ other student ask teacher about the "gone" of No6, he said "why doesn't the gone change to the been?", teacher said "the been is informal, but it's ok. you can use the been"

2013年3月21日木曜日

Adult School 3/20

Lesson of Adult school on March 20.

Dictation

dictate from teacher's spoken sentence and create question sentence from underline sentence.(D=dictated sentence, Q=question sentence)

  1. D: Huck has already driven his truck to the mountains.
    Q: Where has Huck already driven his truck?
  2. D: Maria has just bought some new wool cushions for the sofa.
    Q: Why has Maria just bought some new wool cushions?
  3. D: Robert read his favorite book last weekend.
    Q: When did Robert read his favorite book?
  4. D: Susan put some sugar in the pot yesterday morning.
    Q: What did Susan put in the pot yesterday morning?
  5. D: Sam gets his things from his trunk every morning
    Q: When does Sam get his things from his trunk?
  6. D: Tanya plugs the crock pot in before work everyday.
    Q: What does Tanya plug in before work everyday?
  7. D: We will open the hood of the truck to change the oil
    Q: Why will you open the hood of the truck?
  8. D: The teacher is going to push you a little to come everyday.
    Q: Why is the teacher going to push you a little?
  9. D: Bill is spending ten bucks at swap meet now.
    Q: What is Bill spending at swap meet now?
  10. D: I'm tacking your composition on the board for the principal to see.
    Q: What are you doing for the principal to see?

Writing Test

I tested for writing test today.(level 3-C?)

Ask each other

  1. Who do you live with?
  2. How many brother do you have?
  3. Where do they live?
  4. Are you a parent or grand parent?
  5. How old is he/she?
    How old are you/they?
  6. Are you a parent or grand parent?
  7. How old are they?
    How old is he/she?
  8. What does your family do on holidays?
  9. What are their names?
  10. Why don't you have any children?
  11. Tell me more about your relatives

2013年3月19日火曜日

herokuにNode.jsのアプリを登録

ちょっとNode.jsに興味があってherokuにNode.jsのアプリを登録してみました。
以下は自分の忘れ防止

herokuのアカウントを作成

  1. http://api.heroku.com/signup から新規にアカウントを作成
  2. Email,passwordを選択

herokuのtoolbeltをインストール

herokuの toolbelt をインストールするのになんかコマンドがかかれてたのでコピペで実行
そのあと heroku コマンドが利用できるようになった。

sshの鍵の登録

githubやbitbucketで鍵をわけて利用していたので,heroku用に鍵を作成
私はパスフレーズを登録しました。

mkdir -p ~/.ssh/heroku
cd ~/.ssh/heroku
ssh-keygen -t rsa -C "Mail Addless"


それと~/.ssh/configに以下を追加しました。
(IdentityFileは秘密鍵の場所)

Host heroku
HostName heroku.com
IdentityFile ~/.ssh/path/to/heroku/secret-key_id_rsa
User git

heroku

  1. heroku loginでアカウント情報を入力
    heroku loginでアカウント情報を入力
    sshの鍵は次で登録するのでNoにしました。



    heroku login
  2. heroku keys:addでheroku用のsshの公開鍵を登録



    heroku keys:add file-path(作成したid_rsa.pubのような公開鍵の方のパス)

herokuへpushするとき

普通にpushするには


ssh-add heroku's_secret_key
git push heroku master

でいいと思います。そのあと対象のディレクトリで


heroku open

でそのアプリをブラウザで開けました。

Emacsからpush

私はEmacsでmagitからpushしたかったので下記のコードを.emacsなどの設定ファイルに
追加しました。(ssh-agentが動いていることも必要です)

(defun my/ssh-add ()
(interactive)
(let* ((github "~/path/to/github's_id_rsa")
(bitbucket "~/path/to/bitbucket's_id_rsa")
(heroku "~/path/to/heroku's_id_rsa")
(ssh-add
(lambda (filepath)
(unless (string< "" (shell-command-to-string
(concat "ssh-add -l | grep " filepath)))
(shell-command (concat "ssh-add " filepath)))))
match)
(goto-char (point-min))
(when (search-forward-regexp
"^Remote: master @ .* (\\(.*\\))" nil t)
(setq match (match-string 0))
(when (string-match "@bitbucket.org" match)
(funcall ssh-add bitbucket))
(when (string-match "git@github.com" match)
(funcall ssh-add github))
(when (string-match "git@heroku.com" match)
(funcall ssh-add heroku)))))
(defadvice magit-push
(around ad-magit-push activate)
(my/ssh-add)
ad-do-it)


アプリの/.git/configにbranchの設定を追加しました。
追加後magitでcommitしたところpush待ちのものが見れるようになりました。

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "heroku"]
url = git@heroku.com:YOUR-APPLICATION-NAME.git
fetch = +refs/heads/*:refs/remotes/heroku/*
[branch "master"]
remote = heroku
merge = refs/heads/master


あとはmagit-statusから"P","P"すればpushしてくれるはずです。


2013年3月7日木曜日

Adult School 3/6

Lesson of Adult school on March 6th.

Dictation

dictate from teacher's spoken sentence and create question sentence from underline sentence.

  1. We haven't eatan any beans since we were an on the ship.
    -> What haven't you eaten since you were on the ship?
  2. Susan fell on the hill while wearing heels.
    -> Where did Susan fall while wearing heels?
  3. John gave us a feast with chips and peach dip.
    -> What did John give you?
  4. The baby's cheeks are soft like a chick.
    -> How are the baby's cheeks?
  5. That sheep bit my fist when I tried to feed it.
    -> When did that sheep bite your fist?
  6. Maria bought a new slip last week
    -> What did Maria buy last week?
  7. You can put the rug in the bin after you beat it.
    -> What did Robert have when he was sick?
  8. Robert had a deep sleep when he was sick
    -> What did Robert have when he was sick?
  9. Sam asked me to light the candle wick.
    -> What did Sam ask you to do?
  10. We need to fix the wheel on that bin.
    -> What do you need to fix?

Conversation

Example:


Am I working fast enough?
Actually, you should work faster.

converse each other

  1. Am I typing quickly enough?
    -> Actually, you should type quicker.
  2. Am I dancing gracefully
    -> Actually, you should dance more gracefully.
  3. Am I speakings loud enough?
    -> Actually, you should speak louder.
  4. Am I driveing slowly enough?
    -> Actually you should drinhve slower.
  5. Am I translating accurately enough?
    -> Actually you should translate more accurately.
  6. Am I palying well enough?
    -> Actually you should play better

memo

comparative example

fast -> faster
quickly -> quicker
loud(ly) -> louder
slowly -> slower
long word is added the more
carefully -> more carefully
chgracefully -> more gracefully
accurately -> more accurately

Adult School 3/5

Lesson of Adult school on March 5th.

Memorize how to spell a word

dodiddone
drawdrewdrawn
drinkdrankdrunk
drivedrovedriven
eatateeaten
fallfellfallen
feedfedfed
flyflewflown
getgotgotten
givegavegiven

Create sentences

Create sentence from below box and Create question sentence from box.
and you need to obey next rules.
the box 1 is to use PRESENT CONTINUOUS.
the box 2 is to use SIMPLE PRESENT.
the box 3 is to use FUTURE.
the box 4 is to use PAST.
the box 5 is to use PRESENT PERFECT.

Parson1. do2. draw3. drink4. drive5. eat
Jessicaher homeworksome facessome orenge juiceto Las Vegassome junk food
Josethe laundrya picturesome waterto San Franciscoa hamburger
Ednaher taxesa flowersome milkto the mountainssome tomates
Saulhis exercisesan animalsome wineto the beachsome pasta
Jessica
  1. Jessica is doing her homework now.
    -> What is Jessica doing now?
  2. Jessica draws some faces every moning.
    -> What does Jessica do every morning?
  3. Jessica is going to drink some orange juice this afternoon.
    -> What is Jessica going to drink this afternoon?
  4. Jessica drove to Las Vegas last weekend.
    -> Where did Jessica drive last weekend?
  5. Jessica has just eaten some junk food.
    -> What has Jessica just eaten?
Jose
  1. Jose is doing the laundry right now.
    -> What is Jose doing right now?
  2. Jose draws a picture everyday.
    -> What does Jose draw everyday?
  3. Jose is going to drink some water tomorrow.
    -> What is Jose going to drink tomorrow?
  4. Jose drove to San Francisco last month.
    -> Where did Jose drive last month?
  5. Jose hasn't eaten a hamburger yet.
    -> What hasn't Jose eaten yet?
Edna
  1. Edna is doing her taxes this moment.
    -> What is Edna doing this moment?
  2. Edna always draws a flower.
    -> What does Edna always draw?
  3. Edna is going to drink some milk in a minute.
    -> What is Edna going to drink in a minute.
  4. Edna drove to the mountains 2 years ago.
    -> Where did Edna drive 2 years ago?
  5. Edna has eaten some tomatoes recently
    -> What has Edna eaten recently?
    -> What has Edna recently eaten?
Saul
  1. Saul is doing his exercises today.
    -> What is Saul doing today?
  2. Saul sometimes draws an animal.
    -> What does Saul draw sometimes?
  3. Saul is going to drink some wine next Saturday.
    -> What is Saul going to drink next Saturday?
  4. Saul drove to the beach yesterday.
    -> Where did Saul drive yesterday?
  5. Saul hasn't eaten any pasta for 2 weeks.
    -> What hasn't Saul eaten for 2weeks?

memo

some – use when positive sentence
any – use when negative sentence
http://www.englishclub.com/grammar/adjectives-determiners-some-any.htm

present continuousto be + v ing
simple presenthe/she/it < s
futureto be + going to + verb
pastverb + ed or irregular
present perfecthave/has + past participle

2013年3月6日水曜日

Adult School 3/4

Lesson of Adult school on March 4th.

Dictation

dictate from teacher's spoken sentence and create question sentence from underline sentence.

  1. Hack took his truck to the pump.
    -> Where did Hack take his truck?
    (the pump is meaning of gasoline stand too)
  2. The owner of the new business tacked the fast buck on the wall.
    -> What did the owner of the new business tack on the wall?
  3. There's a sugar pod on the coffee table across from the cushion.
    -> What is there on the coffee table across from the cushion.
  4. Bill always tucks in his wool shirt.
    -> What does Bill always do?
  5. Janet put her hood down before she made that beatiful putt.
    -> What did Janet do before she made that beatiful putt.
  6. I will push you just a little bit to help you.
    -> What will you do to help me?
  7. The teachers haven't chosen the new book yet.
    -> What haven't the teachers chosen yet?
  8. You can hang your hat/cap on the hook.
    -> Where can I hang your hat/cap?
  9. It's easy to plug in the vocabulary if you know the grammar.
    -> What is it easy to do if I know the grammar?
  10. The traffic was slow because there was a hubcap on the free way.
    -> Why was the traffic slow?

Asking each other

Asking each other about last weekend.
Following sentences is that I thought question sentences and other students are asked me questions that they created.


  • Who did you meet on the weekend?
  • What did you see last weekend?
  • Where did you go last weekend?
  • When did you wake up this weekend?
  • How much you spend money to buy food last weekend?

Role Play, Can You Tell Me?

It's example when someone ask me "How to get THE WAY?"


  • Drive along 162nd St to normandie and turn left. Then make a sharp right on 161st St. Go about 3miles on 161st and turn left on CENTRAL Av. You'll see MAXINE WATERS on the left of the corner of CENTRAL Av and 108th St.

※ Use the SHARP left/right if you turn left/right soon after turn left/right

memo

drive/walk up – use the UP when the target is North
drive/walk down – use the DOWN when the target is South
drive/walk along – use the ALONG when the target is East/West


Adult School 2/28

Lesson of Adult school on February 28.

Sentence completion.

Prefer proper word from four words in below box and complete the sentences

1~4salary, heavy, wind, passengers
5~8traffic, eat out, future, polite
9~12difficult, hopes, wild, appetite
13~16nervous, of course, handsome, usually
  1. Take an ambrella, we're going to get heavy rain.
  2. How many passengers are on the plane?
  3. Virginia is the president of the company, and she gets a big salary.
  4. The wind is cold. You need a coat.
  5. We don't know what the future will bring.
  6. I go to work early when there ins't much traffic.
  7. When Len wants something, he always says "please.". He's polite
  8. It's nice to eat out, but it's expensive.
  9. Our business is doing well, and we have hopes it'll do better.
  10. Marilyn loves to eat. she has a big appetite.
  11. Is it difficult to use that computer?
  12. Leo has some wild ideas. I don't pay attention to them.
  13. Most of the girls like Alan. He's very friendly and very handsome.
  14. Of course money is important.
  15. Sara usually has a sandwich and tea for lunch.
  16. I get nervous when I take a test.

Synonyms

Synonyms are words that the same or similar meanings.
Next to the sentence. write a synonym for the underlined word or words.

  1. There are a large number of tall buildings in New York city.
    (large number of ≈ many)
  2. I hope you're correct
    (correct ≈ right)
  3. This camera is very good
    (very good ≈ excellent)
  4. It's stupid to smoke, but hard to stop.
    (stupid ≈ foolish)
  5. It was nice of you to visit me in the hospital.
    (nice ≈ kind)
  6. It's a sunny day. But it's cold
    (but ≈ however)
  7. There's a big error in this bill.
    (error ≈ mistake)
  8. Nicole wants a husband who is rich and good looking
    (looking ≈ handsome)

Antonyms

close - open
everything - nothing
difficult easy
clean - dirty
poor - rich
lie - truth
few - many
past future

Dictation

dictate from teacher's spoken sentence and create question sentence from sentence of underline.

  1. Susan took a cab to the hospital when she had pox.
    -> When did Susan take a cab to the hospital?
  2. I'm going to mop the floor and take out the trash this afternoon.
    -> What are you going to do this afternoon?
  3. You will need a map to find my block.
    -> Why will I need a map?
  4. The cop thinks that criminal is a rat.
    -> What does the cop think?
  5. Sally is going to serve codfish and salad with olives at the picnic.
    -> Where is Sally going to serve codfish and salad with olives?
    (the Codfish is called TARA in Japan)
  6. Robert has just put on a hat for protection from the hot sun.
    -> Why has Robert just put on a hat?
  7. The children enjoyed seeing the octopus at the aquarium.
    -> What did the children enjoy seeing at the aquarium?
  8. Bill is wearing a black cap for his team.
    -> What is Bill wearing for his team.
  9. I will remember to add extra socks when I pack.
    -> What will you remember to add when I pack?
  10. Mother packed a sack lunch for Johnny's field trip.
    -> Why did Mother pack a sack lunch?

memo

What mathematical symbol is used for "nearly equal":
http://answers.yahoo.com/question/index?qid=20080406223143AAWharz


Popular Posts

Blogger templates

Blogger news