Skip to content

Instantly share code, notes, and snippets.

@habedi
habedi / avconv_examples.sh
Created November 12, 2016 16:39 — forked from romuloceccon/avconv_examples.sh
avconv command lines to reduce video size
# https://trac.ffmpeg.org/wiki/Encode/H.264
# https://trac.ffmpeg.org/wiki/Encode/AAC
# -map 0 -c copy: copy all remaining streams
# -pix_fmt yuv420p: be compatible with most players
# high quality video, high quality audio
avconv -i input.mov -map 0 -c copy -c:v libx264 -preset veryslow -pix_fmt yuv420p -crf 17 -c:a libfdk_aac -vbr 4 output.mov
# high quality *compatible* full-hd video, high quality audio
@habedi
habedi / web-servers.md
Created November 11, 2016 16:50 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@habedi
habedi / disk-usage.py
Created August 22, 2016 12:29
A python snippet to figure out disk usage
import os
from collections import namedtuple
disk_ntuple = namedtuple('partition', 'device mountpoint fstype')
usage_ntuple = namedtuple('usage', 'total used free percent')
def disk_partitions(all=False):
"""Return all mountd partitions as a nameduple.
If all == False return phyisical partitions only.
"""
# coding=utf-8
"""
LICENSE http://www.apache.org/licenses/LICENSE-2.0
"""
import datetime
import sys
import time
import threading
import traceback
import SocketServer
@habedi
habedi / soakee.rkt
Created June 30, 2016 19:49 — forked from tonyg/soakee.rkt
Soak-testing Racket's UDP
#lang racket
(require racket/udp)
(define count 0)
(define s (udp-open-socket #f #f))
(udp-bind! s #f 12346)
(define buffer (make-bytes 1024))
(ns echo-server
(:import (java.net InetAddress DatagramPacket DatagramSocket)))
(def udp-server (ref nil))
(def port 12345)
(defn localhost [] (. InetAddress getLocalHost))
(defn message [text]
@habedi
habedi / simple_server.py
Created June 14, 2016 05:21 — forked from trungly/simple_server.py
A simple Python HTTP server that supports a GET that echoes some request data and a POST that reads a request body, parses it as JSON and reponses with part of the data
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse, json
class GetHandler(BaseHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse.urlparse(self.path)
message = '\n'.join([
'CLIENT VALUES:',
'client_address=%s (%s)' % (self.client_address,
@habedi
habedi / gist:3a9dd03cec22acaa2bef3e29f32b613e
Created May 29, 2016 08:56
git clone all remote branches locally
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
@habedi
habedi / latency.txt
Created May 27, 2016 08:10 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@habedi
habedi / gist:0e0a66d1f7bcdfd35483c65739d3eaca
Created May 16, 2016 12:11 — forked from collina/gist:5521087
Blocking on Transfer with UDP on Arbitrary Ports in #Iran
root@nami:~# tcpdump -r random_traffic_port_8082_udp.pcap | head
reading from file random_traffic_port_8082_udp.pcap, link-type EN10MB (Ethernet)
19:40:58.250303 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.250640 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.251200 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.251358 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.251566 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.252529 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.252711 IP internationalhost.35447 > nami.8082: UDP, length 2048
19:40:58.252975 IP internationalhost.35447 > nami.8082: UDP, length 2048