Skip to content

Instantly share code, notes, and snippets.

View forresty's full-sized avatar

Feng Ye forresty

View GitHub Profile
@torsten
torsten / proxy.rb
Last active April 30, 2024 17:53
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@rpetrich
rpetrich / index.php
Created October 14, 2010 21:52
Twitter self-hosted image service/url shortener
<?
// Twitter self-hosted image service/url shortener by Ryan Petrich
// Installation:
// 1. Paste this script into the top of your HTTP root's index.php (rename index.html to index.php if it doesn't exist)
// 2. Add the following to your HTTP root's .htaccess file (create .htaccess if it doesn't exist):
// ErrorDocument 404 /index.php
// 3. Create a "s" subfolder and give it 777 permissions
// 4. Add the following as the custom URL for URL shortening in Twitter for iPhone's settings:
// http://yourdomain.com/?d=%@&p=password
// 5. Add the following as the custom URL for Image service:
@hayesdavis
hayesdavis / blizzard.rb
Created October 19, 2010 17:09
Fun with snowflake
#First tweet on 21 Mar 2006 at 20:50:14.000 GMT (in ms)
TWEPOCH = 1288834974657
#High 42 bytes are timestamp, low 22 are worker, datacenter and sequence bits
SHIFT = 22
# Give it a snowflake id, it tells you what time it was created
# Will fail for very high ids because Ruby Time can only represent up to
# Jan 18, 2038 at 19:14:07 UTC (max signed int in seconds since unix epoch)
def what_time?(id)
module MockSnowflake
TWEPOCH = 1142974214000
WORKERIDBITS = 5
DATACENTERIDBITS = 5
MAXWORKERID = -1 ^ (-1 << WORKERIDBITS)
SEQUENCEBITS = 12
WORKERIDSHIFT = SEQUENCEBITS
DATACENTERIDSHIFT = SEQUENCEBITS + WORKERIDBITS
TIMESTAMPLEFTSHIFT = SEQUENCEBITS + WORKERIDBITS + DATACENTERIDBITS
@pfleidi
pfleidi / fiberchat.rb
Created February 19, 2011 18:51
A naive socket chat using select() and ruby fibers
require 'rubygems'
require 'socket'
include Socket::Constants
class ChatServer
def initialize
@reading = Array.new
@writing = Array.new
@clients = Hash.new
@jinzhu
jinzhu / ArchLinux VPN
Created March 27, 2011 07:12
a script to quick setup vpn server in archlinux
#!/bin/bash
# wosmvp@gmail.com
# thanks sushiyant (me@sushiyant.org)
pacman -S iptables pptpd
echo "iptables -A INPUT -i ppp+ -j ACCEPT" >> /etc/rc.local
echo "iptables -A OUTPUT -o ppp+ -j ACCEPT" >> /etc/rc.local
echo "iptables -A INPUT -p tcp --dport 1723 -j ACCEPT" >> /etc/rc.local
echo "iptables -A INPUT -p 47 -j ACCEPT" >> /etc/rc.local
@jarib
jarib / gist:902119
Created April 4, 2011 18:18
se-conf, google translate example
We couldn’t find that file to show.
We couldn’t find that file to show.
@silviorelli
silviorelli / config.ru
Created April 8, 2011 10:30
config.ru for using POW Rack server with Rails 2
# Rails.root/config.ru
require "./config/environment"
run ActionController::Dispatcher.new
@fnando
fnando / dev.conf
Created July 23, 2011 09:00
Nginx configuration for SSH tunnel
upstream tunnel {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name dev.codeplane.com br.dev.codeplane.com;
location / {
proxy_set_header X-Real-IP $remote_addr;