Skip to content

Instantly share code, notes, and snippets.

View constdrop's full-sized avatar

constdrop

  • dogrun Inc.
  • Shizuoka, Japan
View GitHub Profile
@constdrop
constdrop / html_entity_characters.json
Last active March 29, 2017 02:23
Ascii HTML Character Entities.
{
" ": " ",
"!": "!",
"\"": """,
"#": "#",
"$": "$",
"%": "%",
"&": "&",
"'": "'",
"(": "(",
@constdrop
constdrop / hash_key_to_sym.rb
Last active March 28, 2017 02:54
Changing ruby hash keys to symbol.
class Hash
def keys_to_sym
self.each_with_object({}) do |(k, v), h|
h[k.to_sym] = v.class == Hash ? v.keys_to_sym : v
end
end
end
hash = {"a" => 1, "b" => 2, "c" => {"A" => "foo", "B" => "bar"}}
hash.keys_to_sym
@constdrop
constdrop / hashtotal.js
Created March 23, 2016 14:15
javascript hash total one liner.
hash = { a: 1, b: 2, c: 3 };
total = $.map(hash, function(v, k){return v;}).reduce(function(x, y){return x + y;});
// => 6
@constdrop
constdrop / file0.txt
Created December 16, 2015 00:53
viやvimで「Encounter E437: terminal capability "cm" required」が出た時の対処法 ref: http://qiita.com/constdrop/items/524d9f11fc75d29ca1c1
Encounter E437: terminal capability "cm" required
Press ENTER or type command to continue
@constdrop
constdrop / hash_array_max_min.rb
Created October 29, 2015 01:15
max and min of hash's value included in array.
ary = [ { a: 1, b: 2, c: 3 }, { b: 3, c: 2 }, { a: 2, c: 4 } ]
key = :a
max = ary.select{ |h| h[key] }.map{ |h| h[key] }.max # => 2
min = ary.select{ |h| h[key] }.map{ |h| h[key] }.min # => 1