Skip to content

Instantly share code, notes, and snippets.

View futurist's full-sized avatar

James Yang futurist

  • China
View GitHub Profile
i
me
my
myself
we
our
ours
ourselves
you
your
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@dbrady
dbrady / change_case.el
Created February 28, 2011 01:02
emacs lisp defuns to change the case (camelCase <-> snake_case) of the word under cursor, or an entire region if selected. NOTE: the snake-case defuns do not work, they just camelCase. Ooops.
;; Grateful thanks are given to Brian Marick (@marick) for helping me
;; write these. I got the original idea while reading through
;; http://xahlee.org/emacs/elisp_idioms.html, but couldn't work out
;; the elisp regexes. Brian Marick (@marick) stepped in and helped. He
;; took my tortured and broken camelcase-region and turned it into
;; something that actually worked. I then created
;; camelcase-word-or-region. I then wrote the snakecase versions but I
;; see now that all I did was copy the camelcase defuns over and,
;; meaning to go back and finish them Real Soon Now, forgot all about
;; them. I've had a quick look (2011-02-27) but elisp regexes are
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@remvee
remvee / setup-misc.el
Created March 21, 2011 11:11
Paredit for ruby and javascript.
;; Enable paredit for a couple for non lisp modes; tweak
;; paredit-space-for-delimiter-predicates to avoid inserting spaces
;; before open parens.
(dolist (mode '(ruby espresso))
(add-hook (intern (format "%s-mode-hook" mode))
'(lambda ()
(add-to-list (make-local-variable 'paredit-space-for-delimiter-predicates)
(lambda (_ _) nil))
(enable-paredit-mode))))
@DTrejo
DTrejo / .gitignore
Created April 4, 2011 03:32
How to Readline - an example and the beginnings of the docs
node_modules/
@indexzero
indexzero / conditional-url-forwarding.js
Created April 27, 2011 21:43
Conditional URL rewrite forwarding
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a new instance of HttProxy to use in your server
//
var proxy = new httpProxy.HttpProxy();
var apacheUrls = [
/some\/url\/as\/a\/regexp/,
@think49
think49 / cssstyledeclaration-removeproperty.js
Last active June 7, 2017 04:05
cssstyledeclaration-removeproperty.js, cssstyledeclaration-setproperty.js : IE8- で動作する CSSStyleDeclaration#removeProperty, CSSStyleDeclaration#setProperty
/**
* cssstyledeclaration-removeproperty.js
* define CSSStyleDeclaration.prototype.removeProperty for IE.
*
* @version 1.0.4
* @author think49
* @url https://gist.github.com/953107
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License)
* @see <a href="http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface">5.5.1. The CSSStyleDeclaration Interface - CSSOM</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/dd347052%28v=vs.85%29.aspx">CSSStyleDeclaration Prototype (attribute) - MSDN</a>
@jonleighton
jonleighton / base64ArrayBuffer.js
Last active June 19, 2024 13:39
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
/*
MIT LICENSE
Copyright 2011 Jon Leighton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@developernotes
developernotes / gist:1146913
Created August 15, 2011 14:53
kill diskimages-helper processes
ps -A | grep diskimages-helper | awk '{print $1}' | xargs kill -9