Skip to content

Instantly share code, notes, and snippets.

View mrcasals's full-sized avatar
👨‍🚀
🚀

Marc Riera mrcasals

👨‍🚀
🚀
View GitHub Profile
#!/bin/zsh
# usage: wake_me <command>
echo $@
$@
notification='display notification "'$@'" with title "Finished"'
osascript -e "$notification"
say -v Deranged "it's finally, finally finished. at last."

An ActiveRecord conundrum

I'm going to describe a weird problem I faced when using ActiveRecord today. To protect the innocent, I'm not going to talk about the app I'm actually working on but will instead discuss a hypothetical but isomorphic database design for a clone of the popular blogging platform Tumblr.

Tumblr lets you publish various different sorts of content. We might be tempted to shove all these types in a big STI table, but the types are all quite different from one another and so we give them their own tables.

require 'nokogiri'
class Html2Md
class Link < Struct.new(:href, :title)
end
class Format < Struct.new(:name, :head, :body, :opened)
end
WIDTH = 80
@fbeeper
fbeeper / UsableAccentMarks.md
Last active August 29, 2015 14:06
Usable accentuation on MacOS Lion and above (including Yosemite!)

Usable accent marks on MacOS Lion and above (including Yosemite!)

Since Mac OS Lion, default "press and hold" of keyboard keys brings an easy access to accents and special characters:

alt text

However, who designed the order of elements in these lists is CLEARLY NOT using them with enough frequency*. Depending with what vowel you invoke this tool, the order of diacritical mark is different:

a à á â ä æ ã å ā
require "erb"
require "pathname"
DOT_TEMPLATE=<<-END
digraph {
size="20,20";
overlap=false;
sep=0.4;
graph [fontname=Helvetica,fontsize=10];
node [fontname=Helvetica,fontsize=10];
@txus
txus / wtf.rb
Created October 31, 2014 10:56
Haskell-like function composition in Ruby - let the mad horses unleash
require 'blankslate'
class Proc
def self.comp(f, g)
lambda { |*args| f[g[*args]] }
end
def *(g)
Proc.comp(self, g)
end
module RenderToHTML
def self.book
[title, css, body].join("\n")
end
private
def self.title
commit_hash = `git log -1 --pretty="format:%H"`
%{
@txus
txus / .gitignore
Created September 4, 2011 19:33
ShitDB - YAML-backed document-oriented database in pure ruby
my_db
@txus
txus / memoization_ast_transform.rb
Created October 14, 2011 13:29
Memoization through Rubinius AST Transforms
# This is a Rubinius AST Transform that implements a `memoization` keyword to
# be put before method definitions.
#
# Inspired by José Valim's talk at RuPy 2011.
#
# __KNOWN CAVEATS__: It doesn't reset the cache when changing arguments (it just
# memoizes the first call and returns that value forever more).
#
# Any ideas to make it work better? :D
#
@txus
txus / springpad_api_test.rb
Created February 27, 2012 10:39
Springpad API test
require 'rest-client'
require 'json'
require 'yaml'
config = YAML.load(File.read(File.expand_path("~/.springpad")))
user, password = config['user'], config['password']
#
response = RestClient.get(
"http://springpadit.com/api/users/txus",