Skip to content

Instantly share code, notes, and snippets.

View gingi's full-sized avatar

Shiran Pasternak gingi

View GitHub Profile
@gingi
gingi / inherit.js
Last active August 29, 2015 14:08
A method for generically inheriting classes. Supports strict mode, and the ability to instantiate objects with and without the `new` keyword. Combines ideas from Douglas Crockford and John Resig.
/**
* @method inherit
*
* Creates a new Class. Implements the necessary wiring to ensure a valid
* prototype chain. Returns an object constructor which can be used to
* instantiate new objects. The method accepts two optional parameters: (1) a
* parent class from which to inherit, and (2) a set of methods. An
* `initialize` method can be specified which will be called automatically upon
* object instantiation.
*

Keybase proof

I hereby claim:

  • I am gingi on github.
  • I am gingi (https://keybase.io/gingi) on keybase.
  • I have a public key whose fingerprint is C424 40E5 6E66 6C90 77DE DFA1 BE43 7FBF 0328 C918

To claim this, I am signing this object:

@gingi
gingi / gist:47df42a45bb1653002ee
Last active April 22, 2016 03:10
Redirecting HTTP requests to HTTPS in a Node.js Connect app.
function requireHTTPS(req, res, next) {
if (!req.secure) {
//FYI this should work for local development as well
var domain = "https://" + req.get("host");
if (process.env["SSL_PORT"]) {
domain = domain.replace(/:\d+$/, "");
domain += ":" + process.env["SSL_PORT"];
}
return res.redirect(domain + req.url);
}
@gingi
gingi / app.js
Created April 1, 2013 20:18
CORS in an Express app.
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,OPTIONS,HEAD');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
@gingi
gingi / Crash log
Last active December 14, 2015 05:59
TextMate hangs with JavaScript bundle (v2.0-alpha.9387)
Date/Time: 2013-02-26 10:43:09 -0500
OS Version: 10.8.2 (Build 12C3006)
Architecture: x86_64
Report Version: 11
Command: TextMate
Path: /Applications/TextMate.app/Contents/MacOS/TextMate
Version: 2.0-alpha.9387 (9387)
Parent: launchd [145]
@gingi
gingi / Duplicate Lines.applescript
Created July 3, 2012 20:08
BBEdit Script: Duplicate Lines
tell application "BBEdit"
tell window 1
set start_line to startLine of selection
set end_line to endLine of selection
select (lines start_line thru end_line)
set selectionCopy to duplicate selection
select insertion point after selection
set selection to selectionCopy
end tell
end tell
@gingi
gingi / Join Line With Next.applescript
Created July 3, 2012 20:06
BBEdit Script: Join Line With Next
tell application "BBEdit"
tell window 1
set currentLine to endLine of selection
set nextLine to currentLine + 1
-- Delete starting after the last non-whitespace character in the current line
set findDeleteStart to find "\\s*$" options {search mode:grep} ¬
searching in line currentLine
if found of findDeleteStart then
set firstCharacter to characterOffset of found object of findDeleteStart
@gingi
gingi / Text UnComment Selection.applescript
Created June 19, 2012 01:24
BBEdit Menu Script to Toggle Indented Comments
tell application "BBEdit"
tell front text window
set srcLang to source language of the selection
set commStr to ""
set closeStr to ""
if srcLang = "HTML" then
set commStr to "<!--"
@gingi
gingi / Application.applicationWillSwitchOut.applescript
Created June 15, 2012 14:38 — forked from benspaulding/Application.applicationWillSwitchOut.applescript
AppleScript that will save all documents with unsaved changes when BBEdit loses focus.
(*
File:
Application.applicationWillSwitchOut.scpt
Abstract:
This script will automatically save all on-disk text documents with unsaved
changes when BBEdit loses focus.
Version:
@gingi
gingi / smooth.pl
Created April 26, 2012 16:34
A script for smoothing BED files.
#!/usr/local/bin/perl
use strict;
use warnings;
use Readonly;
use List::MoreUtils qw/any/;
use Getopt::Long;
use Pod::Usage;