Skip to content

Instantly share code, notes, and snippets.

View avsej's full-sized avatar
🛋️
On the couch

Sergey Avseyev avsej

🛋️
On the couch
View GitHub Profile
# This is a monkey patch for MessageVerifier — I need to change Marshal.load to JSON
if defined?(ActionController::Flash::FlashHash)
class ActionController::Flash::FlashHash
def to_json(*args)
{}.merge(self).merge({:used => @used}).to_json
end
end
end
@avsej
avsej / Output
Created January 9, 2010 14:02 — forked from pager/Output
user system total real
pure functional 1.820000 0.000000 1.820000 ( 1.817629)
mutable discriminator 1.530000 0.000000 1.530000 ( 1.534346)
imperative 1.110000 0.020000 1.130000 ( 1.118294)
cursor/iterator 2.370000 0.000000 2.370000 ( 2.373262)
true enumerator 2.090000 0.000000 2.090000 ( 2.089513)
Loaded suite sequences_by
Started
.
Finished in 0.000497 seconds.
require 'rubygems'
require 'id3lib'
$KCODE = 'u'
require 'jcode'
require 'kconv'
FOLDER = '/Users/pa/Tmp/book'
AUTHOR = 'Лем С.'
BOOK_TITLE = 'Возвращение со звезд'
#!/bin/bash
FULLPATH=`cd $(dirname $0); pwd`
echo $FULLPATH >&2
PROJECT=`echo $FULLPATH | awk -F/ '{print $(NF-3)}'`
STATUS=`echo $0 | awk -F- '{print $NF == "worked" ? "pass" : ($NF == "reset" ? "building" : "fail")}'`
PW=`cat $FULLPATH/../../../../credentials`
curl -u $PW -d"author=$AUTHOR" -- http://ci.domain.com/dashboard/build/$PROJECT/$STATUS
echo "Project: "$PROJECT", Status: "$STATUS", Fullpath: "$FULLPATH >&2
@avsej
avsej / gist:735996
Created December 10, 2010 08:59 — forked from theozaurus/gist:716974
# Enable upload_progress module for easy cross browser progress bar support
# using only javascript client side
upload_progress foobar_uploads 1m;
server {
# We only need one server block to deal with HTTP and HTTPS
# avoids duplication
listen 80;
listen 443 default ssl;
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx
@avsej
avsej / migrator
Created February 23, 2011 08:21 — forked from maxim/migrator
script/migrator for easier navigation of migrations
#!/usr/bin/env ruby
# Simple migration navigator for terminal.
#
# Install
# 1) Throw this code into script/migrator
# 2) chmod +x script/migrator
#
# Alternative install
# 1) Put this script into your executable path (e.g. ~/bin)
@avsej
avsej / gist:2775050
Created May 23, 2012 12:39 — forked from kierangraham/gist:2773123
issue with complex keys and startkey and endkey in couchbase-1.2.0.dp ruby client

# Couchbase 1.2.0.dp Complex Key Query

Here is what's needed in order to replicate an issue I'm having with querying complex startkey and endkeys with the Ruby Couchbase 1.2.0.dp.

Use Case

Basically I want to use this kind of map/reduce on a document structure like below to find out the number of type by each author and want to use :start_key and :end_key to get a result for a particular author.

Sample Documents

@avsej
avsej / gist:3621659
Created September 4, 2012 14:28 — forked from johnzablocki/gist:3621597
Couchbase Ruby Client Library Doc Insert and View Query
new_beer = {"name" => "Atlantic Amber"}
client.add("beer_Atlantic_Amber", new_beer)
view = client.design_docs["beers"].by_name(:key => "Atlantic Amber", :limit => 1)
view.each do |beer|
puts beer["name"]
end
# or
class RegistrationsController < Devise::RegistrationsController
def show
github_name = params[:github_name]
if User.find_by_username(github_name)
redirect_to new_user_session_url, :notice => t(:already_registered)
else
session[:github_name] = github_name
@user = User.new(:username => github_name)
if @user.create_for_session_data