Skip to content

Instantly share code, notes, and snippets.

View ehlyzov's full-sized avatar

Eugene Hlyzov ehlyzov

  • http://datafabric.cc
  • SaintPetersburg, Russia
View GitHub Profile
@ehlyzov
ehlyzov / fix_repo.cap
Created May 13, 2015 08:12
Migrate from github to bitbucket. Task for updating repository url on all application instances. Capistrano 3.
task :fix_repo do
on roles(:app) do
config = repo_path.join('config')
execute :sed, '-i', '--', 's/github.com/bitbucket.org/g', config
end
end
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://rating.vc/unijson_v1",
"type": "array",
"items": [
{
"id": "http://rating.vc/unijson_v1/0",
"type": "object",
"properties": {
"company": {
@ehlyzov
ehlyzov / count_intersections.py
Last active August 29, 2015 14:15
Fast intersection counts (thousands lines in sample files, millions in db)
import sys
import sqlite3
import json
import resource
def intersects(sample_file, db):
conn = sqlite3.connect(db)
c = conn.cursor()
def check(id):
@ehlyzov
ehlyzov / raskell.rb
Last active August 29, 2015 14:14 — forked from andkerosine/raskell.rb
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@ehlyzov
ehlyzov / speed.rb
Last active August 29, 2015 14:06
Benchmark calling speed
#!/usr/bin/env ruby
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
def block_call &block
block.call
end
# -*- coding: utf-8 -*-
# Вопрос: что делает следующий код?
(->(g){(->(u){u===u}).(->(x){->(*s){g[x[x]][*s]}})}).(->(c){->{ Hash.new {|h,k| h[k] = c.call }}})
@ehlyzov
ehlyzov / users_to_mailchimp.rb
Created September 9, 2014 10:42
map users to mailchimp list
Gibbon::API.key = ENV['GIBBON_API']
api = Gibbon::API.new
list_id = ENV['SARAFAN_MC_LIST']
to_mailchimp = -> (u) {
api.lists.subscribe({
id: list_id,
email: { email: u.email },
merge_vars: {
'CATEGORY' => u.business.category.translit,
@ehlyzov
ehlyzov / categories.rb
Created July 10, 2014 12:38
working with 4sq
require 'json'
require 'net/http'
require 'csv'
uri = URI('https://api.foursquare.com/v2/venues/categories?oauth_token=QRY3YNHKTYK24JSQPFVBII2YI233T5OZHO2ZQMCG3YU2U05P&v=20140708&locale=ru')
PUSH = -> (categories, scope) do
categories.inject([]) do |res, category|
row = scope + [category['id'], category['name']]
res + [row, *PUSH[category['categories'] || [], row]]
end
@ehlyzov
ehlyzov / categories_info.rb
Created July 7, 2014 09:50
SEO-информация для категорий [tulp.ru]
parents = Category.where(parent_id: nil);
DUMP = -> (category) {
[
category.id,
category.name,
TulpSeo::Data.lookup(
"seo.info.categories.#{category.translit}.default",
{ city_parent: 'Санкт-Петербурга' }
)
@ehlyzov
ehlyzov / demo_controller.rb
Last active August 29, 2015 14:02
systemé demo
module Interviews
class DemoController < Interviews::ApplicationController
# explicit call of ask is not needed, implicit call will be perform when needed
def show
ask(:interview, :other_interviews)
end
def index