Skip to content

Instantly share code, notes, and snippets.

View lianghai's full-sized avatar

梁海 Liang Hai lianghai

View GitHub Profile
@cbeier
cbeier / detect_cleartype.js
Created January 22, 2010 11:08
detect ClearType using javascript
/*
* TypeHelpers version 1.0
* Zoltan Hawryluk, Nov 24 2009.
* @see http://www.useragentman.com/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/
*
* Released under the MIT License. http://www.opensource.org/licenses/mit-license.php
*
* Works for
* - IE6+ (Windows),
* - Firefox 3.5+ (Windows, Mac, Linux),
@Sai
Sai / gist:1348075
Created November 8, 2011 15:37
Shaky Layer
#define degreesToRadian(x) (M_PI * (x) / 180.0)
+ (void)shakyWithLayer:(CALayer *)layer delegate:(id)object forKey:(NSString *)key {
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 0.25;
animation.cumulative = YES;
animation.repeatCount = 9999;
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat: 0.0],
[NSNumber numberWithFloat: degreesToRadian(-4.0)],
@jonatasnona
jonatasnona / gist1994877
Created March 7, 2012 19:00
Javascript: UserAgent
<script>
var ua = navigator.userAgent;
var checker = {
ios: ua.match(/(iPhone|iPod|iPad)/),
blackberry: ua.match(/BlackBerry/),
android: ua.match(/Android/),
windowsphone: ua.match(/Windows Phone/)
};
$(document).ready(function() {
@disinfeqt
disinfeqt / image_replacer.js
Created March 13, 2012 09:11
Image Replacer on Apple.com
if (typeof (AC) === "undefined") {
AC = {}
}
AC.ImageReplacer = Class.create({
_defaultOptions: {
listenToSwapView: true,
filenameRegex: /(.*)(\.[a-z]{3}($|#.*|\?.*))/i,
filenameInsert: "_☃x",
ignoreCheck: /(^http:\/\/movies\.apple\.com\/|\/105\/|\/global\/elements\/quicktime\/|_(([2-9]|[1-9][0-9]+)x|nohires)(\.[a-z]{3})($|#.*|\?.*))/i,
attribute: "data-hires",
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@gnap
gnap / tagshow
Created April 7, 2012 15:18
Tagging TV Show files of mp4 format in given dir(s) for iTunes import
#!/usr/bin/env python
'''
File: tagshow.py
Author: George Ang <gnap.an@gmail.com>
Description:
'''
import os
import sys
import json
@jjgod
jjgod / cascadelist.m
Created April 19, 2012 08:32
Use cascade list attribute to customize font fallback in Core Text
#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
if (argc != 2)
return 0;
NSAutoreleasePool *pool = [NSAutoreleasePool new];
CFStringRef name = (CFStringRef) [NSString stringWithUTF8String: argv[1]];
@neolee
neolee / TeXIt.tex
Created May 3, 2012 10:46
XeLaTeX Sample
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
% 以上设定默认使用 XeLaTeX 编译,并指定 Unicode 编码,供 TeXShop 自动识别
% XeLaTeX 示例
\documentclass[12pt]{article}
% XeTeX 配合 fontspec 可以非常方便的设置字体
@marcedwards
marcedwards / high-dpi-media.css
Last active November 19, 2023 12:56
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@MaskRay
MaskRay / gist:4134245
Created November 23, 2012 06:32
Flesch Reading Ease Score of several programming books
% xargs -i sh -c 'echo -n "{} @ "; pdftotext "{}" - 2>/dev/null | ruby -e "require \"lingua\"; p Lingua::EN::Readability.new(STDIN.read).flesch"' < /tmp/books | sort -t@ -k2n
scheme/sicp.pdf @ 42.013863374063305
smalltalk/Joy of Smalltalk.pdf @ 47.861949781603954
falcon/Falcon Survival Guide.pdf @ 52.899363840845155
ruby/The Rails 3 Way.pdf @ 55.05629641057524
c/The C Programming Language.pdf @ 55.17174939358114
python/Learning Python.pdf @ 56.67476157760058
c++/C++ Primer.pdf @ 57.237840064930595
ruby/The Ruby Programming Language.pdf @ 57.75836947304364
haskell/Real World Haskell.pdf @ 58.23158652909788