Skip to content

Instantly share code, notes, and snippets.

coffeelint=./node_modules/coffeelint/bin/coffeelint -f coffeelint.json
coffee=./node_modules/coffee-script/bin/coffee
handlebars=./node_modules/handlebars/bin/handlebars
COFFEE=$(shell find app -type f -name '*.coffee')
JS=$(patsubst app/%.coffee, public/js/%.js, $(COFFEE))
SCSS=$(shell find stylesheets -type f -name '*.scss')
CSS=$(patsubst stylesheets/%.scss, public/css/%.css, $(SCSS))
drop table if exists genre cascade;
drop table if exists song cascade;
drop table if exists users cascade;
drop table if exists listened_song cascade;
create table genre(
id serial primary key,
name text not null
);
@dmitry-vsl
dmitry-vsl / ref.rb
Last active August 29, 2015 14:10
Script to refactor requirejs(amd) modules to more convenient style
init

Use vim and chrome developer tools as REPl environment. Press Ctrl-C Ctrl-C to eval code right in chrome console.

/* @flow */
// http://flowtype.org/
class DumbPromise<T>{
value: T;
constructor(value:T){
this.value = value;
};
then<Y>(f:(x:T)=>Y): DumbPromise<Y> {
return new DumbPromise(f(this.value));
};
@dmitry-vsl
dmitry-vsl / gist:53ebed9ded50647cc947
Created January 28, 2015 20:29
Run command in tmux tab from vim
nnoremap <C-c><C-C> :wa\|call system("tmux send-keys -t right ./build C-m")<CR>
{-# LANGUAGE NoMonomorphismRestriction #-}
import Text.ParserCombinators.Parsec
empty = many (oneOf "\t\n\r ")
/* @flow */
type ParseContext = {string: string; position: number;};
type Error = {reason: string; position: number};
type Result<T> = {value: ?T; error: ?Error};
type Parser<T> = (c:ParseContext) => [ParseContext, Result<T>];
function then<T,U>(p: Parser<T>, f: (t: T) => Parser<U>): Parser<U>{
return function(cxt){
var [newCxt, result] = p(cxt);
if(result.value != null){
Две параллельные транзакции, одна слева, другая справа.
Каждая проверяет количество активных пользователей,
убеждается что оно не превышает лимит, и вставляет нового пользователя. В некоторых БД реализация такой функциональности потребовала бы явной блокировки таблицы перед запросом select count(*), но только не в постгресе
test=# test=# begin transaction;
test=# begin transaction; BEGIN
BEGIN test=# select count(*) from u where status='active';
test=# select count(*) from u where status = 'active'; count
count -------
------- 6
Создаем pipe номер 1 (можно любой номер указать) с ограничением 10Kb/s
sudo ipfw pipe 1 config bw 10Kbytes/s
Создаем правило номер 10 (любой номер можно указать), которое вешает пайп номер 1 на исходящий канал от моей к машине к virtual box
sudo ipfw 10 add pipe 1 ip from me to 192.168.15.15 out
Удаляем правило номер 10
sudo ipfw delete 10