Skip to content

Instantly share code, notes, and snippets.

View gotar's full-sized avatar
🏠
Working from home

Oskar Szrajer gotar

🏠
Working from home
View GitHub Profile
@gotar
gotar / gist:2643135
Created May 9, 2012 08:54
rewrited
class WebRequest
attr_reader :time, :ip, :referer, :user_agent
def initialize(time, ip, referer, user_agent)
@time = time
@ip = ip
@referer = referer
@user_agent = user_agent
@mobile = is_mobile?
end
@gotar
gotar / gist:2923506
Created June 13, 2012 11:19
vim config
" General ********************************************************************
set nocompatible
set encoding=utf-8
set fileencodings=utf-8,latin2
" Autowrite current buffer on switch
set autowrite
" Tabs ************************************************************************
set softtabstop=2
@gotar
gotar / rapi.rb
Created August 6, 2012 11:02
Rapi
#!/usr/bin/env ruby
#encoding: utf-8
require "digest/md5"
require "open-uri"
require "pp"
class Rapi
def initialize avi_file_path
@avi_file_path = avi_file_path
@gotar
gotar / parallel_search.rb
Created August 13, 2012 12:28
ParallelSearch
module API
class ParallelSearch
API_FETCHING_TIMEOUT = 1 # seconds
def initialize(config, search_apis)
@config = config
@search_apis = search_apis
end
# Returns results hash of {#ExternalSearchApi => [item, ...], ...}.
@gotar
gotar / cache.rb
Created August 13, 2012 12:45
Cache
module Cache
class Entry
include Mongoid::Document
field :key, type: String
field :_id, type: String, default: -> { key }
field :value
field :created_at, type: DateTime
end
@gotar
gotar / pmap_spec.rb
Created October 10, 2012 15:41
test for pmap
describe Array do
describe '#pmap' do
context "without timeout" do
it "should not raise error" do
expect {
[].pmap{|x| x}
}.not_to raise_error
end
it "should return proper values" do
[user]
name = Imie Nazwisko
email = email@example.com
[alias]
br = branch
co = checkout
ci = commit
df = diff
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@gotar
gotar / pmap.rb
Last active December 10, 2015 17:18
require 'celluloid'
module Enumerable
# Parallel map. Calculates each element in a separate thread.
def pmap(timeout=nil, &block)
map {|element|
Celluloid::Future.new(element, &block)
}.map{|result|
begin
result.value(timeout)
@gotar
gotar / combine.rb
Last active December 15, 2015 13:48
chat: {
id: 1,
owner_id: 1,
member_id: 2
}
user1: {
id: 1
name: 'Foo'
}
@gotar
gotar / rapi.rb
Created April 2, 2013 13:56
Rapi - download subtitles
gotar@air ~/Programowanie/mamymo/Api [master] $ cat ~/Skrypty/Rapi/rapi
#!/usr/bin/env ruby
#encoding: utf-8
require "digest/md5"
require "open-uri"
class Rapi
def initialize avi_file_path
@avi_file_path = avi_file_path