Skip to content

Instantly share code, notes, and snippets.

View vejuhust's full-sized avatar
🎯
Focusing

Vej vejuhust

🎯
Focusing
  • Beijing, China
View GitHub Profile
@vejuhust
vejuhust / rdtsc.c
Created October 5, 2012 06:03
Read Time Stamp Counter from Intel x86 CPU
#include <stdio.h>
int main (int argc, const char * argv[]) {
unsigned int hi;
unsigned int lo;
long double result;
/* Set *hi and *lo to the high and low order bits of the cycle counter.
Implementation requires assembly code to use the rdtsc instruction. */
asm("rdtsc; movl %%edx,%0; movl %%eax,%1" /* Read cycle counter */
@vejuhust
vejuhust / json_test.php
Last active December 14, 2015 07:09
a json testing controller in CodeIgniter.
<?php
class Json_test extends Controller {
public function setter() {
$fp = fopen("/tmp/json_test.txt","w");
$content = json_encode($_POST);
fwrite($fp, $content, strlen($content));
fclose($fp);
echo $content;
}
@vejuhust
vejuhust / printallccode.sh
Last active December 15, 2015 09:19
print all c code in this folder
#!/bin/sh
TARGETFILE=allinone.c
if [ -e "$TARGETFILE" ]; then
rm -f "$TARGETFILE"
fi
if [ -n "$1" ]; then
printf "$1""\n" >> "$TARGETFILE"
@vejuhust
vejuhust / listdate.py
Created January 5, 2014 09:28
List past 20 days
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from datetime import datetime
from datetime import timedelta
now = datetime.now()
delta_day = timedelta(days = -1)
for i in range(21):
now += delta_day
@vejuhust
vejuhust / estimated.py
Created January 9, 2014 15:31
In Agile development, we usually use hours to estimate our projects, and it's not easy to make it accurate. This little tool might be useful to you.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
x = int(raw_input("how many work items do you have? "))
hours = [4,6,6,8,8,8,8,10,10,12,14]
for i in range(x):
print random.choice(hours)
@vejuhust
vejuhust / combine.sh
Last active August 29, 2015 14:02
using imagemagick to append bottom parts of other images to the first one
#!/bin/bash
if [ $# -lt 1 ]; then
percent=13
printf "percent missing: using default value "$percent" %% \n"
else
percent=$1
fi
type=png

ffmpeg

install

apt-add-repository ppa:jon-severinsson/ffmpeg
apt-get update
apt-get install ffmpeg

generate silent film

@vejuhust
vejuhust / raspi-buy
Created September 25, 2014 16:41
Shopping List for Raspberry Pi B+
Raspberry Pi
http://item.taobao.com/item.htm?spm=a1z09.2.9.10.MbZ8cB&id=38987175483&_u=p30n4aoe69b
Shell
http://item.taobao.com/item.htm?spm=a1z09.2.9.40.MbZ8cB&id=40236827770&_u=p30n4ao46eb
Heat sink
http://item.taobao.com/item.htm?spm=a1z09.2.9.30.MbZ8cB&id=40272781292&_u=p30n4aoa8ab
Camera wire
@vejuhust
vejuhust / vej_bash_alias.sh
Created February 13, 2015 12:54
# Also write this to .bashrc if it doesn’t contain if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
function gp() {
if [ $# -eq 0 ];
then
count=10
else
count=$1
fi
cat /dev/urandom | tr -dc "a-zA-Z0-9" | fold -w 16 | head -n $count
}