Skip to content

Instantly share code, notes, and snippets.

@zxiest
zxiest / gist:1477058
Created December 14, 2011 15:37
Select from hash
# select_from_hash location_size
def select_from_hash(object, name, args, options={})
selected = []
include_blank = false
if (!options[:selected].nil?)
selected = options[:selected]
end
@zxiest
zxiest / gist:1482920
Created December 15, 2011 21:15
truncate rails console output
module IRB
class Irb
MAX_LEN = 10000
def output_value
if (@context.inspect_last_value.length > MAX_LEN)
printf @context.return_format, "#{@context.inspect_last_value[0..MAX_LEN]} <- Truncated"
else
printf @context.return_format, @context.inspect_last_value
end
@zxiest
zxiest / gist:1499353
Created December 19, 2011 23:12
link_to_function (for instance) now requires removing "," between "Add Number" and do
<%= link_to_function "Add Number" do |page|
partial = escape_javascript( render PhoneNumber.new, { :phone_types => PhoneNumbersHelper::phone_types, :name => "location[numbers][]" } )
page << "$('#phone_numbers .rightside .phonenumbers').append(\"#{partial}\")"
end %>
class Geolocation < ActiveRecord::Base
belongs_to :geotaggable, :polymorphic => true
end
class Location < ActiveRecord::Base
has_many :geolocations, :as => :geotaggable, :dependent => :destroy
end
irb(main):045:0> Location.first.geolocations
←[1m←[36mLocation Load (1.0ms)←[0m ←[1mSELECT `locations`.* FROM `locations`
@zxiest
zxiest / gist:2429661
Created April 20, 2012 15:34
Mini Webserver Example
require 'socket' # Get sockets from stdlib
filename = "file.txt"
port = 80
server = TCPServer.open(port) #open socket for listening
loop { # Servers run forever
client = server.accept # Wait for a client to connect
file = File.new(filename, "r")
user::rwx
group::rwx
other::r--
default:user::rwx
default:group::rwx
default:group:root:rwx
default:mask::rwx
default:other::r--
@zxiest
zxiest / .vimrc
Created November 15, 2014 17:14
set nocompatible
filetype off
" set runtime path to include vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Let Vundle manage Vundle
let mapleader="\<Space>"
set number
" easymotion works with <leader><leader>s
" lines below allow yanking to be shared with system clipboard
set clipboard^=unnamed
set clipboard^=unnamedplus
set wrapscan
set nocompatible
filetype off
" set runtime path to include vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Let Vundle manage Vundle
@zxiest
zxiest / steps.md
Last active August 29, 2015 14:11

A Little more Bootstrap Plan

Le Wagon Beirut; Dec 17, 2014; Abdo Achkar


We'll follow a "What, How, DIY, Fix" (WHDF) methodology throughout the workshop:

  • We'll show the feature we'll be building
  • How to build it
  • You then do it yourself