Skip to content

Instantly share code, notes, and snippets.

View localhots's full-sized avatar

Gregory Eremin localhots

View GitHub Profile
@localhots
localhots / mina_crontab.rb
Created May 29, 2014 11:45
Mina task that saves Unicorn and Sidekiq startup scripts to a file and adds its invocation to crontab on @reboot
namespace :maintenance do
task :save_startup_script do
script = "#!/bin/bash\n"
crontab_task = "@reboot #{deploy_to}/shared/startup.sh > #{deploy_to}/shared/log/startup.log #minareboot"
isolate do
invoke 'unicorn:start'
invoke 'sidekiq:start'
script << commands.join(" && \\\n")
end
@localhots
localhots / closed.go
Last active October 8, 2015 12:18
Writing to a closed channel in Go lang
package main
import (
"fmt"
"time"
)
func main() {
chans := []chan int{
make(chan int, 1),
type Counter struct {
Write uint
Read uint
stream chan uint
inLoop bool
}
func NewCounter(wi, ri uint) *Counter {
c := &Counter{Write: wi, Read: ri}
c.stream = make(chan uint)
create procedure `suicide`(arg int)
begin
if arg = 1 then
select id, "GIMMEPID" from information_schema.processlist
where info like "%GIMMEPID%" limit 1 into @pid, @_;
select "BYE!";
kill @pid;
end if;
select 'FINISHED!';
@localhots
localhots / inheritance.go
Last active August 29, 2015 14:05
Examples of inheritance (embedded types) and interfaces in Go language
package main
import (
"fmt"
)
type (
person struct {
name string
age int
@localhots
localhots / config.ru
Created August 27, 2014 13:14
Unicorn worker killer + out-of-band garbage collection
require 'bundler'
Bundler.setup
require 'unicorn'
begin
# Unicorn self-process killer
require 'unicorn/worker_killer'
# Max requests per worker
package main
import (
"flag"
"fmt"
"time"
as "github.com/aerospike/aerospike-client-go"
)
package main
import "time"
// Uint32BatchWithTimeout is an implementation of a batch that starts processing
// either if maximum size or timeout is reached.
type Uint32BatchWithTimeout struct {
size int
timeout time.Duration
fun func(batch []uint32)
package main
import (
"log"
"runtime"
"strings"
)
const (
rootPath = "/path/to/project/root/"
func processWithBatches(items []uint32, batchSize int, f func(batch []uint32)) {
if len(items) == 0 {
return
}
if len(items) <= batchSize {
f(items)
} else {
f(items[:batchSize])
processWithBatches(items[batchSize:], batchSize, f)