Skip to content

Instantly share code, notes, and snippets.

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@821760408-sp
821760408-sp / asyncio_producer_consumer.py
Created February 28, 2019 20:23
producer-consumer example using python asyncio
async def do_something():
for _ in range(3):
await produce()
await asyncio.sleep(5)
async def produce():
id_ = str(uuid.uuid4())
global global_task_queue
task = str(uuid.uuid4()) + ': CONSUME ME IN ' + str(randint(5, 9))
@821760408-sp
821760408-sp / gist:60c786cd8beabffc72e17627be180be2
Last active January 6, 2019 05:37 — forked from pazdera/gist:1098129
Singleton example in Python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Example of Singleton design pattern
# Copyright (C) 2011 Radek Pazdera
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@821760408-sp
821760408-sp / redis_py_watch_behaviror.py
Last active January 5, 2019 23:28
Observe redis-py behavior with "watch" in pipeline
import redis
r = redis.Redis()
r.set('target-key', 1)
with r.pipeline() as pipe:
artificial_race_condition_flag = True # Create race condition the first time pipeline executes
while True: # Keep retrying until success
try:
@821760408-sp
821760408-sp / main.rs
Created November 27, 2018 06:33
solution to the section "Limitations of the Cacher Implementation" of Chapter 13 from the book "The Rust Programming Language"
#![allow(unused_variables)]
fn main() {
let simulated_user_specified_value = 100;
let simulated_random_number = 30;
generate_workout(
simulated_user_specified_value,
simulated_random_number
);
}
@821760408-sp
821760408-sp / cronjob
Created February 8, 2018 16:33
cron job for fetching remote git repo
*/5 * * * * . /path/to/.ssh/agent/ssh_agent && cd /path/to/local/repo && (echo "<<<<<<<<<<<<<<<< fetching all from remote" && /bin/date "+DATE: \%m-\%d-\%Y TIME: \%H:\%M:\%S" && /usr/local/bin/git fetch --all --prune && echo ">>>>>>>>>>>>>>>> done fetching") >> cron.out 2>&1
@821760408-sp
821760408-sp / dockertags.sh
Created September 20, 2017 22:14
List all tags for a Docker image in Docker Hub
#!/bin/bash
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image on a remote registry.
EXAMPLE:
- list all tags for ubuntu:
@821760408-sp
821760408-sp / parse_mbox.py
Last active February 23, 2017 19:20
Parse mbox file from Gmail
import mailbox
def read_mbox(mbox_path, username):
box = mailbox.mbox(mbox_path)
payload = []
for msg in box:
payload.append(read_payload(msg, msg)) #if msg['from'].find(username) != -1 else ''
return ''.join(payload)
@821760408-sp
821760408-sp / updates.sh
Created November 19, 2016 22:27
Updates
#!/bin/bash
apt-get update &&
apt-get check &&
apt-get upgrade -f &&
apt-get dist-upgrade -f &&
dpkg --configure -a &&
apt-get autoclean &&
apt-get autoremove -f &&
aptitude purge '~c'
@821760408-sp
821760408-sp / digits.md
Last active September 6, 2016 18:08 — forked from joyofdata/digits.md
Installing CUDA, cuDNN, caffe and DIGITS on EC2