Skip to content

Instantly share code, notes, and snippets.

@tvandervossen
tvandervossen / blink.css
Created May 31, 2012 07:27
Blink element for HTML5
@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@alloy
alloy / DEA-providers.rb
Created May 24, 2012 09:47
List of ‘disposable email address’-provider hostnames. Collected from http://bit.ly/Jt6FZU & http://bit.ly/JKNcYC.
[".e4ward.com",
".mailexpire.com",
".otherinbox.com",
"0815.ru",
"0clickemail.com",
"0wnd.net",
"0wnd.org",
"10minutemail.com",
"20minutemail.com",
"2prong.com",
@norman
norman / character_reference.rb
Last active September 9, 2021 20:48
HTML entities? We don't need no stinkin' HTML entities.
# coding: utf-8
#
# Encode any codepoint outside the ASCII printable range to an HTML character
# reference (https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_reference_overview).
def encode(string)
string.each_codepoint.inject("") do |buffer, cp|
cp = "&#x#{cp.to_s(16)};" unless cp >= 0x20 && cp <= 0x7E
buffer << cp
end
end
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@joshsusser
joshsusser / silence_assets.rb
Created April 17, 2012 22:34
put in config/initializers to silence asset logging in Rails development mode
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
@chriseppstein
chriseppstein / defining_placeholders_once.scss
Created April 17, 2012 15:11
If you have a module with placeholder selectors, this pattern will help you avoid outputting them twice if imported twice.
$module-placeholders-defined: false !default;
@mixin module-placeholders {
@if not $module-placeholders-defined {
$module-placeholders-defined: true;
%module-object { color: red; }
%module-object:hover { color: blue; }
}
}
@include module-placeholders;
@listrophy
listrophy / roman.rb
Created April 11, 2012 17:00
To/From Roman numerals
class Fixnum
def to_roman
return '' if self == 0
roman, arabic = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
module GGeocode
### ref: http://code.google.com/apis/maps/documentation/geocoding/
GGeocode::Version = '0.0.3'
def GGeocode.version
GGeocode::Version
end
require 'net/http'
@drnic
drnic / Guardfile
Created April 5, 2012 06:45
An example Guardfile with the works for a Rails app
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }