Skip to content

Instantly share code, notes, and snippets.

View amrnt's full-sized avatar

Amr Tamimi amrnt

View GitHub Profile
require 'rack'
# Released under MIT license, see tests / example.ru for usage
module Rack
class APIVersionMapper
ERROR_TEXT = '<html><head><title>Unknown API Version</title></head><body>Unknown API Version v%s</body></html>'.freeze
EMPTY_RESPONSE = [404, {'Content-Type' => 'text/html', 'Content-Length' => '0'}, ['']].freeze
VERSION_ENV_KEY = 'x-rack.api_mapper.version'.freeze
QUERY_STRING = "QUERY_STRING".freeze
@amrnt
amrnt / chat.html
Created October 27, 2011 16:57 — forked from JoeyButler/chat.html
Simple Chat app
<!DOCTYPE html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script>
<script>
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>"+str+"</p>"); };
if(typeof WebSocket === 'undefined') {
alert("Your browser does not support websockets.")
}
u1 = User.first
u2 = User.last
p = Post.first
u1.cancel_like!(p)
u2.cancel_like!(p)
p.like_count == 0
p.dislike_count == 0
/*
* Author: Amr Numan Tamimi <[email protected]>
* Extracted from: Foursquare.com
* Last Modify: 1/3/2011
*/
(function() {
var iframeManager;
/*
* Author: Amr Numan Tamimi <[email protected]>
* Extracted from: Foursquare.com
* Last Modify: 1/3/2011
*/
(function() {
var Api;
@amrnt
amrnt / README.md
Created March 8, 2012 13:29 — forked from fnichol/README.md
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects

Background

I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.

@amrnt
amrnt / gist:2012155
Created March 10, 2012 17:13
Ember.js Helpful Resources
@amrnt
amrnt / referer_control.rb
Created May 30, 2012 17:03 — forked from postmodern/referer_control.rb
A Rack middleware app to control access to paths based on the Referer header.
module Rack
#
# RefererControl is a Rack middleware app which restricts access to paths
# based on the Referer header. Using RefererControl you can make sure
# users follow the intended flow of a website. If a controlled path is
# visited with an unacceptable Referer URI, then a simple 307 Redirect
# response is returned.
#
# RefererControl should also make Cross Site Request Forgery (CSRF) a
# little more difficult to exploit; but not impossible using JavaScript.
@amrnt
amrnt / gist:2881883
Created June 6, 2012 13:34 — forked from yoshioota/gist:2070371
ruby-debug + ruby 1.9.3 + rbenv
# Install with:
# bash < <(curl -L https://raw.github.com/gist/2070371)
#
# renv, ruby 1.9.3-p125, linecache19-0.5.13.gem, ruby-debug-base19-0.11.26.gem
#
# https://raw.github.com/gist/1333785
# http://d.hatena.ne.jp/kurizo/20111225/p1
#
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
require 'net/http'
class ServerProxy
def self.call(env)
if env["PATH_INFO"] =~ /^\/server_proxy/
request = Rack::Request.new(env)
params = request.params
Net::HTTP.start(params["service_url"]) {|http|
req = Net::HTTP::Get.new(params["service_path"])