Skip to content

Instantly share code, notes, and snippets.

View pyrocat101's full-sized avatar

Linjie Ding pyrocat101

View GitHub Profile
@pyrocat101
pyrocat101 / douban-movie-2011-egg.js
Created December 23, 2011 14:34
豆瓣电影2011彩蛋脚本
Do.ready("tmpl", "share", function () {
var f = $("body"),
b = f.attr("data-cover").split(","),
h = 0,
a = $("#summary-2011"),
d = $("#summary-hd"),
g = $("#summary-bd"),
c = $("#summary-ft");
$.fn.resortMovie = function () {
$(this).one("click", function (m) {
@pyrocat101
pyrocat101 / twisted-roses.logo
Created December 24, 2011 17:30
Twisted Roses in Logo
@pyrocat101
pyrocat101 / multipart.py
Created September 9, 2012 04:04
Encode multipart/form-data in python
_CONTENT_TYPES = { '.png': 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.jpe': 'image/jpeg' }
def _encode_multipart(**kw):
'''
Build a multipart/form-data body with generated random boundary.
'''
boundary = '----------%s' % hex(int(time.time() * 1000))
data = []
for k, v in kw.iteritems():
data.append('--%s' % boundary)
@pyrocat101
pyrocat101 / dabblet.css
Created April 3, 2013 12:09
CJK/Western text emphasis
/**
* CJK/Western text emphasis
*/
@font-face {
font-family: "Western Italic";
src: local("HoeflerText-Italic"),
local("Baskerville-Italic"),
local("Georgia Italic");
font-style: normal;
@pyrocat101
pyrocat101 / pack-css.coffee
Created May 16, 2013 09:12
Compress CSS and convert linked images into data URIs. Suitable for HTML inlining and optimize HTTP requests.
embedImages = (cssPath) ->
imgRegex = /url\s?\(['"]?(.*?)(?=['"]?\))/gi
css = fs.readFileSync cssPath, 'utf-8'
while (match = imgRegex.exec css)
imgPath = path.join path.dirname(cssPath), match[1]
try
img = fs.readFileSync imgPath, 'base64'
ext = imgPath.substr imgPath.lastIndexOf('.') + 1
css = css.replace match[1], "data:image/#{ext};base64,#{img}"
catch e
@pyrocat101
pyrocat101 / escapist.js
Created May 17, 2013 03:46
Escape the given string of `html`
/**
* Escape the given string of `html`.
*
* @param {String} html
* @return {String}
* @api private
*/
exports.escape = function escape(html){
return String(html)
@pyrocat101
pyrocat101 / unescape.py
Created June 1, 2013 10:25
Unescape HTML entities to str (not unicode!)
import re
import htmlentitydefs
def unescape(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
(defn binary-search [items value]
(letfn
[(do-search
[items offset]
(let [/ (comp long /)
mid (/ (dec (count items)) 2)
mid-value (items mid)]
(cond
;; found
(= value mid-value) (+ offset mid)
(defn nth-root
[x n]
(Math/pow Math/E (/ (Math/log x) n)))
(defn sum-of-powers
[sum n start]
(let [upper-bound (int (inc (nth-root sum n)))]
(->> (range start (inc upper-bound))
(map
(fn [x]
@pyrocat101
pyrocat101 / octave-mavericks.patch
Created October 24, 2013 03:26
Quick n' dirty patch for Octave on Mavericks
diff --git a/src/DLD-FUNCTIONS/rand.cc b/src/DLD-FUNCTIONS/rand.cc
index 0602379..cdad2e2 100644
--- a/src/DLD-FUNCTIONS/rand.cc
+++ b/src/DLD-FUNCTIONS/rand.cc
@@ -26,11 +26,7 @@ along with Octave; see the file COPYING. If not, see
#endif
#include <ctime>
-#if defined (HAVE_UNORDERED_MAP)
#include <unordered_map>