Skip to content

Instantly share code, notes, and snippets.

View chsh's full-sized avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
resources :concepts do
resources :watches do
collection do
delete 'index'
end
end
end
@chsh
chsh / hash_with_method.rb
Created September 11, 2011 14:14
Create Hash with methods for keys. (currently requires ActiveSupport for symbolize_keys :-)
class HashWithMethod < Hash
def self.from(hash)
instance = self.new
hash.symbolize_keys.each do |key, value|
case value
when Hash
value = self.from(value)
when Array
value = value.map { |v| from_any(v) }
@chsh
chsh / config_loader.rb
Created September 11, 2011 14:22
Load Rails related configuration from yaml file with erb evaluation.
require 'erb'
class ConfigLoader
def self.from(yaml)
yaml = File.read(yaml) if File.exist?(yaml)
YAML.load(ERB.new(yaml).result)[Rails.env]
end
end
@chsh
chsh / mongo-repair.sh
Created September 25, 2011 04:12
mongo repair script
#!/bin/bash
LOCK_FILE=/opt/var/db/mongodb/mongod.lock
PID_FILE=/var/run/mongo.pid
DAEMON=/opt/mongodb/bin/mongod
DBPATH=/opt/var/db/mongodb
mongo_running=0
if [ -f $PID_FILE ]; then
@chsh
chsh / usersctipt.js
Created February 9, 2012 05:22
User Scripts for ChatWork.app made by Fluid.
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 1000);
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
function updateDockBadge() {
var newBadge = '';
var totalCount = 0;
var roomsRoot = document.getElementById('cw_roomlist_items');
var ur_elms = roomsRoot.getElementsByClassName('cw_unread');
@chsh
chsh / configuration.rb
Created February 16, 2012 07:01
configuration gem configurations loader. :-)
# place this file under Rails.root/config/initializers/configuration.rb
#
# load configurations from Rails.root/config/environments.
#
# load order is:
# 0. application.rb
# 1. #{Rails.env}.rb
# 2. app(1|2).rb
# 3. app(1|2)_#{rails.env}.rb
# 4. app(1|2)_local.rb
@chsh
chsh / webloc-spotlight.rb
Created February 22, 2012 03:42
Set spotlight searchable content scraped from web to FinderComment for webloc
#!/usr/bin/ruby
require 'tempfile'
require 'open-uri'
require 'rubygems'
require 'sanitize'
require 'nokogiri'
webloc = ARGV[0]
@chsh
chsh / dig_key.coffee
Created February 26, 2012 02:04
Handle all keyevents and react if digit or return key.
class DigKey
constructor: (@catch_elm, @disp_elm, @form_elm) ->
$(@catch_elm).keydown (event) =>
kc = event.keyCode
$(@disp_elm).append dig(kc) if is_num(kc)
if is_cr(kc)
$(@form_elm).submit
else
$(@disp_elm).append '<br/>' if is_cr(kc)
@chsh
chsh / wunderkit-userscript.js
Created February 28, 2012 04:25
UserScripts for Wunderkit.app made by Fluid.
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 1000);
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
function updateDockBadge() {
var newBadge = '';
var totalCount = 0;
var badgesRoot = document.getElementById('wk-notifications');
@chsh
chsh / ean.coffee
Created March 2, 2012 11:36
Verify EAN and fix if available.
class EAN
valid_code: (ean) ->
return false if ean.match(/[^0-9]/)
ean += '00000' if ean.length == 8
return false unless ean.length == 13
return ean if is_valid(ean)
[ean[1], ean[0]] = [ean[0], ean[1]]
return ean if is_valid(ean)
false