Skip to content

Instantly share code, notes, and snippets.

View odiak's full-sized avatar

Kaido Iwamoto odiak

View GitHub Profile
#!/usr/bin/env ruby
require 'date'
exit if `which brew`.empty?
last_update = DateTime.parse(File.stat(`brew --repository`.strip + '/.git').mtime.to_s)
days = (DateTime.now - last_update).to_i
if days >= 3
var expr = function expr(x) {
return function (op) {
return ({
'+': function (y) { return expr(x + y); },
'-': function (y) { return expr(x - y); },
'*': function (y) { return expr(x * y); },
'/': function (y) { return expr(x / y); },
'=': x,
})[op];
};
@odiak
odiak / test.md
Created July 4, 2014 07:32
markdown

header1

header2

(1..10).each do |n|
  puts "#{n}!!"
end
@odiak
odiak / classy-extends.coffee
Last active August 29, 2015 14:03
Extending controller on Angular Classy
angular.module('classyExtends', ['classy-core']).classy.plugin.controller
name: 'classyExtends'
classObjs: {}
waitingClassConstructors: {}
options:
enabled: true
convertInject: (classObj) ->
@odiak
odiak / decorate_included_by_state.coffee
Created November 7, 2014 05:18
UI-Router の includedByStateFilter に配列を渡せるようにする
angular.module('App')
.config ['$provide', ($provide) ->
$provide.decorator 'includedByStateFilter', [ \
'$delegate', '$state', \
($delegate, $state) ->
origFilter = $delegate
filter = (state) ->
if _.isArray state
@odiak
odiak / in_filter.coffee
Created November 7, 2014 05:21
`x == a || x == b || x == c` を `x | in:[a, b, c]` と書けるようにするフィルター
angular.module 'App'
.filter 'in', -> (obj, array) -> array.indexOf(obj) != -1
@odiak
odiak / pomodoro.rb
Last active August 29, 2015 14:13
Pomodoro Timer
#!/usr/bin/env ruby
#
# Usage:
#
# ruby pomodoro.rb # => 25 minutes timer
# ruby pomodoro.rb break # => 5 minutes timer
# ruby pomodoro.rb long-break # => 15 minutes timer
# ruby pomodoro.rb 20 # => 20 minutes timer
# ruby pomodoro.rb 10:30 # => 20 minutes and 30 seconds timer
@odiak
odiak / ar_enum.rb
Last active August 29, 2015 14:13
ActiveRecordでオレオレenum
class Issue < ActiveRecord::Base
module STATUSES
OPEN = 1
IN_PROGRESS = 2
RESOLVED = 3
CLOSED = 4
end
STATUSES.constants.each do |name|
class_eval <<-CODE, __FILE__, __LINE__ + 1
@odiak
odiak / tap_if.rb
Last active August 29, 2015 14:14
#tap_if and #else
class Object
def tap_if
yield(self)
self
end
def else
self
end
end
var slice = Array.prototype.slice;
var push = Array.prototype.push;
var inlineTags = [
'input',
'br',
];
var entities = {
'&': '&amp;',