Skip to content

Instantly share code, notes, and snippets.

View aderyabin's full-sized avatar
👨‍💻
building something new

Andrey Deryabin aderyabin

👨‍💻
building something new
View GitHub Profile
@aderyabin
aderyabin / rack_example.ru
Created January 11, 2012 15:52 — forked from mattetti/rack_example.ru
Very basic rack application showing how to use a router based on the uri and how to process requests based on the HTTP method used.
#########################################
# Very basic rack application showing how to use a router based on the uri
# and how to process requests based on the HTTP method used.
#
# Usage:
# $ rackup rack_example.ru
#
# $ curl -X POST -d 'title=retire&body=I should retire in a nice island' localhost:9292/ideas
# $ curl -X POST -d 'title=ask Satish for a gift&body=Find a way to get Satish to send me a gift' localhost:9292/ideas
# $ curl localhost:9292/ideas
a = tag(:b)
=> "<b />"
rubinius-2.0.0dev :015 > a.html_safe?
=> true
rubinius-2.0.0dev :016 > a.dup.html_safe?
=> nil
@aderyabin
aderyabin / last.rb
Created May 31, 2012 21:20
caching last in AR
Role.count
(0.5ms) SELECT COUNT(*) FROM "roles"
=> 0
1.8.7 :037 > Role.last
Role Load (0.5ms) SELECT "roles".* FROM "roles" ORDER BY "roles"."id" DESC LIMIT 1
=> nil
1.8.7 :038 > Role.create!(:name => 'php_committer')
(0.2ms) BEGIN
Role Exists (0.4ms) SELECT 1 FROM "roles" WHERE "roles"."name" = 'php_committer' LIMIT 1
SQL (0.7ms) INSERT INTO "roles" ("created_at", "description", "name", "title", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["created_at", Fri, 01 Jun 2012 01:15:04 MSK +04:00], ["description", nil], ["name", "php_committer"], ["title", nil], ["updated_at", Fri, 01 Jun 2012 01:15:04 MSK +04:00]]
@aderyabin
aderyabin / gist:3096201
Created July 12, 2012 06:11
PG shortkeys
mysql: SHOW TABLES
postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
mysql: SHOW DATABASES
postgresql: \l
postgresql: SELECT datname FROM pg_database;
mysql: SHOW COLUMNS
postgresql: \d table
@aderyabin
aderyabin / gist:3600804
Created September 2, 2012 15:52
Install VirtualBox guest additions on Ubuntu Server
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential
sudo mount /dev/cdrom /media/cdrom
cd /media/cdrom && sudo sh ./VBoxLinuxAdditions.run
@aderyabin
aderyabin / skype.sh
Created December 4, 2012 04:24
Save Skype log into Dropbox
mv ~/Library/Application\ Support/Skype ~/Dropbox/
ln -s ~/Dropbox/Skype ~/Library/Application\ Support/Skype
@aderyabin
aderyabin / kladr.rake
Created December 29, 2012 05:57
kladr.rake
# encoding: utf-8
# needs to be installed 7za, pgdbf
namespace :kladr do
PATH = 'tmp/kladr'
def import_options(database=nil)
host = ActiveRecord::Base.configurations[Rails.env]['host']
user = ActiveRecord::Base.configurations[Rails.env]['username']
host &&= "--host=#{host}"
puts <<-SNOWMAN
________
* [________] . *
* . |________| / . *
| |/
* =========
* ______________
* |||||| / \\
||> || ( 0 0 ) .
. ||- | | O |
<?php
/*
* Podcast URL Extractor
* implemented at http://itunes.so-nik.com
*
* All code has been re-written by lasavior.
* Original code & inspiration from Michael Sitarzewski, zerologic.com
*
* Ex: http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewPodcast?id=269238657
@aderyabin
aderyabin / index.rb
Created January 23, 2013 13:11
What do you think about this?
# current
class AddAuthorIdToBooksTable < ActiveRecord::Migration
def change
add_column :books, :author_id, :integer
add_index :books, :author_id
end
end
# thought
class AddAuthorIdToBooksTable < ActiveRecord::Migration