Skip to content

Instantly share code, notes, and snippets.

View vayn's full-sized avatar

Vayne Tsai vayn

View GitHub Profile
@vayn
vayn / gunicorn_start.sh
Created October 9, 2016 12:53
Django+Supervisor+Gunicorn
#!/bin/bash
NAME="myproject"
VIRTURLROOT=/home/ubuntu/.virtualenvs/hezhi
DJANGODIR=/var/www/hezhi
SOCKFILE=/var/www/hezhi/run/gunicorn.sock
USER=ubuntu
GROUP=ubuntu
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=hezhi.settings.dev
@vayn
vayn / gunicorn_start.sh
Last active October 1, 2016 18:28
django, gunicorn, supervisor, virtualenvwrapper settings
#!/bin/bash
NAME="hezhi" # Name of the application
PYTHONPATH=/home/ubuntu/.virtualenvs/hezhi/bin/python3 # Python path
DJANGODIR=/var/www/hezhi # Django project directory
SOCKFILE=/var/www/hezhi/run/gunicorn.sock # we will communicte using this unix socket
USER=ubuntu # the user to run as
GROUP=ubuntu # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hezhi.settings # which settings file should Django use, change to
@vayn
vayn / word_len_stat.c
Created May 9, 2016 07:36
Analyse length of words and draw the statistics with a chart
#include <stdio.h>
#define IN 1
#define OUT 0
#define MAXWORDLEN 10
void drawChart(int maxValue, int *wordsLengthNum)
{
int i, j;
@vayn
vayn / curl_play.c
Created May 7, 2016 05:23
Curl_Player
//
// main.c
// PointerPlayer
//
// Created by Vicent Tsai on 16/3/1.
// Copyright © 2016年 HeZhi Corp. All rights reserved.
//
#include <stdio.h>
#include <string.h>
@vayn
vayn / dp_3.py
Last active October 7, 2021 08:11
BadNeighbors - 2004 TCCC Online Round 4 - Division I, Level One
# https://community.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009
#
# 状态转移方程:
#
# max{
# max{m[i-1][0], m[i-2][0] + A[i-1]},
# max{m[i-1][1], m[i-2][1] + A[i]}
# }
#
# https://community.topcoder.com/stat?c=problem_statement&pm=1259&rd=4493
def longest_zigzag(A):
n = len(A)
d = [0] * n
s = [0] * n
last_indices = [0] * n
longest_len = 1
for i in range(0, n):
# http://www.hawstein.com/posts/dp-novice-to-advanced.html
# d(i) = max{1, d(j)+1}, 其中j<i, A[j]<=A[i]
def longest_increasing_sequence(A):
n = len(A)
d = [0] * n
last_idx_to_this_one = [0] * n
length = 1
for i in range(0, n):
@vayn
vayn / gist:f18dad1185f2e7da338b
Created December 23, 2015 02:31 — forked from ynechaev/gist:8123997
UITableViewCell popular animation (flipping around Y axis, depending on scroll direction)
@interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UIImageOrientation scrollOrientation;
CGPoint lastPos;
}
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView.isDragging) {
UIView *myView = cell.contentView;
CALayer *layer = myView.layer;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
@vayn
vayn / flask.py
Last active May 18, 2016 17:29 — forked from kageurufu/flask.py
Flask-WTF FieldLists with Dynamic Entries
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.wtf import Form
from flask.ext.babel import gettext
from wtforms import SelectField, TelField, TextField, FormField, Fieldlist, SubmitField
from wtforms.validators import Optional, Required
app = Flask(__name__)
db = SQLAlchemy(app)
@vayn
vayn / flask_static_files_cache_invalidator.py
Last active August 30, 2015 07:03 — forked from iximiuz/flask_static_files_cache_invalidator.py
Flask: add static file's cache invalidator param to URLs generated by url_for(). Blueprints aware.
""" Inspired by http://flask.pocoo.org/snippets/40/ """
app = Flask(__name__)
@app.url_defaults
def hashed_url_for_static_file(endpoint, values):
if 'static' == endpoint or endpoint.endswith('.static'):
filename = values.get('filename')
if filename:
if '.' in endpoint: # has higher priority