Skip to content

Instantly share code, notes, and snippets.

View nima's full-sized avatar

Nima Talebi nima

  • Amazon
  • Seattle, WA
View GitHub Profile
$ grep hosts /etc/nsswitch.conf
hosts: files dns
$ grep hosty.products /etc/hosts
127.1.1.1 hosty.products.site.org hosty.products
$ strace -e open,connect getent hosts hosty.products
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
@nima
nima / vim-red-after-80.vim
Last active August 29, 2015 13:56
Warn after 80-characters, with a toggle switch
set colorcolumn=81,82,83,84
au! FileType gitcommit set colorcolumn=71,72,73,74
let s:color_column_old = 0
function! s:ToggleColorColumn()
if s:color_column_old == 0
let s:color_column_old = &colorcolumn
windo let &colorcolumn = 0
else
windo let &colorcolumn=s:color_column_old
let s:color_column_old = 0
#!/usr/bin/env python
def encrypt(x):
return [((a+1)*ord(b)%256) for a,b in zip(range(len(x)), x)]
def decrypt(a):
for i in range(len(a)):
while not (a[i] % (i+1) == 0 and a[i]/(i+1) in range(48,123)):
a[i] += 256
a[i] /= (i+1)
@nima
nima / .gitconfig
Created March 13, 2016 02:55
gitconfig
[merge]
tool = vimdiff
[user]
name = Nima Talebi
email = ntd@amazon.com
#name = Nima Talebi
#email = me@nima.id.au
@nima
nima / hgd-validate.bash
Created December 14, 2016 01:33
Validates HGD string
function validate() {
let -i e=0
let -i balance=0
let -i opset=0
local ch
for (( i=0; i<${#1}; i++ )); do
ch="${1:$i:1}"
case "${ch}" in
@nima
nima / .vimrc
Created December 21, 2016 01:47
Vim RC
". BEGIN -={
let g:solarized_termcolors=256
"let colortheme="solarized"
". advantage candy distinguished earendel gentooish
". grb256 inkpot jellybeans liquidcarbon moria
". nu42dark twilight vividchalk wombat zenburn
". molokai mustang koehler blue darkblue
". default delek desert elflord evening
@nima
nima / toys#pointers.c
Last active December 27, 2016 00:19
C, Go, and Pointers
int fn_b(int a, int b) { return a % b; }
int fn_c1(int a, int b, int c) { return a + b + c; }
int fn_c2(int a, int b, int c) { return a * b * c; }
int (*fn_d(int (*x)(int, int), int y))(int, int, int) {
return x(y, 2) ? fn_c1 : fn_c2;
}
@nima
nima / bash-var-operators.sh
Created March 28, 2017 23:21
How the various bash operators work
#!/bin/bash
cat <<!
+--------------+-----------------+-----------------+-----------------+
| | var | var | var |
| Statement | SetNotNull | SetButNull | Unset |
+--------------+-----------------+-----------------+-----------------+
| \${var:-word} | substitute var | substitute word | substitute word |
| \${var-word} | substitute var | substitute null | substitute word |
| \${var:=word} | substitute var | assign word | assign word |
@nima
nima / catan-odds.py
Last active January 18, 2018 05:18
CatanOdds
#!/usr/bin/env python
import operator as op
import sys
from decimal import Decimal
import decimal
decimal.getcontext().prec = 6
def ncr(n, r):