Skip to content

Instantly share code, notes, and snippets.

View kpumuk's full-sized avatar

Dmytro Shteflyuk kpumuk

View GitHub Profile
@kpumuk
kpumuk / cqd
Created September 11, 2009 12:24
Script used to deploy to a QA server
#!/bin/bash
#
# Usage: cqd [QAID] [BRANCH]
# When QAID is missing, 1 will be used
# When BRANCH is missing, current one will be used for deploy
# Example 1: cqd
# Deploy to qa01.scribd.com, deployment branch is master (if current one is master)
# Example 2: cqd 5 lazy_carousel
# Deploy to qa05.scribd.com, deployment branch is lazy_carousel
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.scribd.com (be patient).....done
Server Software: nginx/0.7.61
Server Hostname: www.scribd.com
Server Port: 80
# Bash completition for Git
[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh
export LANG=ru_RU.UTF-8
export QTDIR=/opt/local/lib/qt3
# Add ~/bin, /opt/local/bin and /opt/local/sbin to path
export PATH=$HOME/bin:/opt/local/bin:/opt/local/apache2/bin:/opt/thrift/bin:/opt/local/sbin:/opt/jruby/bin:$PATH
# Setup some environment variables
export PS1='\w$(__git_ps1 " (\[\e[0;32m\]%s\[\e[0m\])")$ '
@kpumuk
kpumuk / gist:54615
Created January 29, 2009 16:43 — forked from mdarby/gist:54614
alias ga="git add"
alias gb="git branch"
alias gc="git checkout"
alias gd="git diff"
alias gci="git commit"
alias gg='git log --graph --pretty=format:"%Cred%h%Creset — %s %Cgreen(%cr)%Creset" --abbrev-commit --date=relative'
alias gl="git pull"
alias gm="git merge"
alias gp="git push"
alias gs="git status"
@kpumuk
kpumuk / gist:54141
Created January 28, 2009 19:28 — forked from mdarby/gist:43082
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
find(rand(count))
rescue ActiveRecord::RecordNotFound
retry
# Redefines const value during block execution.
#
# Usage example:
# SOMECONST = 1 # SOMECONST == 1
# redefine_const(:SOMECONST, 'hello') do
# puts SOMECONST # SOMECONST == 'hello'
# end
# # SOMECONST == 1
def redefine_const(const, value, &block)
if const_defined = Object.const_defined?(const)
# Given a set of documents this method returns a list of tags associated with
# those documents ordered by the ones occuring on the most documents. Tags th
# only appear on one doc are excluded from the list.
# If the user supplies a specific tag to exclude it will not be included
# in the list.
def self.related_tags(docs, exclude = nil)
doc_ids = docs[0, 20].map { |doc| doc.id }.join(',')
tags = self.connection.select_all(
"SELECT word_tag_id, COUNT(word_tag_id) FROM word_documents_word_tags
WHERE word_document_id IN (#{doc_ids}) GROUP BY word_tag_id
# Given a set of documents this method returns a list of tags associated with
# ordered by the ones occuring on the most documents. Tags that only appear o
# If the user supplies a specific tag to exclude it will not be included in t
def self.related_tags(docs,exclude = nil)
related = {}
docs.each_with_index do |doc, i|
break if i >= 20 # only consider the first 10 docs
doc.word_tags.each do |tag| # count num times each tag occurs
next if exclude && tag.name == exclude # if caller specified a tag to e