Skip to content

Instantly share code, notes, and snippets.

View ecleel's full-sized avatar

Abdulaziz Alshetwi ecleel

View GitHub Profile
@arfon
arfon / em_tweetstreamer.rb
Created January 21, 2012 12:54
Tweet parsing with EventMachine
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
@ruralocity
ruralocity / share_buttons.rb
Created April 17, 2012 11:20
incomplete, untested at all spaghetti helpers for social media sharing in rails
def facebook_button(url)
content_for :head do
content_tag :script,
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
@lloeki
lloeki / foo_controller.rb
Created May 29, 2012 07:05
Streaming (CSV) data in Rails 3.2
class FooController
respond_to :csv
def index
@foos = Foo.scoped
if stale?(:last_modified => Foo.something)
respond_with @gta do |format|
format.csv { stream_csv @foo }
end
end
@iragsdale
iragsdale / async_resolver.rb
Created November 4, 2010 22:07
Asynchronous DNS resolver based on EventMachine and net-dns
require 'eventmachine'
require 'net/dns'
require 'net/dns/resolver'
module EM # :nodoc:
module Protocols
include Logger::Severity
class AsyncResolver < Net::DNS::Resolver
@TalkingQuickly
TalkingQuickly / gist:6636214
Created September 20, 2013 11:33
Simple unicorn nginx vhost file
upstream unicorn {
server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}
server {
listen 80 default deferred;
root /home/deploy/apps/<%= application %>/current/public;
location ^~ /assets/ {
gzip_static on;
@melchoy
melchoy / mobile_site.rb
Created February 16, 2012 07:26
Mobile Subdomains in Rails
module MobileSite
def self.included(base)
base.class_eval do
# Uncomment for JQM Integration
#rescue_from ActionView::MissingTemplate, :with => :view_unavailable
before_filter :set_mobile_preferences
before_filter :redirect_to_mobile_if_applicable
before_filter :set_mobile_view_path
@lukekarrys
lukekarrys / README.md
Last active February 4, 2018 01:05
Instagram Jekyll Plugin for to Embed Photos
[alias]
wip = !"git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m \"wip\""
unwip = !"git log -n 1 | grep -q -c wip && git reset HEAD~1"
rb = !"git wip;git rebase -i origin/master;git unwip"
pr = !"git fetch;git wip;git rebase --stat origin;git unwip;git heads"
head = !"git log -n1"
lost = !"git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
@seanlilmateus
seanlilmateus / gist:1386468
Created November 22, 2011 18:34
Macruby Face Detection in Mac OS X Lion
framework 'Cocoa'
framework 'QuartzCore'
class NSColor
def toCGColor
colorRGB = self.colorUsingColorSpaceName NSCalibratedRGBColorSpace
components = Array.new(4){Pointer.new(:double)}
colorRGB.getRed components[0], green:components[1], blue:components[2], alpha:components[3]
@otobrglez
otobrglez / Article.rb
Created July 12, 2011 20:51
Finding related articles using Jaccard index and tags
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t