Skip to content

Instantly share code, notes, and snippets.

@m-renaud
m-renaud / custom-decoder.elm
Created November 15, 2016 18:11
Custom decoder in elm 0.18
customDecoder decoder toResult =
Json.andThen
(\a ->
case toResult a of
Ok b -> Json.succeed b
Err err -> Json.fail err
)
decoder
@umuro
umuro / Phoenix Cheatsheet.md
Last active September 2, 2017 01:44
Elixir Cheatsheets
@umuro
umuro / template_demo_blog_hobo.rb
Created August 20, 2012 15:13
A template to create a blog with hobo. Quickly!
# Creates a demo blog in a new hobo project
# Usage: rake rails:template LOCATION=template_demo_blog_hobo.rb
# Or: rake rails:template LOCATION=https://raw.github.com/gist/3405055/9aaac7c1c9e9571b32c4359fa9fff77c89de82a9/template_demo_blog_hobo.rb
say ("Installing gems so that we can scaffold...")
run 'bundle install'
generate 'hobo:setup_wizard' if yes? "Wanna run hobo:setup_wizard?"
generate 'hobo:resource', 'Post title:string text:text'
@umuro
umuro / gemset.thor
Created August 20, 2012 13:08
Thor: Create new RVM gemsets by example for new Rails projects
# kate: syntax ruby;
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'rubygems'
require 'thor'
class Gemset < Thor
include Thor::Actions
@umuro
umuro / Ruby header.rb
Created June 4, 2012 10:51
Ruby colorize non-rb files. Enable ruby coloring on files that does not end with .rb
# kate: syntax ruby;
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Add those comments to colorize non-rb files automatically. It happens that not all ruby files have the rb extension.
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@umuro
umuro / .irbrc *.rb
Created March 18, 2009 16:34
IRB improvements: Command history, coloring, more shell like commands cd, pwd, dir, cat
# kate: syntax ruby;
# -*- mode: ruby -*-
# vi: set ft=ruby :
# IRB improvements: Command history, coloring, more shell like commands cd, pwd, dir, cat
# Use powerful shell commands
# dir
# dir '**/*.rb'
# cd 'app'
# pwd