Skip to content

Instantly share code, notes, and snippets.

@cstipkovic
cstipkovic / formatDate.js
Last active July 31, 2017 03:02
A simple format Date function using Javascript prototype
/*
Based on Rick Strahl code
http://www.west-wind.com/weblog/posts/2008/Mar/18/A-simple-formatDate-function-for-JavaScript
Contributors:
Clauber Stipkovic - @clauberhalic
Mário Rinaldi - @MarioRinaldi
*/
Date.prototype.formatDate = function (format) {
@atopal
atopal / gist:3906711
Created October 17, 2012 16:57
a/b testing of new forum excerpts
SELECT table_numerator.ds, table_numerator.numerator AS clicks, table_denominator.denominator AS searches, round((table_numerator.numerator/ table_denominator.denominator), 2) AS CTR
FROM
(
select ds, count(*) AS numerator
FROM research_logs
WHERE
ds > '2012-10-09'
AND `domain`='support.mozilla.com'
AND ip_address != 'NULL' AND http_version = 200 AND request_type = 'GET'
AND parse_url(empty_string_1,'PATH') RLIKE '\\/en-US\/search\$'
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@harthur
harthur / snippet.md
Created June 18, 2012 22:12
console.log() key binding for Sublime Text

Go to Sublime Text 2 > Preferences > Key Bindings - User and add this JSON to the file:

[
    { "keys": ["super+shift+l"],
      "command": "insert_snippet",
      "args": {
        "contents": "console.log(${1:}$SELECTION);${0}"
      }
 }
@jsocol
jsocol / gist:2696070
Created May 14, 2012 19:43
Bash prompt function
_prompt() {
local _prompt=$1
local _out=$2
local _default=$3
local _val=''
if [ $_default ]; then
_prompt="${_prompt} [${_default}]"
fi
read -p "$_prompt " _val
if [ $_val ]; then
@potch
potch / mozApp.js
Created May 3, 2012 16:22
simple open web app lib
// manage a webapp.
// place <link rel="app-manifest" href="path-to-manifest.webapp"> in your <head>
// mozApp.install() attempts installation
// mozApp.uninstall() removes
// mozApp.isRunning() indicates whether the app is currently installed and open
var mozApp = (function() {
var manLink = document.querySelector('link[rel="app-manifest"]'),
manifestURL = manLink.href;
var self = false;
@paulrouget
paulrouget / scratchpad.js
Created March 21, 2012 09:38
Firefox Magnifier
/*
TODO:
- zoom level menu
- need to find a way to re-start the update
- add color tools
- integrate better in Firefox
- crosshair has a 1px offset
*/
@potch
potch / bezzy.js
Created March 5, 2012 21:58
bezier curve function generator returns a function(t) that accepts [0..1] and returns an [x,y] pair at that point.
function bezzy() {
var pts = Array.prototype.slice.call(arguments),
funcs = [];
function b1(p1, p2) {
return function(t) {
var i = 1 - t;
return [p1[0]*i+p2[0]*t, p1[1]*i+p2[1]*t];
}
}
function b2(p1, p2, p3) {
@jsocol
jsocol / Explain.rst
Last active September 28, 2015 07:27
@json_view decorator

I finally put this in its own package! Check out django-jsonview.

This is a decorator that guarantees a response will be JSON, and sends meaningful (to a developer) error messages. It relies on a BadRequest exception I created elsewhere, because there is no standard way of handling that in Django (frex, we should really return HTTP 400 on form validation failures but they don't make that particularly easy). That could easily be removed, though.

@harthur
harthur / tweets.js
Created October 25, 2011 19:25
tweets.js
var ntwitter = require("ntwitter"),
growl = require("growl");
var twitter = new ntwitter({
// fill in w/ keys from https://dev.twitter.com/apps/new
consumer_key: null,
consumer_secret: null,
access_token_key: null,
access_token_secret: null
});