Skip to content

Instantly share code, notes, and snippets.

QList<QString> list;
QSet<QString> source;
// result is a QSet containing elements in both list and source
// Method 1
template <class T>
QSet<T> intersect(QSet<T> &set, QList<T> &list)
{
QSet<T> result = set;
@uranusjr
uranusjr / cpu.py
Created March 17, 2012 10:08
Get CPU usage in %
import time
def cpuUsage():
with open('/proc/stat', 'r') as statFile:
cpuValues = [int(v) for v in statFile.readline().strip().split()[1:]]
total1 = sum(cpuValues)
work_1 = sum(cpuValues[0:3])
time.sleep(2) # Sample 2 seconds
@uranusjr
uranusjr / Connect.scpt
Created October 16, 2012 21:58
Connect to specified SSID via Terminal on Mac OS X
set interface to "enXX" # 把它換成你的無線網卡編號
set ssid to "" # 填入你想連接網路的 SSID
set passwd to (text returned of (display dialog "Enter password:" default answer "" with hidden answer))
do shell script "networksetup -setairportnetwork " & interface & " " & (quoted form of ssid) & " " & (quoted form of passwd)
@uranusjr
uranusjr / .gitignore
Created October 20, 2012 02:10 — forked from adamgit/.gitignore
.gitignore file for Xcode4 / OS X Source projects
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#########################
@uranusjr
uranusjr / dm.py
Last active December 15, 2015 16:49
from dateutil.relativedelta import relativedelta
def three_months_from(date):
return date + relativedelta(months=3)
require 'date'
def three_months_from(d)
return d >> 3
end
⁰¹²³⁴⁵⁶⁷⁸⁹₀₁₂₃₄₅₆₇₈₉
@uranusjr
uranusjr / gist:5433388
Created April 22, 2013 08:59
URL-compatible DateTime string from timestamp
String dateStringFromTimestemp(long miliseconds)
{
Date date = new Date(miliseconds);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = format.format(date);
return dateString;
}
String getNotificationsAfter(long miliseconds)
{
@uranusjr
uranusjr / injection.py
Last active December 17, 2015 08:08
A tag that injects any output of another template tag into current context. Syntax: `{% inject as variable_name from tag_name [tag_arg ...] %}` where `variable_name` if the key to inject into, `tag_name` is the name of tag to retrieve value from, and `tag_arg`s are parameters to be used in the tag specified by `tag_name`.
from django.template import (
TemplateSyntaxError, Library, Node, Variable, Token, TOKEN_BLOCK
)
register = Library()
@register.tag(name='inject')
def inject(parser, token):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import HTMLParser
OUTPUT_PATH = None
URL = None
# Set URL here