Skip to content

Instantly share code, notes, and snippets.

def commafy(num):
return splitThousands(str(num), ',', '.')
def splitThousands(s, tSep, dSep=None):
if s.rfind('.')>0:
rhs=s[s.rfind('.')+1:]
s=s[:s.rfind('.')-1]
if len(s) <= 3: return s + dSep + rhs
return splitThousands(s[:-3], tSep) + tSep + s[-3:] + dSep + rhs
else:
# This all assumes you have the process running in
# a terminal screen and you're on Linux-like system.
# First off, suspend the process and background it
ctrl-z # suspend the process
bg # restart/continue the process in the background
# Now create files to log to. They can be called anything,
# Personally I would end the in .log. E.g. could be
# /var/logs/myprocess-stdout.log,
@mariorz
mariorz / compile_handlebars.sh
Created April 29, 2012 22:34
Handlebar compilation with name-spacing and folder structure
#! /usr/bin/env sh
# Detects files inside static/js/apps/<app_name>/templates
# compiles files to static/js/var/apps/<app_name>/templates
# Example: static/js/apps/cms/templates
TEMPLATE_DIR="static/js/apps"
TEMPLATE_DIR_TAIL="templates"
TEMPLATE_FILES_DELIMITER=":*:"
TEMPLATE_FILES=""
@mariorz
mariorz / nginx log ip counter
Last active December 17, 2015 19:29
store and count unique IPs in nginx logs
cat <(cat /var/log/nginx/access.log /var/log/nginx/access.log.1 | grep /apath | awk '{print $1}') ips.txt | sort | uniq > tmp.txt; mv tmp.txt ips.txt; cat ips.txt | wc -l
@mariorz
mariorz / PGPKey
Created July 3, 2013 05:35
my key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.19 (Darwin)
mQGNBFHTsngBDADEZKbugBiONcWj0CtQ+1vM1zXVecK7YRca/8ot60jLDIanzQX+
/XIaD15s6kmXbeOTlLLNGpbODksfJgr9JCptTz4RxgXMGtAgY5/kRoAf7Q2eVCmd
g/MK7xCq+TLGk7w/pjZRmXpcDGMr+OTVElEJ8gP5JjxFvLVZe0SKHlI+x77LAKLi
igyJvxu3u9ME3jV9FDg/RZKaA4aDkHw3N/jeQiZNIbk6iexHfNG3IdAkRx4NVLc9
uyUcYeIrWBOCj/A5hLIwv8MtDt5p+LpQiVRrc9M3br+VTLyHx8VASqm3QyKV9jN8
S4N7AOKry9Q4TLhSlQnOmfmx0rw6msalZRdS1bug3UMrudcbS7nCaY0/ZBdPuC3M
e5WpUqCuM60r4/ElHu4bcF4975yJ0j2QKRzryyrZW+SlH+gysOh4rIz++9WNQ3DA

Keybase proof

I hereby claim:

  • I am mariorz on github.
  • I am mariorz (https://keybase.io/mariorz) on keybase.
  • I have a public key whose fingerprint is 89FC 44A9 8DB1 EE76 357B B3B4 5F73 759F F22A A421

To claim this, I am signing this object:

@mariorz
mariorz / 0_reuse_code.js
Created June 5, 2014 05:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#! /usr/bin/env python
# avahi-alias.py
import time
import sys
import locale
import dbus
import avahi
from encodings.idna import ToASCII
{
"width": 900,
"height": 600,
"data": {
"values": [
{
"item": "Guanajuato",
"pos": 53,
"negs": 852,
"cdratio": 1,
from decimal import Decimal
import itertools
import coinbasepro as cbp
def compute_coinbase_attack_cost():
client = cbp.PublicClient()
#get last 10000 trades, for good measure
trades = list(itertools.islice(client.get_product_trades('DAI-USDC'), 10000))
#filter for off-price trades