Skip to content

Instantly share code, notes, and snippets.

@robertomiranda
robertomiranda / securing_rails_updates.md
Created March 5, 2012 19:15 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


call pathogen#runtime_append_all_bundles()
set rtp+=/usr/share/vim/addons
source ~/.vim/vimrc "linux
set number
" Indent
set cindent
set autoindent
set expandtab
@robertomiranda
robertomiranda / elements.md
Created April 27, 2012 18:37 — forked from guilleiguaran/elements.md
Excerpts from The Elements of Programming Style. The source of this compilation is unknown.

The Elements of Programming Style

The following rules of programming style are excerpted from the book "The Elements of Programming Style" by Kernighan and Plauger, published by McGraw Hill. Here is quote from the book: "To paraphrase an observation in The Elements of Style by Strunk and White, the rules of programming style, like those of English, are sometimes broken, even by the best writers. When a rule is broken, however, you will usually find in the program some compensating merit, attained at the cost of the violation. Unless you are certain of doing as well, you will probably do best to follow the rules."

@robertomiranda
robertomiranda / users_controller.rb
Created July 19, 2012 21:47 — forked from guilleiguaran/users_controller.rb
Using attr_accessible: the right way
class UsersController < ApplicationController
include ActiveModel::MassAssignmentSecurity
attr_accessible :name, :age
attr_accessible :name, :age, :admin, :as => :admin
def create
@user = User.create!(user_params)
redirect_to @user
end
fibonacci_numbers = Enumerator.new do |yielder|
i1, i2 = 0, 1
loop do
yielder.yield i1
i1, i2 = i2, i1+i2
end
end
fibonacci_numbers.first(10)
=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
class Object
# Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
# param name.
#
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
def to_query(key)
require 'uri' unless defined?(URI)
regexp = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
"#{URI.escape(key.to_s, regexp)}=#{URI.escape(to_param.to_s, regexp)}"
end
@robertomiranda
robertomiranda / sequel.rb
Created September 26, 2012 01:23
Connecting to a database with sequel
require "rubygems"
require "sequel"
DB = Sequel.connect(:adapter=>'postgres', :host=>'localhost', :database=>'blog', :user=>'user', :password=>'password')
@robertomiranda
robertomiranda / chat.rb
Created October 13, 2012 20:15 — forked from rkh/chat.rb
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
function seconds_to_time(seconds){
var minutes = Math.floor(seconds / 60);
var seconds = seconds - minutes * 60;
return seconds < 10 ? minutes + ":0" + seconds : minutes + ":" + seconds
}
/*
* Playlist Object for the jPlayer Plugin
* http://www.jplayer.org
*
* Copyright (c) 2009 - 2011 Happyworm Ltd
* Dual licensed under the MIT and GPL licenses.
* - http://www.opensource.org/licenses/mit-license.php
* - http://www.gnu.org/copyleft/gpl.html
*
* Author: Mark J Panaghiston