Skip to content

Instantly share code, notes, and snippets.

View yaodong's full-sized avatar

Yaodong Zhao yaodong

View GitHub Profile
@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\\\\?[\">]")
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) {
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):
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 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()
@yaodong
yaodong / event-manager.js
Created August 10, 2016 19:38
simple js event manager
const $ = require('jquery');
class EventManager {
constructor(handlers) {
this._handlers = {};
if (handlers) {
$.each(handlers, (name, cb) => {
this.listen(name, cb);
});

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

@yaodong
yaodong / keybase.md
Created September 9, 2016 21:15
keybase.md

Keybase proof

I hereby claim:

  • I am yaodong on github.
  • I am yaodong (https://keybase.io/yaodong) on keybase.
  • I have a public key ASAWJz1sEECftwSUiciKblE7agUb5InsuvcFnFCe5X0hXAo

To claim this, I am signing this object:

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
pyenv install 3.5.2
pyenv global 3.5.2