Skip to content

Instantly share code, notes, and snippets.

@jackhq
jackhq / Rails-MSSQL-FROM-UBUNTU
Created April 28, 2010 20:52
Rails to MSSQL on Ubuntu
Rails to connect SQL SERVER is a more complicated matter. Since different platforms are different methods of treatment.
Take linux for a different release version has a different treatment methods.
Record ubuntu here under the rails to connect sqlserver steps.
Reference: http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServerFromRailsOnLinux
1 Edit ~ /. Bashrc file, add:
export ODBCINI=/etc/odbc.ini
@tylerhall
tylerhall / strong-passwords.php
Created August 12, 2010 21:38
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@didip
didip / supervisord-example.conf
Created January 30, 2011 05:10
Example configuration file for supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
@hugs
hugs / selenium-examples.py
Created February 16, 2011 19:40
Example code for using the Selenium 2 Python bindings.
# To install the Python client library:
# pip install -U selenium
# Import the Selenium 2 namespace (aka "webdriver")
from selenium import webdriver
# iPhone
driver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')
# Android
@codification
codification / graphite-client.py
Last active April 29, 2019 17:21
Graphite client in python
import time
import socket
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.connect( ("localhost", 2003) )
sock.send("%s %d %d\n" % (name, value, timestamp))
sock.close()
def now():
return int(time.time())
@methane
methane / gist:2185380
Created March 24, 2012 17:28
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
@ssaunier
ssaunier / generate_api_controller.sh
Created May 10, 2012 09:42
Generate a Rails controller in namespace /api/v1
#! /bin/sh
if [ $# -eq 0 ]; then
echo "Usage: ./generate_api_controller.sh CONTROLLER"
exit 1
fi
bundle exec rails generate controller "api/v1/$1" --no_helper --no_assets
rm -rf app/views/api
@nhocki
nhocki / gist:3645632
Created September 5, 2012 21:53
Liquid `includes` from the DB
# Class to be used as a Liquid File System for the `include` tag
class LiquidTemplateSystem
attr_reader :user
def initialize(user)
@user = user
end
# Return a valid liquid template string
def read_template_file(template_path, context)
@manfe
manfe / _some_field.html.haml
Created September 11, 2012 20:24
Creating <optgroup> in select fields using simple_form
= f.association :cities, :collection => State.all, :as => :grouped_select,
:group_method => :cities, :group_label_method => :name
@crusty
crusty / imageRotate.js
Created November 18, 2012 10:57 — forked from seungjin/imageRotate.js
image ratate javascript (rotate image 90 degree....)
/* image rotate javascript */
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Benoit Asselin | http://www.ab-d.fr */
function rotate(p_deg) {
if(document.getElementById('canvas')) {
/*
Ok!: Firefox 2, Safari 3, Opera 9.5b2