2015-06-01から1ヶ月間の記事一覧

has_many through: するとき

has_many :sales, through: product と has_many :sales, through: products の違い

Railsのhas_many ,through: の反対

delegate、あるいはhas_one, :throughを使う http://blog.toshimaru.net/belongs_to-through/has_one, :throughを使ったらいけた。

treatのインストール

birchのインストールでコケるので、githubからspecific_installする https://github.com/louismullie/treat/issues/91 $ gem install 'specific_install' $ gem specific_install -l https://github.com/faustoct/birch.git $ gem install 'treat' $ irb > r…

Rubyでハッシュを要素に持つ配列の操作

[ {"1"=>"16"}, {"2"=>"13"}, {"3"=>"1"}, {"4"=>"8"}, {"5"=>"2"}, {"8"=>"7"}, ] という配列を以下のハッシュにしたい { "1"=>"16", "2"=>"13", "3"=>"1", "4"=>"8", "5"=>"2", "8"=>"7", } 以下で出来た。 http://qiita.com/abey1192/items/838ceb96b18ae…

herokuのDBをダンプしてローカルにリストアする

https://devcenter.heroku.com/articles/heroku-postgres-backups $ heroku pg:backups capture --app sushi $ curl -o latest.dump `heroku pg:backups public-url` これでlatest.dumpがダウンロードできる リストア http://www.workabroad.jp/posts/2074 P…

RailsやRubyのリファレンスを辞書.appに登録する

ここのdictionaryファイルを~/Library/Dictionariesに置く http://www.priithaamer.com/blog

配列の中のハッシュをまとめる

以下のデータを同じnameごとにまとめて、dataを加算したい [ {name: "fruits", data: [1,2,3]}, {name: "meat", data: [3,4,5]}, {name: "fruits", data: [5,6,7]} ] 求める形 [ {name: "fruits", data: [6,8,10]}, {name: "meat", data: [3,4,5]}, ] arr = …

rubyで配列の足し算

[1,2]と[3,4]を足して[4,6]を出したい([1+3,2+4]) http://qiita.com/Kta-M/items/b54f12d3eb49520925e7 a1= [1,2,3] a2=[3,4,3] a3=[5,6,3] [a1, a2, a3].transpose.map{|a| a.inject(:+) }

VMware fusionのCPU使用率が100%を超える

http://www.denki-kayou.net/?p=2041 試したこと ・.vmxファイルに追加 ・vmware toolsの再インストール ・ネットワークのIPv6をOFFに 最後のipv6を切る設定でファンが止まったような気がする

Railsで日付で集計する

http://qiita.com/ryonext/items/4ed2f7635135a7b388f3 DATE(:created_at)が使える pry(main)> Deal.all.group("date(created_at)").select("date(created_at)").count (0.5ms) SELECT COUNT(date(created_at)) AS count_date_created_at, date(created_at) …

irbで5.daysとかを使う

Active Suportの機能なのでrequireすればいい、と思いきや、require 'active_support'じゃ駄目だった。 http://stackoverflow.com/questions/4238867/how-do-i-use-active-support-core-extensions require 'active_suport/all'する。 $ irb > require 'acti…

VimのNeoBundleでCoffeeScriptがシンタックスハイライトされない

https://github.com/gmarik/Vundle.vim/issues/202filetype onとfiletype offの間にvim-coffee-scriptを宣言する call neobundle#rc(expand('~/.vim/bundle/')) syntax on syntax enable filetype off NeoBundle 'kchmck/vim-coffee-script' "this should co…

RailsでPostgreSQLを使う

http://qiita.com/_daisuke/items/13996621cf51f835494bユーザ(role)追加 $ createuser -P myuserデータベース作成 / -O はowner $ createdb nypd_development -O myuserこれでrake db:migrateすればいいconfig/database.yml default: &default adapter: p…

herokuでのassets precompileをスキップする

https://gist.github.com/Geesu/d0b58488cfae51f361c6 lib/tasksにassets.rakeを追加する Rake::Task["assets:precompile"].clear namespace :assets do task 'precompile' do puts "Not pre-compiling assets..." end end

RailsのデータをCSVでダウンロードする

https://salayhin.wordpress.com/2014/05/10/export-csv-file-from-rails-console/MacのExcelのエンコーディングはUTF-16LEかつ、BOMをヘッダに付けないといけないとのこと http://hondou.homedns.org/pukiwiki/pukiwiki.php?Mac%20Mac%20%C8%C7%20Excel%20%…

Mac OSXでScreen flashを無効にしているのにflashするとき

ここのチェックを外しているのにスクリーンが点滅する。 http://apple.stackexchange.com/questions/25605/how-can-i-stop-my-whole-screen-from-flashing-white-on-errors 再起動せよとのこと。

MacでExcelの環境を整える

0. ターミナルで.xlsxを生成する ターミナルから直接は.xlsxを作れないので、まず.csvをtouchしてopenし、⌘ + Shift + S「名前をつけて保存」して.xlsxを指定して保存する。 .csvは消去してgit init しておく。 $ touch hoge.csv $ open hoge.csv Excel上でh…

中国でのネット

深センではGoogleのサービスが全滅だった Facebookもつながらない ちなみに香港は何の制限もなかったさくらVPS上にたてたSquid(プロキシサーバ)を経由させてみたけど 普通のページは見れるけど、グレート・ファイアウォールに指定されてるページは見れない…

iOS8のサードパーティキーボードで外付けBluetoothキーボードのCaps lockをControlにする

ことはできないのだろうか http://www.macworld.com/article/2241994/ios-8-changes-we-d-like-to-see-the-os-and-home-screen.html このプロジェクトをフォークしてみる https://github.com/archagon/tasty-imitation-keyboard

How to compute delta robot kinematics

http://stackoverflow.com/questions/18162880/how-to-correctly-compute-direct-kinematics-for-a-delta-robothttps://gist.github.com/hugs/4231272

デルタロボットの計算

https://github.com/Jaydmdigital/mk_visual_calchttps://sites.google.com/site/3dprinterlist/delta-3d-printers/delta-robot-calculatorhttps://docs.google.com/spreadsheets/d/1hxlW7l-9fA_VWM-tKPwt8gp_vhGXPhrogSufBOluFDw/edit#gid=0

デルタロボットのシミュレータ

http://www.thinkyhead.com/_delta/

Arduino UNOにスケッチをアップロード出来ないとき

AVRISP mkIIが必要。 1. シリアル変換のファームウェア(ATmega8u2用)をアップロードする シリアルポートが見えないときは、ATMega8u2のファームを入れ替える。 http://www.arduino.cc/en/Hacking/DFUProgramming8U2 ArduinoのICSPヘッダじゃない方の6ピンヘ…

VisualmicroとAtmel Studio 6でブレークポイントの値をダンプ

http://www.visualmicro.com/post/2012/05/05/Arduino-Debugger-Trace-Messages-and-VariablesExpressions.aspx

Ubuntuで2種類のlibusb

sudo apt-get install libusb-dev sudo apt-get install libusb-1.0-0-dev最初libusb-1.0.0-devとやってて間違えた→正しくはlibusb-1.0-0-dev $ dpkg -L libusb-dev|grep /usr/include /usr/include /usr/include/usb.h $ dpkg -L libusb-1.0-0-dev|grep /us…

libusbの使い方

http://penguin.tantin.jp/hard/libusb%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6.html

lsusbでエンドポイントを調べる

http://stackoverflow.com/questions/16428356/know-a-usb-devices-endpoint $ sudo lsusb -v -d 0b75:039f Bus 002 Device 002: ID 0b75:039f Roland DG Corp. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 (Defined at In…

MacからBOOTCAMPフォルダが見えないとき

http://kanzmemo.cocolog-nifty.com/blog/2014/03/os-xboot-camp-5.html WindowsでBOOTCAMP(C:)ディスクのプロパティを開き、check diskする

sudoでリダイレクトしたいとき

shに-cオプションをつける http://yut.hatenablog.com/entry/20111013/1318436872 sudo sh -c "cat zero.rml > /dev/usb/lp0"

Rasberry piでNative WebRTCのビルド

http://raspberrypi.stackexchange.com/questions/29871/how-to-build-native-webrtc