Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -euo pipefail
# readonly SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
function process() {
python - << END_OF_PY_CODE
import os
@DavidPu
DavidPu / sed_cheatsheet.md
Last active September 26, 2017 16:41
sed cheatsheet
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=816533
# start at server side(ssh)
xpra start --no-daemon --xvfb="/usr/bin/Xvfb +extension Composite -screen 0 3840x2560x24+32 -nolisten tcp -noreset" --start=/usr/bin/code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
class FSO(object):
import win32com.client as com
import pywintypes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def happy_number(val):
nums = []
nums.append(val)
while True:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import BaseHTTPServer
import SimpleHTTPServer
import argparse
import socket
parser = argparse.ArgumentParser()
parser.add_argument('-b', action='store', dest='host',
def check_string(s):
mstack = []
bFind = False
matches = {')': '(', '}': '{', ']': '['}
for c in s:
if c in matches.values():
bFind = True
mstack.append(c)
elif c in matches.keys():
if len(mstack) == 0 or mstack[-1] != matches[c]:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def maxsum(arr):
# maxsum, start, end:
result = [arr[0], 0, 0]
curr = [0, 0, 0]
for i in range(0, len(arr)):
@DavidPu
DavidPu / bitmap.c
Last active February 15, 2017 18:09
bitmap
#include <stdlib.h>
#include <stdio.h>
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)
#define BIT(x) (1UL<<OFF(x))
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
#define FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
@DavidPu
DavidPu / setclocks.sh
Last active August 29, 2015 14:21
fix jetson tk1 cpu/gpu/emc clocks to specific frequency.
#!/bin/bash
#usage:
# $source setclocks.sh
# $setxxfreq ..
#set -x
function setcpufreq()
{
if [ -z $1 ]; then
echo "usage:setcpufreq <CPUFREQ in kHz>|max [ONLINECPUS](default 4)"
echo "e.g: setcpufreq max or setcpufreq max 2"