Skip to content

Instantly share code, notes, and snippets.

View brainwire's full-sized avatar

Vadim Gorbunov brainwire

View GitHub Profile
@brainwire
brainwire / 1.reg
Created November 14, 2015 09:36
swap caps lock control
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
@brainwire
brainwire / days.sql
Created November 10, 2015 10:20
Как найти самый длинный непрерывный ряд событий с помощью SQL http://habrahabr.ru/post/270573/
WITH
-- This table contains all the distinct date
-- instances in the data set
dates(date) AS (
SELECT DISTINCT CAST(CreationDate AS DATE)
FROM Posts
WHERE OwnerUserId = ##UserId##
),
@brainwire
brainwire / timezones.ru.rb
Last active August 28, 2015 08:53 — forked from Envek/timezones.ru.rb
Full list of russian time zones for Ruby on Rails
# Full list of Russian Federation time zones with helper to get this list.
# Place this file in config/initializers/timezones.ru.rb
class ActiveSupport::TimeZone
@country_zones = ThreadSafe::Cache.new
def self.country_zones(country_code)
code = country_code.to_s.upcase
@country_zones[code] ||=
TZInfo::Country.get(code).zone_identifiers.select do |tz_id|
@brainwire
brainwire / Readme.md
Last active August 27, 2015 06:32 — forked from vodafon/Readme.md
Linking #GoLang lib in #Ruby
go build -buildmode=c-shared -o sum.so sum.go
ruby link.rb
@brainwire
brainwire / trgm.rb
Last active August 29, 2015 14:26 — forked from davetoxa/trgm.rb
require 'active_record'
require 'open-uri'
require 'pg'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'trgm',
host: 'localhost',
username: 'postgres'
@brainwire
brainwire / angular_momentjs_binding_directive.js
Last active August 29, 2015 14:26 — forked from kolen/angular_momentjs_binding_directive.js
Two-way binding between form field and moment.js date object for angular.js. With validation.Date object is in UTC, form field displays local date.
directive('dateBinding', function() {
//var format = "YYYY-MM-DD HH:mm:ss"
//date.isValid() is not enough for strict validation, see moment.js doc
//var pattern = /^\s*\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}(:\d{2})?\s*$/
var parseFormat = attrs.dateBinding;
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
ngModel.$parsers.push(function(text) {
@brainwire
brainwire / gist:50b9d5c85fd10b8bea40
Last active June 28, 2023 04:17
Postgresql's tsrange Range Type with Rails
http://www.postgresql.org/docs/devel/static/rangetypes.html
create_table :Room do |t|
t.daterange :availability
end
Room.create(availability: (Date.today..Float::INFINITY))
Room.first.availability # => Wed, 19 Sep 2012..Infinity
connection.execute(%q{
@brainwire
brainwire / ssh_client.go
Last active August 29, 2015 14:25 — forked from iamralch/ssh_client.go
SSH client in GO
package main
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
@brainwire
brainwire / gist:6e91f727101d043c9080
Created July 20, 2015 07:29
Horizontal, vertical or absolute centering
// ----
// libsass (v3.2.4)
// ----
/// Horizontal, vertical or absolute centering
/// If specified, this mixin will use negative margins
/// based on element's dimensions. Else, it will rely
/// on CSS transforms which have a lesser browser support
/// but are more flexible as they don't require to set
/// any specific dimensions to the element.
# http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby
# requires the distribution gem from https://github.com/clbustos/distribution (gem 'distribution', require: false)
def probability_b_beats_a(completed_a, total_a, completed_b, total_b)
require 'distribution/math_extension'
total = 0.0
alpha_a = completed_a + 1
beta_a = total_a - completed_a + 1
alpha_b = completed_b + 1