Skip to content

Instantly share code, notes, and snippets.

View ads901119's full-sized avatar

Alan Sha ads901119

View GitHub Profile
@ads901119
ads901119 / playlist-dl.py
Created May 1, 2012 08:18 — forked from FiloSottile/playlist-dl.py
Download a youtube playlist using rg3/youtube-dl by @orschiro
import shutil
import os
import sys
import subprocess
import re
# Settings
root_folder = 'C:/Users/Robert/Videos/YouTube/Playlists/'
destination_regex = re.compile(r'^\[download\] Destination: (.*)$', re.M)
@ads901119
ads901119 / sift3.py
Created July 8, 2012 11:07 — forked from fjorgemota/sift3.py
Sift3 in Python
def sift3(s1,s2, maxOffset):
s1L = len(s1)
s2L = len(s2)
if not s1:
return (not s2 and 0 or s2L)
if not s2:
return s1L
c1 = 0
c2 = 0
lcs = 0
@ads901119
ads901119 / models.py
Created July 31, 2012 06:11 — forked from treyhunner/models.py
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
# This code is under the MIT license.
# Inspired by this StackOverflow question:
http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):
@ads901119
ads901119 / profile_picture_django_social_auth
Created August 2, 2012 22:21 — forked from kousha789123/profile_picture_django_social_auth
Extending User class to save profile picture in django-social-auth when registering
# This is models.py for a new user profile that you would like to create.
"""
this gist gets an id from django-social-auth and based on that saves the photo from social networks into your model. This is one of the best ways to extend User model because this way, you don't need to redefine a CustomUser as explained in the doc for django-social-auth. this is a new implementation based on https://gist.github.com/1248728
"""
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models
@ads901119
ads901119 / gist:3394795
Created August 19, 2012 13:30 — forked from evildmp/gist:3094281
Set up Django, nginx and uwsgi

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi
@ads901119
ads901119 / nginx.conf
Created August 27, 2012 11:16 — forked from timmyomahony/nginx.conf
Python, UWSGI, Supervisor & Nginx
upstream uwsgi {
ip_hash;
server 127.0.0.1:40000;
}
server {
listen 80;
server_name www.domain.com;
root /sites/mysite/;
access_log /sites/mysite/log/nginx/access.log;
@ads901119
ads901119 / models.py
Created October 2, 2012 01:08 — forked from zvictor/models.py
An example how to connect userena with django-social registration.
from socialregistration.signals import connect as profile_connect
from userena.managers import ASSIGNED_PERMISSIONS
@receiver(socialregistration_signals.connect, sender = FacebookProfile, dispatch_uid = 'facebook.connect')
def social_connect_callback(sender, user, profile, client, **kwargs):
"""
Create a profile for this user after connecting
"""
# Create a userena user.
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
@ads901119
ads901119 / form.py
Created January 31, 2013 06:16 — forked from smugen/form.py
# -*- coding: UTF-8 -*-
from flaskext.wtf import Form, TextField, PasswordField, RecaptchaField, \
AnyOf, NoneOf, Regexp, Email, Required, EqualTo, Recaptcha
from wtforms.validators import StopValidation
from flask import request, session
import model
# 身份證字號格式驗證
def check_ID(form, field):
locations = dict(zip([c for c in 'ABCDEFGHJKLMNPQRSTUVXYWZIO'], range(10,36)))
// Based off example code from Hal Robertson
// https://github.com/halrobertson/test-restify-passport-facebook
// See discussion: https://groups.google.com/forum/?fromgroups#!topic/passportjs/zCz0nXB_gao
var restify = require('restify')
// config vars
var FB_LOGIN_PATH = '/api/facebook_login'
var FB_CALLBACK_PATH = '/api/facebook_callback'
var FB_APPID = '<<YOUR APPID HERE>>'