Skip to content

Instantly share code, notes, and snippets.

View yaodong's full-sized avatar

Yaodong Zhao yaodong

View GitHub Profile
from binascii import crc32
from app import models, db
from os import path
import inflect
import yaml
MAX_ID = 1073741823 # 2 ** 30 -1
inf = inflect.engine()
query = some_model.query.filter_by(a=b)
count_q = query.statement.with_only_columns([db.func.count()]).order_by(None)
count = query.session.execute(count_q).scalar()
return count
from cryptography.fernet import Fernet
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.types import TypeDecorator, BINARY
secret_key = 'change me!'
class EncryptedTypeBase(TypeDecorator):
impl = BINARY
def process_bind_param(self, value, dialect):
const $ = require('jquery');
class Modal {
constructor($trigger) {
this.trigger = $trigger;
this.target = $trigger.data('target');
this.id = this.target.slice(1);
if (!$(this.target).length) {
@yaodong
yaodong / time-stamp.el
Created July 12, 2016 06:52
emacs, org-mode, replace time stamp when saving
(add-hook 'before-save-hook 'time-stamp)
(setq time-stamp-pattern "8/Time-stamp:[ \t]+\\\\?[\"<]+%:y-%02m-%02d %3a %02H:%02M\\\\?[\">]")
@yaodong
yaodong / github_flask_oauth2.py
Last active June 3, 2016 18:49 — forked from ib-lundgren/github_flask_oauth2.py
Example of how to use Flask with requests-oauthlib to fetch a GitHub user profile using an OAuth 2 token.
from requests_oauthlib import OAuth2Session
from flask import Flask, request, redirect, session, url_for
from flask.json import jsonify
import os
app = Flask(__name__)
# This information is obtained upon registration of a new GitHub
client_id = "<your client key>"
sudo apt-get update && apt-get install vim wget build-essential -y
sudo apt-get install guile-2.0 guile-2.0-dev hdf5-* -y
export LDFLAGS="-L/usr/local/lib -lm"
export CPPFLAGS="-I/usr/local/include"
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
export PATH=/lib64/mpich/bin:$PATH
cd ~ && wget http://www.fftw.org/fftw-3.3.4.tar.gz && tar -zxf fftw-3.3.4.tar.gz
cd ~/fftw-3.3.4 && ./configure && make && sudo make install
@yaodong
yaodong / conflict.json
Last active February 12, 2016 04:37
things data
{
"items": [{
"91B4717C-D8F7-427E-9A7D-9E9D3D9989E8": {
"p": {
"md": 1455251561.220994,
"tt": "testing012 -- testing 0121212"
},
"e": "Task2",
"t": 1
}
@yaodong
yaodong / gist:f5b785c5b17337ce1b9a
Created February 11, 2016 23:15
things cloud requests
login
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com
get key
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com/own-history-keys
get index
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Accept-Language: en-us" --compressed https:
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591