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
WITH date_series_bounds AS ( | |
SELECT date('2012-12-21') as start, date('2013-08-23') as end | |
), date_series AS ( | |
select date(days.start + days.interval) | |
from ( | |
select bounds.start, generate_series(0, bounds.end - bounds.start) AS interval from date_series_bounds bounds | |
) as days | |
) | |
select * from date_series | |
-- 2012-12-21 |
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 Numeric | |
# Returns true if for any i, self.round(i) == numeric | |
# | |
# Usage: | |
# | |
# 149.835.rounds_to?(0) #=> true | |
# 149.835.rounds_to?(100) #=> true | |
# 149.835.rounds_to?(150) #=> true | |
# 149.835.rounds_to?(149.8) #=> true | |
# 149.835.rounds_to?(149.84) #=> true |
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
Size comparison beween `diff` and `diff -U 0` |
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
library coalesce; | |
// To turn the situation where we have: | |
// var foo; | |
// if (mightBeNullA != null) { | |
// foo = mightBeNullA; | |
// } else if (mightBeNullB != null) { | |
// foo = mightBeNullB; | |
// } else { | |
// foo = 2; |
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
void handleUpload() { | |
var elem = query("#upload") as FileUploadInputElement; | |
var file = elem.files.first; | |
FormData fd = new FormData(null); | |
fd.append("username", "ajlai"); | |
fd.appendBlob("Filename", file); | |
var req = new HttpRequest(); | |
req.open("POST", "/foo"); |
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
# Facilitate manipulating symbols as AR attribute values while storing them as other values in the DB | |
# | |
# Examples | |
# | |
# class Example < ActiveRecord::Base | |
# serialize :type, SymbolMapper.for(foo: 1, bar: 2, baz: 3) | |
# end | |
# | |
# example.type = :foo | |
# # => :foo |
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 Object | |
# Usage: | |
# maybe_zero.self_unless(&:zero?) || zero_fallback | |
# # => either maybe_zero or zero_fallback (if maybe_zero was zero) | |
def self_unless | |
self unless yield(self) | |
end | |
# Usage: | |
# maybe_present.self_if(&:present?) |
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
# Working with Mac OS X 10.7, bash 1.3 (brew), git 1.7.4.4 (brew) | |
# To get this to work, add a line to source it from your ~/.bashrc | |
# Credit to Scott Bronson for the following tab completion workaround. | |
# https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81 | |
# (only for bash, zsh tab completions are done separately.) | |
__define_git_completion () { | |
eval " | |
_git_$2_shortcut () { | |
COMP_LINE=\"git $2\${COMP_LINE#$1}\" | |
let COMP_POINT+=$((4+${#2}-${#1})) |