Skip to content

Instantly share code, notes, and snippets.

View Gurpartap's full-sized avatar
:octocat:
Working from home

Gurpartap Singh Gurpartap

:octocat:
Working from home
View GitHub Profile
class Singleton
@get: -> @instance ?= new @
class Test extends Singleton
constructor: -> alert "Test constructed"
run: -> alert "Test run"
class OtherTest extends Singleton
constructor: -> alert "OtherTest constructed"
run: -> alert "OtherTest run"
@technoweenie
technoweenie / pinger.rb
Created June 17, 2011 14:38
ZeroMQ pub/sub demo
require 'zmq'
context = ZMQ::Context.new
pub = context.socket ZMQ::PUB
pub.setsockopt ZMQ::IDENTITY, 'ping-pinger'
pub.bind 'tcp://*:5555'
i=0
loop do
pub.send "ping pinger #{i+=1}" ; sleep 1
end
@cballou
cballou / linode-stackscript-centos-lemp-advanced
Created July 19, 2011 14:09
An advanced Linode StackScript for deploying a CentOs 64bit LEMP Stack with a ton of extras and configuration: MySQL, Suhosin, Memcached, Monit, Supervisord, Gearman, Beanstalk, Fail2Ban, IPTables Firewall, SSH
#!/bin/bash
#
# MYSQL CONFIG
# ============
# <UDF name="db_password" Label="Choose a MySQL Root Password" />
# <UDF name="db_name" Label="MySQL - Database Name" default="" example="Optionally create this database." />
# <UDF name="db_user" Label="MySQL - Username" default="" example="Optionally create this user." />
# <UDF name="db_user_password" Label="MySQL - Password" default="" example="The user password." />
#
# OPTIONAL LIBRARIES TO INSTALL
@lukeredpath
lukeredpath / Resizing.m
Created July 26, 2011 11:54
Resizing tableview to accomodate keyboard
- (void)resizeTableViewWithHeightOffset:(CGFloat)offsetHeight
animationDuration:(double)animationDuration
completion:(void (^)(BOOL))completionHandler
{
[UIView animateWithDuration:animationDuration animations:^{
CGRect frame = self.tableView.frame;
frame.size.height += offsetHeight;
self.tableView.frame = frame;
} completion:completionHandler];
}
@akisute
akisute / BPPrivateWebView.h
Created September 12, 2011 00:40
An UIWebView subclass which uses WebKit private APIs to delegate authentications.
//
// BPPrivateWebView.h
// BPUI
//
// Created by akisute on 11/09/11.
//
/*
Copyright (c) 2011 Masashi Ono.
Permission is hereby granted, free of charge, to any person obtaining a copy of
@jnx
jnx / rbenv-install-system-wide.sh
Created October 1, 2011 20:09
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@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
module Rayo
module Aws
AWS = Fog::Compute.new({
:provider => 'AWS',
:aws_access_key_id => CONFIG.aws.access_key_id,
:aws_secret_access_key => CONFIG.aws.secret_access_key
})
def create_server(opts={})
hostname=opts[:hostname]
@steipete
steipete / iOSDocumentMigrator.m
Created December 6, 2011 15:21
Helps migrating documents between iOS <= 5.0 and >= 5.0.1 to comply with Apple's iCloud guidelines. Follow @steipete on Twitter for updates.
#include <sys/xattr.h>
/// Set a flag that the files shouldn't be backuped to iCloud.
+ (void)addSkipBackupAttributeToFile:(NSString *)filePath {
u_int8_t b = 1;
setxattr([filePath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}
/// Returns the legacy storage path, used when the com.apple.MobileBackup file attribute is not available.
+ (NSString *)legacyStoragePath {
@satlavida
satlavida / Gemfile
Created December 10, 2011 06:49 — forked from gvarela/Gemfile
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"