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 / copy_assets_from_remote.rb
Last active August 29, 2015 13:58
Migrate local assets to S3 #paperclip
related_path = ->(poster) { '/system/data/' + q.poster.send(:hashed_path) }
remote_path = -> (p) { '/srv/tulp-application/shared' + related_path[p] }
local_path = ->(p) {'/srv/tulp-application/shared/public' + related_path[p] }
%x[mkdir -p #{local_path[q]} && scp -r tulp@backend02.tulp.ru:#{remote_path[a]} #{local_path[q]}]
@ehlyzov
ehlyzov / application.rb
Created April 29, 2014 14:57
"интересный" кусок рецепта
dump_file = "#{app_dir}/shared/tulp.dump"
cookbook_file dump_file do
source "tulp.dump"
owner node["tulp"]["application"]["application_user"]
group node["tulp"]["application"]["application_user"]
end
execute "default database" do
command "psql -h #{postgresql_master_server} tulp < #{dump_file}"
@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
@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 / 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 / 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,
# -*- coding: utf-8 -*-
# Вопрос: что делает следующий код?
(->(g){(->(u){u===u}).(->(x){->(*s){g[x[x]][*s]}})}).(->(c){->{ Hash.new {|h,k| h[k] = c.call }}})
@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
@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 / 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):