This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Entry < ActiveRecord::Base | |
| scope :filter, -> { | |
| entries = arel_table | |
| # entries = self.arel_table # 同じ | |
| # entries = Entry.arel_table # 同じ | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is a manifest file that'll be compiled into application.js, which will include all the files | |
| // listed below. | |
| // | |
| // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | |
| // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | |
| // | |
| // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | |
| // compiled file. | |
| // | |
| // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe Admin::HomeController do | |
| describe 'devise' do | |
| context '未ログインユーザーの場合' do | |
| before(:each) do | |
| @user = Fabricate :admin | |
| end | |
| it 'ログイン画面へリダイレクトする' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 例えば '/foo/1#/12'の場合 $location.path() は '/12' になる | |
| # それを '12' にしている | |
| $scope.init = -> | |
| articleId = $location.path().replace /^\/(\d+)/, '$1' | |
| if articleId isnt '' | |
| $location.hash 'article-' + articleId | |
| $anchorScroll() | |
| # 参考リンク: | |
| # http://www.axlight.com/mt/sundayhacking/2013/05/angularjs.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jade = require('jade'); | |
| var templateFile = './template.text.jade'; | |
| var str = require('fs').readFileSync(templateFile, 'utf8'); | |
| var fn = jade.compile(str, { | |
| filename: templateFile | |
| }); | |
| var text = fn(); | |
| console.log(text); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| each v, i in ['foo', 'bar', 'baz'] | |
| div(class= i === 0 ? 'first' : 'others') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> show create table aaa; | |
| +-------+----------------------------- | |
| | Table | Create Table | |
| +-------+----------------------------- | |
| | aaa | CREATE TABLE `aaa` ( | |
| `id` int(11) DEFAULT NULL, // -2147483648 から 2147483647 の範囲が格納可能 | |
| `foo` int(10) unsigned DEFAULT NULL // 0 から 4294967295 の範囲が格納可能 | |
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | | |
| +-------+----------------------------- | |
| 1 row in set (0.00 sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ref) http://mongoosejs.com/docs/queries.html | |
| Person | |
| .find({ occupation: /host/ }) | |
| .where('name.last').equals('Ghost') | |
| .where('age').gt(17).lt(66) | |
| .where('likes').in(['vaporizing', 'talking']) | |
| .limit(10) | |
| //.skip(1) // これもある | |
| .sort('-occupation') | |
| .select('name occupation') // fields オプションと同じ、{name:1, occupation:1} と同じ意味 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| grep -r "`pbpaste`" public/js views --exclude-dir=public/js/vendor | sed 's/^\(.\{1,120\}\).*/\1/' | sed 's/[[:cntrl:]]/ /' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 重複エラーが出る | |
| var sandbox = new Sandbox({ | |
| _id: ObjectId('既存の_id'), | |
| }); | |
| sandbox.someProp = 'New value'; | |
| sandbox.save(function(err, sandbox){ | |
| console.log(err); | |
| }); | |
| // | |
| // -> [MongoError: E11000 duplicate key error index: tomcom.sandboxes.$_id_ dup key: { : ObjectId('既存の_id') }] |