Skip to content

Instantly share code, notes, and snippets.

@straydogstudio
straydogstudio / without_runner.rb
Last active Aug 29, 2015
Render a template outside of Rails
View without_runner.rb
require 'abstract_controller'
require 'action_controller'
require 'action_view'
require 'active_record'
# require any helpers
require './app/helpers/application_helper'
# active record only if data is here
require './app/models/widget'
View gist:227332
require File.dirname(__FILE__) + '/spec_helper'
describe "The library itself" do
Spec::Matchers.define :have_no_tab_characters do
match do |filename|
@failing_lines = []
File.readlines(filename).each_with_index do |line,number|
@failing_lines << number + 1 if line =~ /\t/
end
@failing_lines.empty?
View democratic_charsets.rb
# encoding: UTF-8
# Guess the charset encoding of a given input, by submitting it to vote to different guessers.
require 'rubygems'
require 'open-uri'
if RUBY_VERSION > "1.9"
# ruby encodings only work on 1.9
class Yukihiro
def guess_charset(str)
@sween
sween / rgbmacro.txt
Created Oct 18, 2010
Objective C Macro for using RGB Colors
View rgbmacro.txt
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
cell.textColor = UIColorFromRGB(0x333333);
View ba-whatevcache.js
/*!
* JavaScript whatevCache - v0.2pre - 12/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// whatevCache.set( key, value [, ttl ] );
@porras
porras / why_steak.md
Created Jan 8, 2011
Why Steak (over Cucumber)
View why_steak.md

Why Steak (over Cucumber)

From here

  • Plain text have no value if people writing and reading the specs are developers. Code is natural language for developers (specially if that code is Ruby). Having a client who reads the specs is a possible situation and Cucumber is cool there, but in my experience that situation is not the most common one. If in your case there's no value in having your specs in English rather than in Ruby, Cucumber is an additional layer of abstraction in exchange of nothing.

  • There's a myth about clients writing the specs. It sounds like a unicorn to me, but let's take it. Still, I wouldn't want it. Clients are experts in problems, I am expert in solutions. I want the client to describe the problem I have to solve, not to describe the solution.

  • Some people say Cucumber is cool because you write the stories, the client validates them, and then you can start developing. That is not Agile. The on

@aeden
aeden / gem-index-with-dns.md
Created Jan 16, 2011
Using DNS for Rubygems index
View gem-index-with-dns.md

Currently the RubyGems index is stored as a Gzip file that is a marshalled array. Whenever Bundler needs to install a gem that is not yet installed it downloads the index, gunzips it and unmarshals it. It then looks for dependencies that are described in another file that is also a gzipped and marshalled file. There are several issues that arise from this setup:

  • The full index must be downloaded and parsed, but does not contain dependency data, which must then be downloaded and parsed. This is a relatively time consuming process.
  • The index must be centralized.

Additionally the gems themselves are currently centralized since there is nothing in the meta data that indicates where the gem should be downloaded from. However in order to allow this it is important to find ways of keeping the index from being poisoned (is this an issue in the centralized system?)

Dependency Resolution

@cowboyd
cowboyd / allruby.rb
Created Jan 17, 2011
Proof of concept for making all ruby available to javascript.
View allruby.rb
require 'v8'
require 'openssl'
class Module
def [](name)
self.const_get(name)
end
end
@calavera
calavera / gist:790579
Created Jan 21, 2011
Kata de api fluida
View gist:790579
class User
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age
end
end
class Filter
attr_reader :method, :value
def initialize(method, value)
View caveatPatchor.js
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.