Skip to content

Instantly share code, notes, and snippets.

View tianchaijz's full-sized avatar
🏠
Working from home

tianchaijz tianchaijz

🏠
Working from home
View GitHub Profile
#!/bin/bash
set -e
# Usage:
# rsync_parallel.sh [--parallel=N] [rsync args...]
#
# Options:
# --parallel=N Use N parallel processes for transfer. Defaults to 10.
#
# Notes:
@tianchaijz
tianchaijz / git-push.sh
Last active August 29, 2015 14:10 — forked from KushalP/git-push.sh
#!/bin/sh
function gp {
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$(git push origin $CURRENT_BRANCH)
}
@tianchaijz
tianchaijz / tar_nc
Created November 26, 2014 07:26
tar and nc
# http://toast.djw.org.uk/tarpipe.html
Using netcat and tar to quickly transfer files between machines, aka tar pipe
So you have lots of data to transfer between two machines over ethernet. A nice quick and dirty method is to use netcat and tar. This is by no means secure, but if you haven't got the time or desire to setup NFS, FTP, Samba, or wait hours for scp to do its job then this can save you a lot of time.
Linux System using tar and netcat
On the receiving end do:
# netcat -l -p 7000 | tar x
And on the sending end do:

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
#!/bin/bash
choose_congestion_control="/proc/sys/net/ipv4/tcp_congestion_control"
ip=127.0.0.1
iperf -s
iperf_pid=$!
for i in $(ls /lib/modules/3.2.0-4-amd64/kernel/net/ipv4/tcp*); do
# transform the path from /lib/.../tcp_bic.ko to bic
@tianchaijz
tianchaijz / app.lua
Last active August 29, 2015 14:10 — forked from daurnimator/app.lua
if not sinatra.incoming ( ngx.req.get_method() , ngx.var.uri ) then
return ngx.exit ( 404 )
end
--
-- LPeg-based XML parser.
--
-- * Grammar term names are the same as in the XML 1.1
-- specification: http://www.w3.org/TR/xml11/
-- * Action functions are missing.
--
-- Copyright (C) 2012 Adrian Perez <[email protected]>
-- Distribute under terms of the MIT license.
--
@tianchaijz
tianchaijz / sslice.c
Last active August 29, 2015 14:10 — forked from cloudwu/sslice.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct sslice {
const char *ptr;
size_t sz;
};
int
package.cpath = "luaclib/?.so"
local socket = require "clientsocket"
local crypt = require "crypt"
local input = {}
local function readpackage()
local line = table.remove(input, 1)
if line then
@tianchaijz
tianchaijz / bsearch.c
Last active August 29, 2015 14:10 — forked from cloudwu/bsearch.c
int
binary_search_first_position(int *A, int n, int target) {
int end[2] = { -1, n };
while (end[0] + 1 < end[1]) {
int mid = (end[0] + end[1]) / 2;
int sign = (unsigned)(A[mid] - target) >> 31;
end[1-sign] = mid;
}
int high = end[1];
if (high >= n || A[high] != target)