Skip to content

Instantly share code, notes, and snippets.

@kof
kof / inherits.js
Created March 24, 2011 13:10
nodejs like utility method for inheritance
/**
* Inherit prototype properties
* @param {Function} ctor
* @param {Function} superCtor
*/
_.mixin({
inherits: (function(){
function noop(){}
function ecma3(ctor, superCtor) {
@cowboy
cowboy / Abstraction.js
Created May 24, 2012 20:25
A modern JavaScript if-elseif-else abstraction, because control flow statements are so 1995
/*
* Abstraction.js
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
var Abstraction = (function($) {
var _ = $.prototype;

A small sampling of external projects initially built for Ember use but designed to be used standalone:

@devongovett
devongovett / translate.js
Created February 2, 2014 23:14
Use PhantomJS to translate stdin to english using Google Translate. Useful as a textmate command or just a command line tool.
#!/usr/bin/env phantomjs
var system = require('system');
var text = encodeURIComponent(system.stdin.read());
var url = "http://translate.google.com/#auto/en/" + text;
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0';
page.onConsoleMessage = function (msg) {
@davepacheco
davepacheco / testspawn.js
Last active December 6, 2019 19:56
Surprising Node.js/bash interaction
/*
* testspawn.js: exercises surprising interaction between Node.js "spawn" and
* bash. To use this:
*
* (1) Create a file in the same directory called "foo.rc", with just one line:
*
* echo "loaded foo.rc"
*
* (2) Run this program as:
*
@glenjamin
glenjamin / records.js
Last active May 4, 2020 16:50
Flow types for immutable records.
/* @flow */
import * as I from "immutable";
/**
* Define an immutable record intended for holding reducer state
* @param spec - the keys and their default values
* @return a state record factory function
*/
export function defineRecord<T: Object>(
@Carolain
Carolain / beepWhenInternet
Last active August 21, 2020 14:22
Keep pinging google.com and beep on success, so I know my flaky connection is working again
#!/bin/bash
echo pinging google.com, will exit on success
echo ctrl+c to force exit
echo will beep on exit
echo
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 google.com >/dev/null 2>&1; do sleep 60; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
@wacko
wacko / pre-commit
Last active September 16, 2020 22:57
Git hook to avoid commit debug lines (binding.pry console.log debugger...)
#!/usr/bin/env ruby
# Validates that you don't commit forbidden keywords to the repo
# You can skip this checking with 'git commit --no-verify'
exit 0 if ARGV.include?('--no-verify')
# Update this list with your own forbidden keywords
KEYWORDS = %w(binding.pry console.log debugger)
def red(text) "\033[31m#{text}\033[0m"; end
@deanmcpherson
deanmcpherson / alignment.css
Created June 16, 2016 07:54
Text alignment -> draftjs workaround
.alignment--left {
.public-DraftStyleDefault-block {
text-align; left;
}
}
.alignment--center {
.public-DraftStyleDefault-block {
text-align; center;
}
}
@sitano
sitano / gist:2123d9ae297b641fafef
Last active April 17, 2021 03:09
nginx cors with if multiple conditions with http basic auth
location ~* /cache/ {
proxy_pass http://127.0.0.1:8000;
if ($http_origin ~* "^https?://(dev|admin|www)\.site\.com$" ) {
set $cors "A";
}
if ($request_method = 'OPTIONS') {
set $cors "${cors}B";
}