Skip to content

Instantly share code, notes, and snippets.

View Go7hic's full-sized avatar
👓
👖

YiChu Go7hic

👓
👖
View GitHub Profile
@scottjehl
scottjehl / hideaddrbar.js
Created August 31, 2011 11:42
Normalized hide address bar for iOS & Android
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){
@vitaLee
vitaLee / compact_expand_css_command.py
Created June 3, 2012 13:26
SublimeText command for compacting/expanding CSS rules
import sublime
import sublime_plugin
import re
class CompactExpandCssCommand(sublime_plugin.TextCommand):
def run(self, edit, action='compact'):
rule_starts = self.view.find_all('\{')
rule_ends = self.view.find_all('\}')
@wintercn
wintercn / h5g
Last active May 19, 2017 06:50
HTML5 Canvas Game Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<!--允许全屏-->
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="yes" name="apple-touch-fullscreen"/>
<!--禁止电话号码和邮箱识别-->
@sofish
sofish / first.js
Created August 31, 2012 05:47
面试的时候我会经常问,js 中如何获得 <ul> 下的第一个 <li>,你的答案是什么?
// 大家写在评论中吧,代码高亮可以这样写:
// ```js
// your code
// ```
// update: Fri Aug 31 08:39:21
// copyright: https://gist.github.com/3549352
// 加个性能测试:http://jsperf.com/get-dom-s-first-element
var util = {};
@AndrewRayCode
AndrewRayCode / gist:3784055
Created September 25, 2012 19:53
jQuery plugin for shift + click to select multiple checkboxes
// Usage: $form.find('input[type="checkbox"]').shiftSelectable();
// replace input[type="checkbox"] with the selector to match your list of checkboxes
$.fn.shiftSelectable = function() {
var lastChecked,
$boxes = this;
$boxes.click(function(evt) {
if(!lastChecked) {
lastChecked = this;
@wintercn
wintercn / gist:3923697
Created October 20, 2012 15:53
计算“某个范围内能被最多的数整除的数”
var primes = [2,3,5,7,11,13,17];
function find(n){
var table = new Array(n+1);
table[1] = [0,0,0,0,0,0,0];
for(var i = 1;i<n;i++) {
if(!table[i]) {
table[i] = [0,0,0,0,0,0,0];
continue;
}
@nightire
nightire / Changes in Rails 4_1.md
Last active April 21, 2025 07:25
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@callumacrae
callumacrae / build-tools.md
Last active October 25, 2023 15:14
Build tools written in JavaScript
@firedfox
firedfox / add-event-conversion.js
Last active August 29, 2015 13:57
百度统计事件转化目标脚本
/**
* 创建百度统计事件转化目标
*
* 1. 首先确保在页面中已经给需要监控的元素都添加上了id。
* 2. 在下列代码中的 name='';id='';url='' 单引号中间分别填入事件转化目标名称、元素id、页面URL。
* 页面URL可以留空,表示该事件转化目标在全站都生效。
* (例如 name='事件转化目标名称';id='some-id';url='http://some-site.com/some-page')
* 3. 在百度统计里进入”网站中心" -> "事件转化目标”页面,把上述修改好的代码粘贴到浏览器中,并按回车键。
* (如果是Chrome/Firefox/IE9及以上版本浏览器,就粘贴到JS控制台里;如果是IE6/7/8浏览器,就粘贴到顶部地址栏里)
* 4. 如果提示”OK”,说明添加成功;如果出现其他提示,就说明出现了提示所指出的错误,请修改后重试。
@mikaelbr
mikaelbr / destructuring.js
Last active February 20, 2025 13:00
Complete collection of JavaScript destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];