Skip to content

Instantly share code, notes, and snippets.

View pechorin's full-sized avatar
🌴
(do (code) (love life))

andrey pechorin pechorin

🌴
(do (code) (love life))
View GitHub Profile

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@pechorin
pechorin / migrator.rake
Created December 27, 2013 09:57
drupal -> rails db example
# encoding: utf-8
namespace :migrator do
def db
connection_string = ENV['DB']
default_connection_string = 'mysql://root:***@localhost:3306/***'
@connection ||= Sequel.connect(connection_string || default_connection_string)
@connection
@pechorin
pechorin / ui-router-better-state-constraints.js
Created December 11, 2013 14:52
ui-router state constraints example
// Protection for ui-router states
//
// usage:
//
// app.run(function($stateConstraints) {
//
// $stateConstraints.protect({
// state : 'myState',
// guard : function($currentUser) { // <- any service
// // guard should return FALSE if transition to state should be cancelled
@pechorin
pechorin / gist:7020897
Created October 17, 2013 08:01
become a better developer
1) О культуре написания кода очень хорошо здесь - http://www.amazon.com/The-Readable-Code-Theory-Practice/dp/0596802293
Есть море аналогов (которые я все перечитал), к примеру:
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
http://www.ozon.ru/context/detail/id/4187085/
Но "art of redable code" показался мне самым интересным изданием, как в плане содеражтельности, так и в плане оформления :)
2) Очень важно прочесть Фаулера и особенно его http://martinfowler.com/books/eaa.html
Если интересно, то про рефакторинг - http://martinfowler.com/books/refactoring.html, я честно скажу, там все идеи очень простые, поэтому бежать можно буквально по верхушкам и особо не вникать, потому что он там часто простые идеи описывает 5-ую страница текста.
@pechorin
pechorin / rspec.rb
Created September 19, 2013 11:10
rspec readability tip: duplicate each context/describe description-line after each 'end' keyword
describe "#method_a" do
# ...
end # describe "#method_a
describe "#method_b" do
# ...
@pechorin
pechorin / gist:5830294
Created June 21, 2013 10:19
мигратор очередной
# encoding: utf-8
namespace :migrator do
def db
connection_string = ENV['DB']
default_connection_string = 'mysql://root:*****@localhost:3306/******'
@connection ||= Sequel.connect(connection_string || default_connection_string)
@connection
@pechorin
pechorin / gist:5460949
Last active December 16, 2015 16:09
rails 3.2.13 scopes auto merging :(
# Как и ожидалось:
irb(main):151:0> User.where(:id => [1,2]).where(:id => [3,4]).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (1, 2) AND \"users\".\"id\" IN (3, 4)"
# Теперь определяем скоуп:
irb(main):148:0> User.instance_eval { scope :with_ids, ->(ids) { where(:id => ids) } }
# И имеем полнешую хуйню:
irb(main):150:0> User.with_ids([1,2]).with_ids([3,4]).to_sql
without squeel `where(:id => 1).where_values` returns arel nodes. But with squeel i get hash.
irb(main):013:0> User.where(:id => 1).class
=> ActiveRecord::Relation
irb(main):012:0> User.where(:id => 1).where_values
=> [{:id=>1}]
but all is okay then i use scopes:
@pechorin
pechorin / gist:3236224
Created August 2, 2012 10:54
learning c :D
#include <stdio.h>
#include <stdlib.h>
struct db_element {
int id;
char* key;
char* value;
void* next;
struct db_element_collection* db;
};
@pechorin
pechorin / gist:3043734
Created July 3, 2012 22:11
IO language custom syntax
# operators.io
OperatorTable addAssignOperator("->", "setLambda")
# code.io
Object setLambda := method(
slot_name := call message arguments at(0) name asMutable replaceSeq("\"","")
block_body := call message arguments at(1)
object := call target
object setSlot(slot_name, block(