This file contains 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
module Enumerable | |
def random_stream(&block) | |
enumerator = Enumerator.new do |y| | |
loop do | |
y << sample | |
end | |
end | |
block ? enumerator.each(&block) : enumerator | |
end |
This file contains 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 Node | |
attr_accessor :value, :next_element | |
def initialize(value, next_element = nil) | |
@value = value | |
@next_element = next_element | |
end | |
def to_s | |
return value.to_s if @next_element.nil? |
This file contains 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
# BasicObject from | |
# simonecarletti.com/blog/2010/05/understanding-ruby-and-rails-proxy-patter-delegation-and-basicobject/ | |
class BasicObject | |
instance_methods.each do |m| | |
undef_method(m) if m.to_s !~ /^__|^nil\?$|^send$|^object_id$/ | |
end | |
end | |
class ObjectMonitor < BasicObject | |
attr_reader :object |
This file contains 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
{% assign d = time | date: "%d" | plus:0 %} | |
{% assign d_mod = d | modulo:10 %} | |
{% assign ordinals = "th,st,nd,rd,th,th,th,th,th,th" | split:"," %} | |
{% if d > 10 and d < 14 %} | |
{{ d }}th | |
{% else %} | |
{{ ordinals[d_mod] }} | |
{% endif %} |
This file contains 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
# Finds your longest man pages by counting `man n foo | wc -l` | |
# for all man pages available. | |
man -k . | | |
sed -e 's/(//' -e 's/)//' | | |
awk '{ print $2, $1 }' | | |
xargs -n 1 -I {} bash -c "echo -n -e "{}"'\t'; man "{}" | wc -l" 2>/dev/null | | |
awk -F$'\t' 'BEGIN { max = 0 } { if ($2 > max) { max = $2; print "max found: " max " (" $1 ")" } }' |
This file contains 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
# | |
# Show all lines added to `some-dir/` in the last week (on all branches), restricted to: | |
# | |
# * only newly added files, | |
# * those by author matching "adam". | |
# | |
git log --author=adam --since={1.week.ago} --all --diff-filter=A -p -- some-dir/ | | |
# lines added | |
grep -E '^\+' | |
This file contains 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
#!/bin/bash | |
USERNAME=your-username | |
# ----- | |
film_for_year() { | |
output=$(curl -s "http://letterboxd.com/$1/films/diary/year/$2/" | grep -Eo '([0-9]+) films' | grep -Eo '[0-9]+') | |
if [ -z "$output" ]; then |
This file contains 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
def permissions_string(integer) | |
triplet_to_string = lambda { |x, s| x.tr("01", "-#{s}") } | |
integer.to_s(2).rjust(9, "0").chars.each_slice(3).map do |r, w, x| | |
[ | |
triplet_to_string[r, "r"], | |
triplet_to_string[w, "w"], | |
triplet_to_string[x, "x"] | |
].join("") | |
end.join("") |
This file contains 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
layout: none | |
<?xml version="1.0" encoding="utf-8"?> | |
{% assign feed_url = "http://example.com/feed" %} | |
{% assign feed_title = "Example Feed" %} | |
{% assign feed_alternate = "http://example.com/blog" %} | |
{% assign feed_global_unique_id = "tag:example.com,2013:TOTALLY-RANDOM-STRING-OF-CHARACTERS-GOES-HERE" %} | |
{% assign feed_author_name = "J. Smith" %} |
This file contains 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
// | |
// Take a user's selected content in the page, as HTML, and | |
// place it inside a blockquote. | |
// | |
// Allows the possibility of automatically converting it | |
// to Markdown with toMarkdown. | |
// | |
// the selection in the document -- Selection object | |
var sel = document.getSelection(); |