Skip to content

Instantly share code, notes, and snippets.

@airekans
airekans / wxLuaWindow.cpp
Last active December 16, 2015 19:09
wxLua wrapper to make use wxLua easier.
#include "wxbind/include/wxbinddefs.h"
#include "wxbind/include/wxcore_bind.h"
WXLUA_DECLARE_BIND_ALL
wxLuaState& GetWxLuaState()
{
struct wxLuaStateInstance
{
@airekans
airekans / consecutive.py
Last active October 14, 2019 20:07
在一个无序数组里面,找到最长的连续数区间。除了用O(lg n)的排序之外,还有没有O(n)的方法?
# 实际上,下面的解法不是O(n),而是O(n + k),其中k是出现数字的区间大小。
def consecutive(numbers):
# get the min and max of the numbers
min, max = None, None
for n in numbers:
if min is None or min > n:
min = n
if max is None or max < n:
max = n
@airekans
airekans / test_sqlalchemy.py
Last active December 18, 2015 15:18
用SQLAlchemy的declarative_base作为基类并且用了relationship属性的类不会被垃圾回收? 下面的程序输出是: 3 <__main__.Type object at 0x268a490>
from sqlalchemy import (create_engine, Column, select, case, func, ForeignKey)
from sqlalchemy import Integer, String, Boolean
from sqlalchemy.orm import sessionmaker, MapperExtension, aliased
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
import weakref
import sys
import gc
engine = create_engine('sqlite://', echo=True)
@airekans
airekans / .pythonrc.py
Created June 21, 2013 05:36
A python auto-complete startup config
import os
import sys # import sys and os for convinience
import readline
import rlcompleter
# change autocomplete to tab
readline.parse_and_bind("tab: complete")
del readline, rlcompleter
@airekans
airekans / email.py
Created July 25, 2013 09:57
Detect jekyll failure and sending email in Python.
#! /usr/bin/env python
import smtplib
import subprocess
import os
import sys
from email.mime.text import MIMEText
_MAIL_SERVER = "192.168.1.100"
@airekans
airekans / euler_point.cpp
Created August 2, 2013 05:43
在一个椭圆形的土地内,给定椭圆边上的n个点,两两之间连线,最多能将这个土地分成多少块? 思路:欧拉公式 V - E + F = 2
int main(int argc, char** argv)
{
// solution here.
return 0;
}
#include <cstdio>
#include <cctype>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
bool is_start = false;
int count = 0;
@airekans
airekans / BinarySearch.cpp
Last active December 20, 2015 13:29
Sorting Algorithm
#include <iostream>
using namespace std;
int binary_search(int array[], const int size, const int elem)
{
int left = 0;
int right = size;
@airekans
airekans / test_new_handler.cpp
Created August 5, 2013 09:47
A simple program used to test new handler.
#include <iostream>
#include <unistd.h>
#include <cstring>
#include <new>
using namespace std;
struct ListNode
{
@airekans
airekans / char_unique.cpp
Last active December 20, 2015 16:59
[OJ] Careercup Top 150(1.1): Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? Solution: use a character code hash table.
static int count[256];
bool unique(const std::string& s)
{
memset(count, 0, sizeof(count));
const int size = s.size();
for (int i = 0; i < size; ++i)
{
if (count[s[i]] > 0)
{