Skip to content

Instantly share code, notes, and snippets.

Jingchao Hu observerss

Block or report user

Report or block observerss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@observerss
observerss / AioPool.md
Last active Aug 29, 2015
Gevent pool/group alike in python3 asyncio
View AioPool.md

Gevent Pool/Group Alike in Python3 Asyncio

Python3 Asyncio implements an event loop, but in quite low level, it's missing some basic helpers that can make your life a lot easier.

The Pool and Group are typical missing ones. Compare these codes below

Simple Loop

  • without group
View optimizing_python_for_scientific_computing
{
"metadata": {
"name": "",
"signature": "sha256:f7fc0e66200bb5a9cae8e5e59abfaa99691caa881252e9266f11e7cffc7dafe6"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@observerss
observerss / GLOW_PUZZLE.md
Last active Jan 4, 2016
glowing's job puzzle
View GLOW_PUZZLE.md
@observerss
observerss / RedisAsDB.rst
Last active Apr 30, 2018
Redis as database: dealing with indexes and composite indexes
View RedisAsDB.rst

Using Reids As Database

Redis is very performant, due to performance consideration, sometimes we need to use Redis as a database, when querying a redis database, we need to consider indexing and filtering.

Single Index

We can use SortedSet as Index.

@observerss
observerss / throttled_call.py
Created Oct 12, 2013
Python snippet that throttles a function call. This is useful when the function request a remote service that having throttling policy. We must honor the throttling, otherwise we will be banned.
View throttled_call.py
import time
from collections import deque
def throttled_call(func, args=(), kwargs={}, threshold_per_minute=60):
"""Throttling the function call with ``threshold_per_minute`` calls per minute.
This is useful when the function request a remote service that having throttling policy.
We must honor the throttling, otherwise we will be banned.
:param func: the function to be called
View matrix_traverse.py
def chop(matrix, box, direction, results=None):
if results is None:
results = []
x1, y1, x2, y2 = box
w = x2 - x1 + 1
h = y2 - y1 + 1
if w <= 0 or h <= 0:
return results
else:
if direction == 0:
View redis.markdown

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

View redis-server-for-init.d-startup
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@observerss
observerss / etc-init-elasticsearch.conf
Last active Dec 19, 2015 — forked from jaytaylor/etc-init-elasticsearch.conf
elasticsearch upstart script for official deb packages (tested with 0.90.2)
View etc-init-elasticsearch.conf
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
respawn
View PrettyDate.js
/*
Pretty Date script modified from John Resig here http://ejohn.org/blog/javascript-pretty-date
*/
function relativeDateTime (tdate) {
var system_date;
if (typeof (tdate) === "number") {
tdate = new Date(tdate).toString();
}
if (navigator.userAgent.match(/MSIE\s([^;]*)/)) {
You can’t perform that action at this time.