Skip to content

Instantly share code, notes, and snippets.

@tadasv
tadasv / orm.go
Last active February 14, 2022 19:19
Simple ORM for Golang
/*
This is an implementation of simple ORM that supports CRUD operations on single object, column mapping from struct tags.
example:
type Account struct {
orm.Model
UUID string
Name string
Email string
@tadasv
tadasv / keybase.md
Created January 15, 2018 14:51
Keybase proof

Keybase proof

I hereby claim:

  • I am tadasv on github.
  • I am tadasv (https://keybase.io/tadasv) on keybase.
  • I have a public key ASCGrghnxBEUnd7xLAn2V7JWVDloZsz9xIToQZ53RzLt0Qo

To claim this, I am signing this object:

@tadasv
tadasv / Count leading zeros
Created February 3, 2014 02:38
A way to count leading 0 bits of a 32 bit int in 5 instructions :)
#include <stdio.h>
/*
You can do the same with a built in function if your compiler supports it:
zeros = __builtin_clz(arg);
*/
int main(int argc, const char *argv[])
{
@tadasv
tadasv / redshift_notes.rst
Created August 2, 2013 15:18
Redshift notes

Migration

  • Altering tables requires exclusive lock on the table. If you have long running queries on a table plan ahead of time when is the right time to run the alter statements.
  • When loading data from S3 run COPY command with FILLRECORD, so that old data could be loaded if your table schema changes before your ETL process.
@tadasv
tadasv / rsyslogd.conf
Created May 15, 2013 21:10
rsyslog 4.x config for monitoring file contents and pushing them to loggly/papertrail
$InputFileName file.log
$InputFileTag file_tag:
$InputFileStateFile /var/spool/rsyslog/file.log_spool
$InputFileFacility local7
$InputFileMaxLinesAtOnce 100000
$InputRunFileMonitor
#
# Include all config files in /etc/rsyslog.d/
#
@tadasv
tadasv / gist:5461753
Created April 25, 2013 18:00
generators vs lists
[] tadas@tadascb-2 ~/tmp: cat generators.py
def munge(i):
return i ** 2 + i
def func1():
return ( munge(i) for i in xrange(10) )
def func2():
return [ munge(i) for i in xrange(10) ]
@tadasv
tadasv / gist:5367051
Created April 11, 2013 20:49
Prime check
from math import sqrt
def is_prime(n):
if n is 2 or n is 3 or n is 5:
return True
if n % 2 == 0 or n % 3 == 0:
return False
sq = sqrt(n)
Mac OS X has only 16K ports available that won't be released until socket
TIME_WAIT is passed. The default timeout for TIME_WAIT is 15 seconds.
Consider reducing in case of available port bottleneck.
You can check whether this is a problem with netstat:
# sysctl net.inet.tcp.msl
net.inet.tcp.msl: 15000
# sudo sysctl -w net.inet.tcp.msl=1000
@tadasv
tadasv / My settings.terminal
Created June 2, 2012 20:26
Colors settings of Mac Terminal.app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OViRjbGFzc1xOU0NvbG9yU3BhY2VVTlNSR0KAAhAB
TxAQMCAwLjUwMTk2MDgxNCAxANIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xv
cqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FI
@tadasv
tadasv / gist:1929170
Created February 28, 2012 03:22
Get directory of the currently executing script
# Get dir of the script
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"