Skip to content

Instantly share code, notes, and snippets.

@sadjow
sadjow / makesure.example.coffee
Last active August 29, 2015 14:08
A simple example of makesure using CoffeeScript
validateUser = makesure ->
@permit "name email" # optional
@attrs("name email").isNot('empty').orSay "can't be empty"
userInput =
name: ""
description: "My description"
admin: true
@sadjow
sadjow / rmagick.sh
Created January 25, 2013 17:50 — forked from zoras/rmagick.sh
sudo apt-get install libdjvulibre-dev libjpeg-dev libtiff-dev libwmf-dev libmagickcore-dev libmagickwand-dev libmagick++-dev rvm
sudo gem install rmagick
ok!
Fetching: rmagick-2.13.1.gem (100%) Building native extensions. This could take a while ... Successfully installed rmagick-2.13.1 1 gem installed
require 'RMagick' #=> true
@sadjow
sadjow / _addthis.haml
Created February 7, 2013 20:33
AddThis HAML Buttons
%a.addthis_button_facebook_like{"addthis:url" => product_url(p), "fb:like:layout" => "button_count"}
%a.addthis_button_tweet{'tw:text' => "#{p.name} #{app_title}: #{product_url(p)}"}
@neerajsingh0101
neerajsingh0101 / with_published_versions.rb
Last active December 15, 2015 02:28
How to write Active Record bug report when you are using published versions of gems. More details at https://gist.github.com/neerajdotname/5187216 .
gem 'activerecord', '3.2.12'
require 'active_record'
require "minitest/autorun"
require 'minitest/pride'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
# app/models/concerns/slugable.rb
module Slugable
extend ActiveSupport::Concern
included do
validates_format_of :slug, :without => /^\d/
end
module ClassMethods
en:
errors:
messages:
wrong_content_type: "is the wrong content type"
@RandyMcMillan
RandyMcMillan / PhoneGap.gitignore
Created April 17, 2012 18:30
PhoneGap.gitignore
# ANDROID / ECLIPSE
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
@mateusg
mateusg / inflections.rb
Created April 17, 2011 23:03
pt-BR inflections file for Ruby on Rails applications
# encoding: utf-8
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
@sadjow
sadjow / gist:4162756
Created November 28, 2012 17:36
Create a server with http-proxy node.js - Multiple domains.
var http = require('http'),
httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
if(req.headers.host == 'sadjow.com') {
proxy.proxyRequest(req, res, {
host: 'sadjow.com',
port: 3000
});