Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
@yanmhlv
yanmhlv / fileinfo.rb
Last active August 29, 2015 13:56
Получение списка хешей, состоящего из пути, sha1-хеша и информации о файле.
require 'digest'
def get_hash(string=nil, file=nil, method='md5')
raise RuntimeError if string.nil? && file.nil?
method = method.upcase
method = Digest.class_eval(method)
if string
hash = method.hexdigest(string)
@yanmhlv
yanmhlv / functional.rb
Created March 9, 2014 12:27
functional module
module Functional
def apply(enum)
enum.map &self
end
alias | apply
def reduce(enume)
enum.inject &self
end
alias <= reduce
@yanmhlv
yanmhlv / parse_options.rb
Created April 3, 2014 13:15
парсинг коммандной строки
require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
options[:verbose] = false
opts.banner = "Usage: #{$0} --option=value"
opts.on('-v', '--verbose') {options[:verbose] = true}
opts.on('-h', '--help') do
puts "Help message"
#!/bin/sh
### BEGIN INIT INFO
# Provides: btsync
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multi-user daemonized version of btsync.
@yanmhlv
yanmhlv / commands.sh
Created July 11, 2014 06:58
полезные команды
rsync -av -e ssh pi@192.168.0.1:~/logs/* ./logs/ # копирование с помощью rsync
@yanmhlv
yanmhlv / Gemfile
Last active August 29, 2015 14:11
rails_admin + paperclip
# Gemfile
gem 'rails_admin'
gem 'paperclip'
package main
import "fmt"
func main(){
a := 3
if a == 3 {
fmt.Println("1. if-else, a == 3")
} else {
fmt.Println("1. if-else, a != 3")
import timeit
time_python = timeit.timeit("""
from itertools import groupby
from random import randint
import pandas as pd
accruals = [
{'account': i, 'value': i * randint(0, 20), 'foo': randint(0, 10)}
for i in range(5000)
package main
import "log"
func groupBy(vars []int) map[int][]int {
result := make(map[int][]int)
for _, value := range vars {
result[value] = append(result[value], value)
}
var numCPUs = require('os').cpus().length;
var cluster = require('cluster');
var count=0;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {