Skip to content

Instantly share code, notes, and snippets.

View fullofcaffeine's full-sized avatar

Marcelo Serpa fullofcaffeine

View GitHub Profile
@nmariz
nmariz / singleton.py
Created October 15, 2012 11:20
Python Singleton Metaclass
class Singleton(type):
instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
if __name__ == '__main__':
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@jgranick
jgranick / ThreadingSample.hx
Created August 24, 2012 19:05
How to make a background worker thread (NME recipe)
import com.eclecticdesignstudio.motion.Actuate;
import cpp.vm.Thread;
import nme.display.Sprite;
import nme.events.Event;
import nme.Lib;
class ThreadingExample extends Sprite {
@xeoncross
xeoncross / dd.pv.sh
Created June 7, 2012 14:56
Clone hard drive on linux with DD and PV
When using the linux utility dd, there is no visual output of the progress, how long it is going to take, or anything else. Easy to solve with the use of pv:
% sudo fdisk -l
% pv /dev/sda | dd of=/dev/sdb bs=100M
that’ll display the amount of data transferred, the elapsed time, the throughput speed, a nice progress bar, and the ETA. For devices that do not have a fixed size, let’s say, /dev/zero, there’ll be only a throughput display.
- http://www.yournearestbar.com/2011/10/monitoring-dd-with-a-progress-bar/
@ejhayes
ejhayes / README.md
Created June 6, 2012 01:12
Debugging Hubot Scripts using Node Inspector

About

Use node-inspector to debug hubot!

sudo npm install -g node-inspector

Run Hubot in Debug Mode

coffee --nodejs --debug $(which hubot)

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@assaf
assaf / deploy.sh
Created February 16, 2012 00:02
Deploy using chef-solo
# Run command(s) over SSH
run() {
ssh deploy@${HOST} -t $* || exit 1
}
# Transfer all the specified files/directories to working directory
upload() {
tar czf - $* | ssh deploy@${HOST} tar xzf - -C /etc/chef || exit 1
}
@xolox
xolox / restore-zsh-history.lua
Created January 31, 2012 22:20
Lua script to restore ZSH history file from backups (useful for completion)
#!/usr/bin/env lua
-- Posted this online because of http://news.ycombinator.com/item?id=3535349
ordered = {}
index = {}
need_continuation = false
first_continued_line = 0
function add_or_replace(line)
@jblanche
jblanche / typeParams.rb
Created November 22, 2011 23:45 — forked from devboy/typeParams.as
This is not a language flamewar, Haxe really do looks great and one should use the language he feels the more comfortable with. But I wanted to show how Ruby Duck Typing can handle this kind of situations.
# Ruby is using Duck Typing, rather than checking types, Ruby checks if an object can or cannot respond to a method.
# Here is a "port" of the Haxe example in Ruby.
# Ruby is not a compiled language, so that the "easiest" syntax comes with some shortcoming,
# those errors can only be detected at runtime, your favorite IDE won't warn you before :)
ints = [1, 2, 3]
strings = ["a", "bb", "ccc"]
def biggerThan1(x)
x > 1
@pauljamesrussell
pauljamesrussell / spec_helper.rb
Created November 9, 2011 23:15
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear