Skip to content

Instantly share code, notes, and snippets.

@whitekid
whitekid / encdec.py
Last active August 29, 2015 14:23
Simple AES encrypt/decrypt
"""
Usage:
cat '1234567890123456' > secret.key
echo "hello world" | python encdec.py | python encdec.py -d
"""
import sys
import base64
import getopt
@whitekid
whitekid / json_parse.go
Last active August 29, 2015 14:23
json_parse.go
var i interface{}
b := []byte(json_data)
json.Unmarshal(b, &i)
v := i.(map[string]interface{})
data := v["data"].(string)
fmt.Printf("data = %v\n", data)
@whitekid
whitekid / ogg2mp3.py
Last active May 10, 2024 09:51
convert ogg to mp3 with ffmpeg
import os, sys
import fnmatch
import subprocess
import multiprocessing
from multiprocessing.pool import ThreadPool
def iter_files(root, pattern):
for root, dirs, files in os.walk(root):
for f in files:
if not fnmatch.fnmatch(f, pattern): continue
import unittest
import oslo_cache.core as cache
from oslo_config import cfg
CONF = cfg.CONF
class CacheTest(unittest.TestCase):
def get_client(self):
cache.configure(CONF)
#!/bin/bash
if [ "`cat /sys/kernel/mm/ksm/run`" -ne 1 ] ; then
echo 'KSM is not enabled. Run echo 1 > /sys/kernel/mm/ksm/run' to enable it.
exit 1
fi
echo Shared memory is $((`cat /sys/kernel/mm/ksm/pages_shared`*`getconf PAGE_SIZE`/1024/1024)) MB
echo Saved memory is $((`cat /sys/kernel/mm/ksm/pages_sharing`*`getconf PAGE_SIZE`/1024/1024)) MB
if ! `type bc &>/dev/null` ; then
echo "bc is missing or not in path, skipping ratio calculation"
exit 1
@whitekid
whitekid / swap_file.sh
Last active September 21, 2015 09:04
swap file creation & resize
#!/bin/bash
swap_file=/swap0
usage(){
echo "Usage:"
echo " $0 0 disable swap file"
echo " $0 size create swap file"
}
make_swap(){
@whitekid
whitekid / Job.scala
Last active October 21, 2015 12:02
Just simple topic forward with flink
// tested flink 0.9.1
object Job {
def main(args: Array[String]) {
// set up the execution environment
val env = StreamExecutionEnvironment.getExecutionEnvironment
val properties = new Properties
var bootstrap_servers = "<kafka-server>:9092"
properties.setProperty("bootstrap.servers", bootstrap_servers)
properties.setProperty("zookeeper.connect", "<zookeeper-server>:2181")
# dev
.git
**/*.sw*
**/tags
*.sublime*
# docker
Dockerfile*
.dockerignore
docker-compose.yml
def get_servers(opts={}):
limit = 500
marker = None
opts['limit'] = limit
while True:
servers = client.servers.list(search_opts=opts, marker=marker)
for server in servers:
from urlparse import urlsplit, urlunsplit
def url_path_join(*parts):
"""Join and normalize url path parts with a slash."""
schemes, netlocs, paths, queries, fragments = \
zip(*(urlsplit(part) for part in parts))
scheme = next((x for x in schemes if x), '')
netloc = next((x for x in netlocs if x), '')