Skip to content

Instantly share code, notes, and snippets.

@Bobochka
Bobochka / s3.rb
Last active November 29, 2018 20:12
require 'aws-sdk-s3'
require 'benchmark'
def percentile(values_sorted, percentile)
k = (percentile*(values_sorted.length-1)+1).floor - 1
f = (percentile*(values_sorted.length-1)+1).modulo(1)
return values_sorted[k] + (f * (values_sorted[k+1] - values_sorted[k]))
end
@Bobochka
Bobochka / conn.rb
Created May 21, 2018 10:58
Rails Mysql change timeout per connection
connection.instance_variable_get(:@connection).instance_variable_set('@read_timeout', 1)
@Bobochka
Bobochka / authlogic_reset_session
Created April 29, 2018 09:20
AuthLogic destroy/reset user sessions
User.admin.find_each do |user|
user.update_column(:persistence_token, Authlogic::Random.hex_token)
end
@Bobochka
Bobochka / gist:ada3c74afae121daf4d1fd04e12e09fc
Last active April 26, 2018 16:17
mutexed map vs sync map
package main
import (
"math/rand"
"os"
"strconv"
"sync"
"testing"
)
@Bobochka
Bobochka / init.go
Created September 25, 2017 11:52
Init list of structs
package main
import (
"fmt"
"reflect"
)
var A AA
var B BB
@Bobochka
Bobochka / pascal_triangle.go
Created September 23, 2017 12:16
Pascal triangle
package main
import (
"fmt"
"reflect"
)
func main() {
resGot := pascalTriangle(6)
resWant := [][]int{
@Bobochka
Bobochka / eratosphene.go
Created September 23, 2017 11:58
Eratosphenes sieve
package main
import (
"fmt"
"reflect"
)
func main() {
resGot := primesUpTo(30)
resWant := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
@Bobochka
Bobochka / gist:48b07b5c5cbdc5dac815
Created March 7, 2016 12:46 — forked from aurels/gist:843967
stream system command output to STDOUT (ruby)
IO.popen('ant run') do |io|
while (line = io.gets) do
puts line
end
end