Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kumekay's full-sized avatar

Sergei Silnov kumekay

View GitHub Profile
@ipoval
ipoval / http_authentication
Created February 23, 2011 17:51
Http basic authentication for padrino
module HttpAuthentication
module Basic
def authenticate_or_request_with_http_basic(realm = 'Application')
authenticate_with_http_basic || request_http_basic_authentication(realm)
end
def authenticate_with_http_basic
if auth_str = request.env['HTTP_AUTHORIZATION']
return 'login:password' == ActiveSupport::Base64.decode64(auth_str.sub(/^Basic\s+/, ''))
end
@fedesoria
fedesoria / paperclip_scopes.rb
Created April 14, 2011 03:27
Paperclip Scopes
# For finding images as in Article.attachments.images
scope :images, where("file_content_type LIKE ?", "image%")
# For finding other files Article.attachments.docs
scope :docs, where("file_content_type NOT LIKE ?", "image%")
@IPrism
IPrism / gist:1067612
Created July 6, 2011 16:03 — forked from defunkt/gist:208581
god script for unicorn + rvm
# http://unicorn.bogomips.org/SIGNALS.html
# change these to match your app
app_name = "APP_NAME"
rvm_string = "RVM_STRING"
user = "USER"
pid_file = "/srv/webapps/#{app_name}/shared/pids/#{app_name}.pid"
gem_home = "/usr/local/rvm/gems/#{rvm_string}"
app_root = "/srv/webapps/#{app_name}/current"
@cyberfox
cyberfox / humanize.js
Created October 20, 2011 18:43
JavaScript humanize method.
com = { cyberfox: {} };
/**
* Convert a property name into a human readable string by replacing _ with
* spaces, and upcasing the first letter of each word.
*
* @param {string} property The property name to convert into a readable name.
* @return {string} The property name converted to a friendly readable format.
* @private
*/
#! /usr/bin/env python
import fileinput
import argparse
from operator import itemgetter
parser = argparse.ArgumentParser()
parser.add_argument('--target-mb', action = 'store', dest = 'target_mb', default = 61000, type = int)
parser.add_argument('vmtouch_output_file', action = 'store', nargs = '+')
args = parser.parse_args()
@hisea
hisea / nginx
Created January 1, 2012 23:37
ubuntu passenger nginx init.d script
sudo cp nginx /etc/init.d/
sudo update-rc.d nginx defaults
sudo chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
@wojtekmach
wojtekmach / slim.rb
Created January 3, 2012 23:36
Slim + handlebars
module Tilt
class HandlebarsSlimTemplate < ::Slim::Template; end
register HandlebarsSlimTemplate, :handlebars_slim
end
class Slim::EmbeddedEngine
register :handlebars, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }
register :handlebars_slim, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }, engine: StaticTiltEngine
end
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active April 2, 2024 14:57
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@MrDys
MrDys / gist:3512455
Created August 29, 2012 13:26
Link directly to an open modal window in Bootstrap
/* If you've ever had the need to link directly to an open modal window with Bootstrap, here's a quick and easy way to do it:
Make sure your modal has an id:
<div class="modal" id="myModal" ... >
Then stick this bit of Javascript at at the end of your document:
*/
$(document).ready(function() {
@willb
willb / backup-db.rb
Created August 29, 2012 21:00
Backup script for SQLite databases
#!/usr/lib/env ruby
# Acquires a shared lock on a SQLite database file and copies it to a backup
# usage: backup-db.rb DBFILE.db BACKUPFILE.db
# author: William Benton (willb@redhat.com)
# Public domain.
require 'sqlite3'
require 'fileutils'