Skip to content

Instantly share code, notes, and snippets.

View dmitryck's full-sized avatar

dmitryck dmitryck

  • krasava
View GitHub Profile
@dalibor
dalibor / Rails model without table
Created November 7, 2009 11:03
Rails model without table
#In app/models/tableless.rb
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end
@tmm1
tmm1 / gist:329682
Created March 11, 2010 21:31
EM Chat Server Demo
require 'rubygems'
require 'eventmachine'
require 'em-http' # gem install em-http-request
require 'yajl' # gem install yajl-ruby
class String
def bold
"\033[1m#{self}\033[0m"
end
end

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For Less, I'm using the JavaScript version because this is what they suggest on the website. The ruby version may be different.

Variables

@MattWoelk
MattWoelk / workman.vim
Created March 25, 2011 23:45
workman keyboard layout for vim
"A blatant workman ripoff of bmx 007's beautiful colemak version called 'colqer' http://www.vim.org/scripts/script.php?script_id=2865 It makes vim so that you can insert and Ex mode in the workman keyboard layout, but can do the rest in qwerty.
"usage: put it in ~/.vim/plugin/ as workman.vim
"press \; in normal mode to activate/deactivate it.
"Keyboard is qwerty
" we want workman in insert mode
function IMapColemak()
if s:imap_colemak == 0
noremap! q q
noremap! w d
@unnitallman
unnitallman / gist:944011
Created April 27, 2011 10:11
sqlite with activerecord outside rails
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:dbfile => ":memory:"
)
@erichurst
erichurst / database.yml.example mysql2
Created May 9, 2011 02:58
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@EmmanuelOga
EmmanuelOga / callback.rb
Created December 1, 2011 15:54
callback test.
require 'benchmark'
class Proc
def slow_callback(callable, *args)
self === Class.new do
method_name = callable.to_sym
define_method(method_name) { |&block| block.nil? ? true : block.call(*args) }
define_method("#{method_name}?") { true }
def method_missing(method_name, *args, &block) false; end
end.new
@steve9001
steve9001 / application.rb
Created December 7, 2011 16:18
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@vishwassharma
vishwassharma / .vimrc
Created March 25, 2012 00:10
Biggest vimfile ever
" =========================
" _ __(_)__ _ ________
" _| |/ / // ' \/ __/ __/
" (_)___/_//_/_/_/_/ \__/
" =========================
" Author: stardiviner ( numbchild at gmail dot com )
" [[ vim Settings ]] {{{2
" :echo $MYVIMRC
set nocompatible " not vim compatible. must be first one, will affect other options.