Skip to content

Instantly share code, notes, and snippets.

from array import array
import bisect
import struct
import operator
import sys
class WordList(object):
def __init__(self, words):
self.buf = "".join(words)
self.offsets = array("L", [0])
@gleicon
gleicon / gDNS.py
Created July 10, 2011 03:31
gevent/dnslib/redis based DNS server
# dns server using dnslib and gevent
# based on https://bitbucket.org/paulc/dnslib/src/80d85555aae4/src/server/gevent_server.py
# set the key as
# set IP:name ip_addr
# set TXT:name txtfield
# fallback on gevent's dns resolver
# gleicon 2011
import gevent
@darrarski
darrarski / SystemIdleTime.m
Last active March 30, 2021 07:05
Get Mac OS X system idle time in Swift or Objective-C
//
// Created by Dariusz Rybicki on 17/04/16.
// Copyright © 2016 Darrarski. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
Returns number of seconds since system became idle
@sp3c73r2038
sp3c73r2038 / app.py
Last active May 24, 2021 11:51
how to acccess multiple database with same tablename, in Flask and SQLAlchemy.
# -*- coding: utf-8 -*-
from flask import Flask
from sqlalchemy import SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+oursql://foo:bar@localhost/test1"
# binds multiple database definition
app.config['SQLALCHEMY_BINDS'] = {
"db1": "mysql+oursql://foo:bar@localhost/test1",
@millermedeiros
millermedeiros / gist:891886
Created March 29, 2011 06:21
iPad HTML5 video quirks and hacks
/*
* Example how to preload HTML5 video on the iPad (iOS 3.2+)
* @author Miller Medeiros
* Released under WTFPL
*/
var vid = document.createElement('video');
vid.src = 'lol_catz.mp4';
document.getElementById('video-holder').appendChild(vid);
@dingyaguang117
dingyaguang117 / pdfformfiller.go
Last active April 19, 2023 18:29
Fill pdf form with pdfcpu
package render
import (
"bytes"
"fmt"
"math"
"github.com/pdfcpu/pdfcpu/pkg/api"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/validate"
@mrluanma
mrluanma / requirements.txt
Created September 4, 2012 14:40
Python 登录新浪微博(requests 真的比 urllib2 强了 2^^32 倍 pip install requests)
requests==2.4.3
rsa==3.1.4
@Morreski
Morreski / timed_cache.py
Last active December 21, 2023 18:17
Python lru_cache with timeout
from datetime import datetime, timedelta
import functools
def timed_cache(**timedelta_kwargs):
def _wrapper(f):
update_delta = timedelta(**timedelta_kwargs)
next_update = datetime.utcnow() + update_delta
# Apply @lru_cache to f with no cache size limit
#!/usr/bin/env python2
# lrdcq
# usage python2 unwxapkg.py filename
import sys, os
import struct
class WxapkgFile(object):
nameLen = 0
@MikeNGarrett
MikeNGarrett / siege
Last active April 3, 2024 03:49
Siege with JSON POST data
# Changed to use content-type flag instead of header: -H 'Content-Type: application/json'
siege -c50 -t60S --content-type "application/json" 'http://domain.com/path/to/json.php POST {"ids": ["1","2","3"]}'