Skip to content

Instantly share code, notes, and snippets.

View sdvcrx's full-sized avatar
🎯
Focusing

sdvcrx sdvcrx

🎯
Focusing
View GitHub Profile
@sdvcrx
sdvcrx / inplace_swap.c
Created August 6, 2013 12:44
无中间变量交换两值
void inplace_swap(int *x, int *y)
{
*y = *x ^ *y;
*x = *x ^ *y;
*y = *x ^ *y;
}
@sdvcrx
sdvcrx / endian.c
Created August 8, 2013 03:14
辨别系统是64位 or 32位以及大小端
#include <stdio.h>
int main(void)
{
int a = 0x80000000;
printf("os is %d\t%d\n", a, sizeof(int));
union ut {
short s;
char c[2];
} u;
@sdvcrx
sdvcrx / backup.sh
Created August 10, 2013 13:37
MySQL简单的备份恢复(mysqldump)
mysqldump -u root -p linuxcast > linuxcast_backup.sql
mysql -u root -p linuxcast < linuxcast_backup.sql
@sdvcrx
sdvcrx / MultiBaseOutput.c
Created August 17, 2013 14:40
数制转换
#include <stdio.h>
#define MAXSIZE 25
#define OK 1
#define ERROR 0
typedef int Status;
typedef int SElemType;
typedef struct {
SElemType data[MAXSIZE];
@sdvcrx
sdvcrx / thunder.py
Created August 20, 2013 01:33
迅雷链接转换
import base64
def xunlei_url_encode(url):
return 'thunder://'+base64.encodestring('AA'+url+'ZZ').replace('\n', '')
def xunlei_url_decode(url):
assert url.startswith('thunder://')
url = base64.decodestring(url[10:])
assert url.startswith('AA') and url.endswith('ZZ')
return url[2:-2]
@sdvcrx
sdvcrx / bucket.c
Created September 22, 2013 07:20
木桶排序
#include <stdio.h>
#define MAXNUM 100 // Count数组大小(M)
/* 功能:桶式排序
* 输入: 待排序数组arrayForSort[]
* 待排序数组大小arraySize (N)
* 上界maxitem,元素都落在[0, maxitem]
* 输出 void
* 时间复杂度 O(M+N)
*/
@sdvcrx
sdvcrx / equalSymbol
Created October 1, 2013 10:10
平衡符号
int checkSymbol(Stack S){
char ch;
while((ch = getchar()) != '#'){
if(ch == '(' || ch == '[' || ch == '{'){
Push(ch, S);
}
else if(ch == ')' || ch == ']' || ch == '}'){
if(isEmpty(S))
Error("Stack is empty");
else{
@sdvcrx
sdvcrx / upper.c
Created November 26, 2013 12:06
learn how to use exec and what is file descriptor
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int ch;
while((ch = getchar()) != EOF) {
putchar(toupper(ch));
}
return 0;
@sdvcrx
sdvcrx / uniqify_list.py
Created December 26, 2013 08:29
去除list中相同项的最快的方法
def uniqify_list(seq):
seen = Set()
return [x for x in seq if x not in seen and not seen.add(x)]
@sdvcrx
sdvcrx / argparser.py
Created December 27, 2013 14:33
arg parser
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosity", action="count", default=0,
help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2
if args.verbosity >= 2:
print "the square of {} equals {}".format(args.square, answer)