Skip to content

Instantly share code, notes, and snippets.

View kohgpat's full-sized avatar
🤖
...

Nikolay Burlov kohgpat

🤖
...
  • Russia, Siberia
View GitHub Profile
@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/home/deploy/public_html/rm/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production
@mislav
mislav / example.rb
Created May 2, 2010 14:20
Fetch full Atom feed from Google Reader
reader = Reader.new 'mislav.marohnic@gmail.com', PASSWORD
# fetch only unread items
feed = reader.fetch_all(FEED_URL, true) do |entry|
# something with each entry
end
puts feed
@cowboy
cowboy / HEY-YOU.md
Last active May 16, 2024 13:31
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@kornysietsma
kornysietsma / excel_reader.rb
Created November 28, 2010 22:29
basic JRuby code to read/write a spreadsheet using the Apache poi libraries
require 'java'
require 'pp'
import "org.apache.poi.hssf.usermodel.HSSFWorkbook"
import "org.apache.poi.hssf.usermodel.HSSFSheet"
import "org.apache.poi.hssf.usermodel.HSSFRow"
import "org.apache.poi.hssf.usermodel.HSSFCell"
import "java.io.FileInputStream"
import "java.io.FileOutputStream"
@5thWall
5thWall / unicorn
Created February 5, 2011 22:10
/etc/init.d script for unicorn and non-rails app
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by 5thWall@gmail.com http://github.com/5thWall
# based on https://gist.github.com/504875 by http://github.com/jaygooby
#
## A sample /etc/unicorn/my_app.conf
##
@collegeman
collegeman / setup-statsd.sh
Created March 9, 2011 16:12
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
@mislav
mislav / https.rb
Created March 12, 2011 17:43
Perform HTTPS requests over secure, verified connection
require 'net/https'
url = URI.parse ARGV[0]
http = Net::HTTP.new(url.host, url.port)
# enable secure, verified connection
if url.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@mperham
mperham / ex1.rb
Created April 19, 2011 02:43
Simple ping/pong with Actors
require 'actor'
# Execute with Rubinius: rbx ex1.rb
def error_loop(&block)
loop(&block)
rescue Exception => ex
puts ex.message
puts ex.backtrace.join("\n")
end