Skip to content

Instantly share code, notes, and snippets.

@ph87
ph87 / save_to_evernote.scpt
Last active September 11, 2016 06:39
A very simple applescript save given text to default notebook.
on run {input, parameters}
set content to (input as text)
set AppleScript's text item delimiters to "\n"
set textList to every text item of content
set theTitle to item 1 of textList
tell application "Evernote"
create note title theTitle with text content notebook "default"
synchronize
end tell
display notification "Success" with title "Save to Evernote!"
@ph87
ph87 / sumchecker.py
Last active August 29, 2015 14:02
Sum Check Schema for IOS 7064 Mod 11-2 (Unique Identifier for People, People's Republic of China)
code = '12346830281720938x' # check sum equal 10, maped to 'x'
sum = 0
for i in code[:-1]:
sum = ( sum + int(i, 10)) * 2
sum_mod = sum % 11
sum_check = (12 - sum_mod ) % 11
sum_check = 'x' if sum_check == 10 else str(sum_check)
assert sum_check == code[-1]
@ph87
ph87 / generics.py
Last active August 29, 2015 14:01
override related django rest framework's generics pagination for only get the count of result by passing param page_size = 0
# read the codes commented by ph87
def paginate_queryset(self, queryset, page_size=None):
"""
Paginate a queryset if required, either returning a page object,
or `None` if pagination is not configured for this view.
"""
deprecated_style = False
if page_size is not None:
warnings.warn('The `page_size` parameter to `paginate_queryset()` '
@ph87
ph87 / redis-server
Created April 3, 2014 03:01
redis-server
#!/bin/sh
# /etc/rc.d/init.d/redis-server
# From - http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
#
# redis - this script starts and stops the redis-server daemon
# Originally from - https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
@ph87
ph87 / mailer.py
Last active December 23, 2015 01:49
一个发简单邮件用的脚本
#!/usr/local/bin/python2.7
#encoding:utf8
import sys
import os
import datetime
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from optparse import OptionParser