Skip to content

Instantly share code, notes, and snippets.

module Merb::Helpers::Form
def date_field(*args)
if bound?(*args)
current_form_context.bound_date_field(*args)
else
current_form_context.unbound_date_field(*args)
end
end
def datetime_field(*args)
# A nice demonstration of how much faster Ruby 1.9 is than Ruby 1.8
require "complex"
class Complex
def m
z=self
1024.times { |i| z=z*z+self; return i+1 if z.abs > 2 }
return 1024
end
@Antti
Antti / floppy.rb
Created February 7, 2010 21:28 — forked from pjb3/floppy.rb
class Floppy
def method_missing(method, *args)
super unless args.length > 0 && method.to_s[-1..-1] == "="
if args.first.is_a?(Proc)
(class << self; self; end).class_eval do
define_method(method.to_s[0..-2].to_sym, args.first)
end
else
(class << self; self; end).send(:attr_accessor, method.to_s[0...-1])
@Antti
Antti / irbrc.rb
Created June 3, 2010 13:26 — forked from wycats/irbrc.rb
module Matz
def self.included(*)
puts <<-MATZ
Simplicity is NOT a Goal
------------------------
Things too simple are difficult
Things too complex are difficult
rm -R $HOME/Desktop/server-{1,2}
mkdir -p $HOME/Desktop/server-{1,2}
mysql_install_db --datadir=$HOME/Desktop/server-1 && mysqld --server-id 1 -h ~/Desktop/server-1 --socket ~/Desktop/server-1/mysql.sock -P 10001 --log-bin &
mysql_install_db --datadir=$HOME/Desktop/server-2 && mysqld --server-id 2 -h ~/Desktop/server-2 --socket ~/Desktop/server-2/mysql.sock -P 10002 --master-port=10001 --master-host=127.0.0.1 --master-user=root &
alias sql-master="mysql -h127.0.0.1 -P10001 -uroot"
alias sql-slave="mysql -h127.0.0.1 -P10002 -uroot"
alias sql-master-admin="mysqladmin -h127.0.0.1 -P10001 -uroot"
@Antti
Antti / gist:1106691
Created July 26, 2011 12:57
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@Antti
Antti / config.ru
Created March 6, 2012 12:32
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
use std::io;
fn main() {
eval(bytes!("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")); // I stole this off of wikipedia, sorry, wikipedia :(
}
fn eval(program: &[u8]) {
let mut pointer = 0u;
let mut memory = [0u8, ..1024];
let mut jmp_stack = vec!();
module Sass::Script::Functions
def user_color
color_values = options[:custom][:user].color.
scan(/^#?(..?)(..?)(..?)$/).first.
map {|num| num.ljust(2, num).to_i(16)}
Sass::Script::Color.new(color_values)
end
end
@Antti
Antti / HungarianCUDA.cu
Created February 19, 2018 22:18 — forked from paclopes/HungarianCUDA.cu
Fast CUDA implementation of the Hungarian algorithm.
// Fast Block Distributed CUDA Implementation of the Hungarian Algorithm
//
// Annex to the paper:
// Paulo A. C. Lopes, Satyendra Singh Yadav, Aleksandar Ilic, Sarat Kumar Patra ,
// "Fast Block Distributed CUDA Implementation of the Hungarian Algorithm",
// Parallel Computing
//
// Hungarian algorithm:
// (This algorithm was modified to result in an efficient GPU implementation, see paper)
//