Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
beccasaurus / config.ru
Created August 27, 2012 01:25
Example of how to dispatch requests from 1 Rack application out to different Rack apps
apps = {
'localhost.first' => ->(env) { [200, {'Content-Type' => 'text/plain'}, ['App 1']] },
'localhost.second' => ->(env) { [200, {'Content-Type' => 'text/plain'}, ['App 2']] }
}
run ->(env) do
request = Rack::Request.new(env)
if app = apps[request.host]
app.call(env)
@artpolikarpov
artpolikarpov / doubleHover.js
Created August 22, 2012 19:51
Cинхронное подсвечивание одинаковых ссылок: http://artgorbunov.ru/bb/soviet/20120823/
/*
Функция для одновременной подсветки ссылок с одинаковым href,
на вход принимает:
1) selector — джеквери-селектор ссылок, чтобы
была возможность включить дублирующую подсветку в определённом фрагменте;
2) hoverClass — какой класс добавить по ховеру и псевдо-ховеру.
Инициализация для всего документа:
doubleHover('a', 'hover');
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@stanislaw
stanislaw / ruby-vips-vs-oil.rb
Created July 29, 2012 14:35
Ruby-vips vs Oil
#!/usr/bin/env ruby
require 'rubygems'
gem 'ruby-vips'
gem 'oil'
require 'vips'
require 'oil'
@ChickenProp
ChickenProp / gist:3194723
Created July 28, 2012 20:45
The Liang-Barsky algorithm for line-rectangle collisions

The Liang-Barsky algorithm is a cheap way to find the intersection points between a line segment and an axis-aligned rectangle. It's a simple algorithm, but the resources I was pointed to didn't have particularly good explanations, so I tried to write a better one.

Consider a rectangle defined by x_min ≤ x ≤ x_max and y_min ≤ y ≤ y_max, and a line segment from (x_0, y_0) to (x_0 + Δ_x, y_0 + Δ_y). We'll be assuming at least one of Δ_x and Δ_y is nonzero.

Image depicting the situation

(I'm working with Flash, so I'll be using the convention that y increases as you go down.)

We want to distinguish between the following cases:

@rmartinho
rmartinho / hate.markdown
Last active July 15, 2020 01:33
I will hate you

Dear C++ library writer,

  1. If your library forces me to use new all over, I will hate you.

  2. If your library has types with bogus values, I will hate you.

  3. If the documentation for your library gets the terminology of its own domain wrong, I will hate you.

  4. If I say "My God, it's full of stars!" when I see the function signatures in your library, I will hate you.

@alunny
alunny / slides.md
Created July 23, 2012 19:45
PhoneGap Day Talks
@mattmassicotte
mattmassicotte / gist:3150651
Created July 20, 2012 13:11
Dot-syntax assignment versus traditional assignment
// clang -framework Foundation -c properties.m
#import <Foundation/Foundation.h>
@interface PropertyBug : NSObject {
NSString* _value;
}
@property (copy) NSString* value;
@eltiare
eltiare / carrierwave_config.rb
Created July 18, 2012 16:47
Example of a CarrierWave S3 configuration
# Here's what I have in my CarrierWave configuration file
require 'carrierwave/processing/mime_types'
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'REPLACE WITH AWS KEY', # required
:aws_secret_access_key => 'REPLACE WITH AWS SECRET' # required
}
@indirect
indirect / source.rake
Created June 13, 2012 06:56
rake tasks to remove trailing whitespace and tabs from your codebase
namespace :source do
def find_and_replace_in_source_files(find, replace)
puts "Search and replace #{find.inspect} => #{replace.inspect}"
files = %w[ .autotest .rspec .rvmrc Gemfile Procfile config.ru ].select{|f| File.exist?(f) }
directories = %w[app config lib public script spec test] # exclude bin, db, doc, log, and tmp
directories.each do |d|
files += Dir[File.join(d, "**/*.{rb,rake,haml,erb,builder,js,coffee,css,scss}")]
end