Skip to content

Instantly share code, notes, and snippets.

View dmitry-ilyashevich's full-sized avatar

Dzmitry Ilyashevich dmitry-ilyashevich

View GitHub Profile
/*
natcompare.js -- Perform 'natural order' comparisons of strings in JavaScript.
Copyright (C) 2005 by SCK-CEN (Belgian Nucleair Research Centre)
Written by Kristof Coomans <kristof[dot]coomans[at]sckcen[dot]be>
Based on the Java version by Pierre-Luc Paour, of which this is more or less a straight conversion.
Copyright (C) 2003 by Pierre-Luc Paour <natorder@paour.com>
The Java version was based on the C version by Martin Pool.
Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
@netzpirat
netzpirat / string_call.coffee
Created November 29, 2010 21:23
String.call and Namespaces in CoffeeScript tested with JasmineBDD
#
# Calls a function that is defined as a String
#
# 'ws.extranett.subdomain_for'.call('argument1', 'argument2')
#
# Will call the function subdomain_for bound on the object extranett
# with arguments 'argument1' and 'argument2'
#
String::call = (args...) ->
@mattetti
mattetti / nested_merge.rb
Created December 2, 2010 06:45
nest merge hashes
h1 = {:key => {a: 1, b: 2, c: {a: 1, b: 2}}}
h2 = {:key => {c: {a:'a', c: 'c'}, d: 4}}
recursive_merge = lambda do |k, old, new|
(new.respond_to?(:merge) && old.respond_to?(:merge)) ? new.merge(old, &recursive_merge) : new
end
puts h1.merge(h2, &recursive_merge)
# => {:key=>{:a=>1, :b=>2, :c=>{:a=>"a", :b=>2, :c=>"c"}, :d=>4}}
@RyanScottLewis
RyanScottLewis / rulebook_rewrite.rb
Created December 21, 2010 20:02
Rewrite of my RuleBook gem
module RuleBook
def RuleBook.add_rules(object, instance_or_class, rules)
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class)
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash)
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing.
object.instance_variable_set(:@_rulebook_initiated, true)
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class
end
@rsim
rsim / jasmine_config.rb
Created January 21, 2011 21:41
Adds CoffeeScript support for jasmine gem (rake jasmine task), uses barista gem to compile CoffeScript files to JavaScript before running Jasmine tests.
# put this file in spec/javascripts/support directory
require 'barista'
require 'logger'
require File.join(Rails.root, 'config/initializers/barista_config')
Barista.configure do |c|
c.env = 'test'
c.logger = Logger.new(STDOUT)
c.logger.level = Logger::INFO
@dmitry-ilyashevich
dmitry-ilyashevich / install-rails-ruby-1.9.2.sh
Created January 21, 2011 20:37
Installing rails on rvm ruby 1.9.2
#!/bin/bash
# created by Josh Frye | joshfng@gmail.com
# Check if the user has sudo privileges.
sudo -v >/dev/null 2>&1 || { echo $(whoami) has no sudo privileges ; exit 1; }
# Update the system before going any further
echo "Updating system..."
sudo apt-get update >> install.log && sudo apt-get -y upgrade >> ~/install.log
echo "done.."
@kathgironpe
kathgironpe / precompile_assets.textile
Created July 7, 2011 16:55
Rails 3.1: Precompile Assets for Cloudfront/CDN support

Naming files and using asset_path

application.scss.erb
- use <%= asset_path 'background.jpg' %>

on config/environments/production.rb

@daneden
daneden / animate.js
Created December 6, 2011 13:23
A function to apply animate.css classes dynamically
// Use the animate.css animations
function animate(element, effect, delay, callback) {
// Set a delay if needed
var animation = setTimeout(function () {
// Add the animation effect with classes
$(element).addClass('animate ' + effect);
// Check if the elemenr has been hidden to start with to prevent FOUC
if ($(element).css('visibility') == 'hidden') {
// If it has, show it (after the class has been added)
@pvinis
pvinis / face_detector.rb
Created December 7, 2011 12:06
run with "macruby face_detector.rb" or "macruby face_detector.rb https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/304055_10150415385415891_522505890_10347873_1682210515_n.jpg?dl=1" for a photo of me with woody and buzz lightyear :p
framework 'Cocoa'
class NSColor
def toCGColor
color_RGB = colorUsingColorSpaceName(NSCalibratedRGBColorSpace)
## approach #1
# components = Array.new(4){Pointer.new(:double)}
# color_RGB.getRed(components[0],
# green: components[1],
# blue: components[2],
@Filirom1
Filirom1 / README.md
Created December 22, 2011 00:33
Test Backbone Model and Collections with NodeJs and Vows. Isomorphic JS