Skip to content

Instantly share code, notes, and snippets.

View parallel588's full-sized avatar

Maksim Pechnikov parallel588

  • WELLNUTS
  • Tampere
View GitHub Profile
@parallel588
parallel588 / gist:972228
Created May 14, 2011 13:53 — forked from ebeigarts/gist:970898
html2haml recursive
for f in `find . -regex '.*\.html\.erb'`; do echo "Converting $f" && html2haml $f > "${f%.erb}.haml" && rm $f; done
@parallel588
parallel588 / gist:1633887
Created January 18, 2012 16:31
Dump remote production postgresql database, rsync to localhost
desc "Dump remote production postgresql database, rsync to localhost"
task :postgresql do
get("#{current_path}/config/database.yml", "tmp/database.yml")
remote_settings = YAML::load_file("tmp/database.yml")[rails_env]
local_settings = YAML::load_file("config/database.yml")["development"]
run "export PGPASSWORD=#{remote_settings["password"]} && pg_dump --host=#{remote_settings["host"]} --port=#{remote_settings["port"]} --username #{remote_settings["username"]} --file #{current_path}/tmp/#{remote_settings["database"]}_dump -Fc #{remote_settings["database"]}"
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{user}@#{shared_host}:#{current_path}/tmp/#{remote_settings["database"]}_dump tmp/"
@parallel588
parallel588 / group
Created February 20, 2012 11:25
mongo_group
@map_function = "
function(log) {
var pad = function(n) {return n<10 ? '0'+n : n}
var date = new Date(log.created_at);
var d = pad(date.getFullYear()) + '-' + pad(date.getMonth()+1) + '-' + pad(date.getDate());
return { group_period: d };
}"
@reduce_function = " function(doc, out) { out.count++; } "
<div style="text-align: center">
<script type="text/javascript" src="http://www.kaltura.com/p/874892/sp/87489200/embedIframeJs/uiconf_id/7218852/partner_id/874892"></script><object id="kaltura_player_1335237510" name="kaltura_player_1335237510" type="application/x-shockwave-flash" allowfullscreen="true" allownetworking="all" allowscriptaccess="always" height="450" width="500" bgcolor="#000000" xmlns:dc="http://purl.org/dc/terms/" xmlns:media="http://search.yahoo.com/searchmonkey/media/" rel="media:video" resource="http://www.kaltura.com/index.php/kwidget/cache_st/1335237510/wid/_874892/uiconf_id/7218852/entry_id/1_qjhijm22" data="http://www.kaltura.com/index.php/kwidget/cache_st/1335237510/wid/_874892/uiconf_id/7218852/entry_id/1_qjhijm22"><param name="allowFullScreen" value="true"><param name="allowNetworking" value="all"><param name="allowScriptAccess" value="always"><param name="bgcolor" value="#000000"><param name="flashVars" value="&amp;{FLAVOR}"><param name="movie" value="http://www.kaltura.com/index.ph
<div style="text-align: center">
<script type="text/javascript" src="http://www.kaltura.com/p/874892/sp/87489200/embedIframeJs/uiconf_id/7218852/partner_id/874892"></script><object id="kaltura_player_1337705630" name="kaltura_player_1337705630" type="application/x-shockwave-flash" allowfullscreen="true" allownetworking="all" allowscriptaccess="always" height="450" width="500" bgcolor="#000000" xmlns:dc="http://purl.org/dc/terms/" xmlns:media="http://search.yahoo.com/searchmonkey/media/" rel="media:video" resource="http://www.kaltura.com/index.php/kwidget/cache_st/1337705630/wid/_874892/uiconf_id/7218852/entry_id/1_ftzarkdi" data="http://www.kaltura.com/index.php/kwidget/cache_st/1337705630/wid/_874892/uiconf_id/7218852/entry_id/1_ftzarkdi"><param name="allowFullScreen" value="true"><param name="allowNetworking" value="all"><param name="allowScriptAccess" value="always"><param name="bgcolor" value="#000000"><param name="flashVars" value="&amp;{FLAVOR}"><param name="movie" value="http://www.kaltura.com/index.ph
@parallel588
parallel588 / avatar_uploader.rb
Created July 5, 2012 11:05 — forked from kirs/avatar_uploader.rb
Validation of image dimensions with CarrierWave
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
require 'benchmark'
n = 1000
Benchmark.bm do |x|
x.report {
n.times do |j|
Item.all(:conditions => {:id => with}, :order => "FIELD(id, #{with.join(',')})")
end
}
end
@parallel588
parallel588 / gist:4094537
Created November 17, 2012 09:42
email benchmark
require 'benchmark'
require "pony-express"
require 'net/smtp'
BOUNDARY = Time.now.to_i.to_s
headers =<<EOF
From: xxx@gmail.com
Subject: Hello Mr.Burns
To: xxx2@gmail.com
---
rackup: /xapit.ru
chdir: /app
environment: production
address: 0.0.0.0
port: 9293
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
for f in *.scss; do sass-convert -F scss -T sass $f ${f%%.*}.sass; done