Skip to content

Instantly share code, notes, and snippets.

View limboinf's full-sized avatar
🎯
Focusing

limbo limboinf

🎯
Focusing
View GitHub Profile
@limboinf
limboinf / gist:9777756
Created March 26, 2014 06:24
Mysql常用日期时间函数
#天数
TO_DAYS(NOW())-TO_DAYS(t.end_time) = 1
#分钟
TIMESTAMPDIFF(MINUTE,ms.add_date,NOW()) =3600
#几天前
DATE_SUB(NOW(),INTERVAL 7 DAY)
# 分组排名
@limboinf
limboinf / FibonacciDecorator.py
Last active August 29, 2015 14:20
Fibonacci decorator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def memoize(f):
cache = {}
def helper(x):
if x not in cache:
cache[x] = f(x)
return cache[x]
return helper
@limboinf
limboinf / musg.sql
Created June 2, 2015 05:34
mysql update whit select and group by
-- update table with select and group by statement
-- Ohs my poor SQL.
-- contacts:beginman.cn
update group_info as g
left join (
select gi.group_id, count(gm.id) as nums from group_info gi
inner join group_members gm on gm.group_id = gi.group_id
group by gm.group_id
)
@limboinf
limboinf / pic_bin.py
Created July 2, 2015 02:57
图片>>base64>>二进制文本 转换
#coding=utf-8
__author__ = 'beginman'
__describe__ = '图片>>base64>>二进制文本 转换'
import binascii
import re
def pic2bin(data):
b64 = binascii.b2a_base64(data)
j = 0
@limboinf
limboinf / p12Topem.md
Created July 31, 2015 03:34
p12 to pem
openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys
openssl pkcs12 -in path.p12 -out newfile.key.pem -nocerts -nodes

After that you have:

certificate in newfile.crt.pem

private key in newfile.key.pem

@limboinf
limboinf / torndb.ex.py
Last active January 19, 2016 07:11 — forked from damozhang/torndb.ex.py
Examples of that how to use Torndb.
import torndb
mysql_settings = {
'host': 'localhost:3306',
'user': 'user',
'password': 'password',
'database': 'database',
'time_zone': '-8:00',
'charset': 'utf8'
@limboinf
limboinf / flask-sse.py
Created February 25, 2016 08:22
flask SSE.
# coding=utf-8
# Make sure your gevent version is >= 1.0
import gevent
from gevent.wsgi import WSGIServer
from gevent.queue import Queue
from flask import Flask, Response
import time
@limboinf
limboinf / bit_op_to_check_even.c
Created March 28, 2016 08:43
bit operation to check even
/*
** 右移计算值为1的位的个数
** 接收一个无符号参数,避免右移歧义
*/
int
count_one_bits(unsigned value)
{
int ones;
for (ones = 0; value != 0; value = value >> 1) {
printf("%d\n", value);
@limboinf
limboinf / point_to_arr.c
Created March 31, 2016 02:59
指向数组的指针与多维数组
#http://docs.linuxtone.org/ebooks/C&CPP/c/ch23s07.html
#include <stdio.h>
int main(int argc, const char * argv[]) {
char a[4][3][2] = {
{
{'a', 'b'}, {'c', 'd'}, {'e', 'f'}
},
{
{'g', 'h'}, {'i', 'j'}, {'k', 'l'}
@limboinf
limboinf / main.c
Created March 31, 2016 06:24
C两层指针的参数
#include <stdio.h>
#include "redirect_ptr.h"
/*
总结一下,两层指针参数如果是传出的,可以有两种情况:
第一种情况,传出的指针指向静态内存(比如上面的例子),或者指向已分配的动态内存(比如指向某个链表的节点);
第二种情况是在函数中动态分配内存,然后传出的指针指向这块内存空间.
这种情况下调用者应该在使用内存之后调用释放内存的函数,调用者的责任是请求分配和请求释放内存,
实现者的责任是完成分配内存和释放内存的操作。
由于这两种情况的函数接口相同,应该在文档中说明是哪一种情况。