Skip to content

Instantly share code, notes, and snippets.

@jedy
jedy / compare_version.c
Last active August 29, 2015 14:00
compare version
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int compareVersion(const char *v1, const char *v2)
{
char *f1, *f2, *s1, *s2;
int n1, n2, r;
f1 = s1 = strdup(v1);
f2 = s2 = strdup(v2);
@jedy
jedy / copy_to_clipboard.py
Created April 10, 2015 10:11
copy figure to windows clipboard
import matplotlib.pyplot as plt
from cStringIO import StringIO
import win32clipboard
from PIL import Image
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
@jedy
jedy / gray.go
Created June 15, 2015 02:14
gray code
func BinaryToGray(num uint) uint {
return (num >> 1) ^ num
}
func GrayToBinary(num uint) uint {
for mask := num >> 1; mask != 0; mask = mask >> 1 {
num = num ^ mask
}
return num
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style>
table {
border-collapse: collapse
}
</style>
<script src="jquery.min.js"></script>
<script>
function add_float_head(tid){
@jedy
jedy / tail_recurse.py
Created June 5, 2012 09:53
python尾递归
# This program shows off a python decorator(
# which implements tail call optimization. It
# does this by throwing an exception if it is
# it's own grandparent, and catching such
# exceptions to recall the stack.
import sys
class TailRecurseException:
def __init__(self, args, kwargs):
@jedy
jedy / ip_addr.py
Created June 5, 2012 09:55
get ip address
import socket
import fcntl
import struct
def get_ip_address(ifname):
"""
>>> get_ip_address('lo')
'127.0.0.1'
>>> get_ip_address('eth0')
@jedy
jedy / Monokai.tmTheme
Created June 25, 2012 12:34 — forked from anateus/Monokai.tmTheme
Monokai for Sublime Text: Markdown supported + some additional element differentiation
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Monokai</string>
<key>settings</key>
<array>
<dict>
@jedy
jedy / ExportHtml.py
Created June 28, 2012 03:49
fix color of exporthtml
import sublime
import sublime_plugin
from os import path
import tempfile
import sys
import datetime
import webbrowser
import re
from HtmlAnnotations import get_annotations
import ExportHtmlLib.desktop as desktop
# -*- coding: utf8 -*-
"""
使用java的模块SmartXLS[http://www.smartxls.com/indexj.htm]和jpype修改excel
和xlrd,xlwt不同的是它可以生成和保持图表
"""
from __future__ import print_function, division
import os
@jedy
jedy / lua_mem_usage.c
Last active October 14, 2015 09:17 — forked from AndrewTsao/lua_mem_usage.c
lua memory usage
#include <stdio.h>
#include <stdlib.h>
#include "lua5.1/lua.h"
#include "lua5.1/lauxlib.h"
#include "lua5.1/lualib.h"
// Measuring lua vm memory usage.
// build: gcc main.c -llua5.1 -lm -ldl -fPIC
static size_t mem_used = 0;