Skip to content

Instantly share code, notes, and snippets.

var
preFunc = null,
preInput = '',
input = '',
ajaxPost = function(input) {
// apiコール
};
$('#ajax_form').on('keyup', function() {
@ganmacs
ganmacs / gist:4cbaf2dc54d6a3235ba7
Last active November 11, 2016 05:17
add-to-listを複数指定するマクロ
(defmacro append-to-list (mode-list &rest body)
(let ((lst (gensym)))
`(dolist (,lst ',body)
(add-to-list ,mode-list ,lst))))
; Unit Test
(dont-compile
(require 'ert)
(require 'cl)
@ganmacs
ganmacs / gist:045e8fb4552dd2e0c898
Created May 16, 2014 13:50
sheme mode in emacs
(autoload 'scheme-mode "cmuscheme" "Major mode for Scheme." t)
(autoload 'run-scheme "cmuscheme" "Run an inferior Scheme process." t)
(add-to-list 'process-coding-system-alist '("gosh" utf-8 . utf-8))
(setq scheme-program-name "/usr/local/bin/gosh -i")
(defun scheme-other-windows ()
(interactive)
(save-selected-window
(select-window (split-window-horizontally))
@ganmacs
ganmacs / gist:1ceafc33555e05afe743
Last active August 29, 2015 14:01
Rubyのuniqの条件を複数指定する
hash = [{id: 1, name: 'taro', old: 22, sex: 'men'},
{id: 2, name: 'hanako', old: 22, sex: 'woman'},
{id: 3, name: 'taro', old: 24, sex: 'men'},
{id: 4, name: 'taro', old: 24, sex: 'woman'},
{id: 5, name: 'taro', old: 22, sex: 'woman'},
]
p hash.uniq { |h| [h[:name], h[:old]] }
# => [{:id=>1, :name=>"taro", :old=>22, :sex=>"men"}, {:id=>2, :pname=>"hanako", :old=>22, :sex=>"woman"}, {:id=>3, :name=>"taro", :old=>24, :sex=>"men"}]
@ganmacs
ganmacs / gist:fa28a3142b2ae7df8fa6
Created June 10, 2014 13:07
emacsで1行コメント
(defun one-line-comment ()
(interactive)
(save-excursion
(beginning-of-line)
(set-mark (point))
(end-of-line)
(comment-or-uncomment-region (region-beginning) (region-end))))
@ganmacs
ganmacs / gist:e08f1420909f867438ba
Created July 3, 2014 13:52
最小値の添字を取得
ary = [1, 10, 2, 5, 8, 4, 6]
ary.each_with_index.max[1]
@ganmacs
ganmacs / gist:949b6f34d5613005da10
Created July 8, 2014 14:02
Hash#sortの返り値がArrayなのでどうにかする
a = {c: 3, b: 2, dd: 5, a: 1}
p a.sort.to_h
# メソッド内で
value = foo_method
return if value.nil?
# 下でも一緒
value = foo_method.tap { |e| return if e.nil?}
@ganmacs
ganmacs / gist:a498999f33b91a34dd15
Last active August 29, 2015 14:18
rubocop.yml
AllCops:
Exclude:
- 'db/schema.rb'
- 'vendor/**/*'
- 'db/migrate/**/*'
Metrics/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
@ganmacs
ganmacs / gist:097353b76befb74e9566
Last active August 29, 2015 14:20
forwadable tekina
require 'forwardable'
class A
extend Forwardable
def_delegators :@ary, :size, :[]=, :[], :<<, :to_s, :inspect
def initialize
@ary = []
end
end