Skip to content

Instantly share code, notes, and snippets.

View localhots's full-sized avatar

Gregory Eremin localhots

View GitHub Profile
@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
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!';
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)
@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),
@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
<?php
$config_file = "default.json";
$config = json_decode(file_get_contents($config_file));
$host = $config["default_host"];
$uri = $_SERVER["QUERY_STRING"];
if ($config["ab_enabled"]) {
if (in_array($_COOKIE["ab"], $config["ab_hosts"])) {
$host = $_COOKIE["ab"];
DELIMITER $$
CREATE FUNCTION angle_point(lat double, lon double, deg double, dist double) RETURNS POINT DETERMINISTIC
BEGIN
DECLARE dist2 double;
DECLARE rdeg double;
DECLARE rlat1 double;
DECLARE rlon1 double;
DECLARE rlat2 double;
DECLARE rlon2 double;
@localhots
localhots / application_controller.rb
Created March 6, 2014 16:15
Clear impersonation logic in Rails
def session_user
@session_user ||= if current_user.admin? && params[:user_id].present?
User.find(params[:user_id])
else
current_user
end
end
@localhots
localhots / config.ru
Created January 27, 2014 13:01
Tiny static serving server written in Ruby
%w[ logger yaml rack eventmachine ].each(&method(:require))
log = Logger.new(STDOUT)
config = YAML.load_file('config.yml')
Thread.new{ EM.run }
templates = config['storage']['templates'].map{ |tpl| config['storage']['root'] + tpl }
cache = templates.map{ |tpl| Dir[tpl] }.inject(:+).keep_if{ |f| File.file?(f) }
cache = Hash[cache.map do |f|
l = config['storage']['root'].length
[
{
"weight": "400",
"style": "italic",
"family": "ABeeZee"
},
{
"weight": "400",
"style": "normal",
"family": "ABeeZee"