Skip to content

Instantly share code, notes, and snippets.

@mgadzhi
mgadzhi / year_month_group.sql
Last active December 18, 2015 19:09
Grouping by month and year in Postgres
SELECT CAST(date_part('year', date) AS varchar(4)) || '-' || CAST(date_part('month', date) AS varchar(2)) AS month, SUM(amount)
FROM withdrawals
WHERE some_predicate()
GROUP BY month
ORDER BY month;
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
(ns algo.stack)
(defn make-stack [] {:first nil})
(defn is-empty? [stack] (nil? (:first stack)))
(defn stack-push [stack item]
(let [previous (:first stack)]
{:first
{:item item :next previous}}))
@mgadzhi
mgadzhi / bash_floats_range.sh
Last active August 29, 2015 14:06
Produce range of floats with step
for i in `echo {0..95..5}`; do echo $i | awk '{print $i/100}'; done
@mgadzhi
mgadzhi / floats_range.mk
Created September 15, 2014 14:08
Produce range of floats in makefile
GROUPS := $(shell for i in `echo {0..95..5}`; do echo $$i | awk '{print $$i/100}'; done)
echo "1234" | gpg --no-use-agent -o /dev/null --local-user <KEYID> -as - && echo "The correct passphrase was entered for this key"
fn swap(arr: &mut Vec<int>, i: uint, j: uint) -> &Vec<int> {
let buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
arr
}
fn insertion_sort(arr: &mut Vec<int>) -> &Vec<int> {
for i in range(1, arr.len()) {
let key = arr[i];
$ find . -wholename '*.py' -type f | xargs -n1 -I {} bash -c 'echo {}; grep -R settings {}'
@mgadzhi
mgadzhi / curl.py
Created May 14, 2015 10:35
pycurl example
#!/usr/bin/env python
from pycurl import Curl
def write(*args):
pass
if __name__ == '__main__':
@mgadzhi
mgadzhi / curl_multi.py
Created May 14, 2015 11:01
curlMulti example
#!/usr/bin/env python
import pycurl
import select
def write(*args):
pass