Skip to content

Instantly share code, notes, and snippets.

@d48
d48 / debug-js-console.php
Created April 10, 2012 07:20
php debug to javascript console.log
function debug ($data) {
echo "<script>\r\n//<![CDATA[\r\nif(!console){var console={log:function(){}}}";
$output = explode("\n", print_r($data, true));
foreach ($output as $line) {
if (trim($line)) {
$line = addslashes($line);
echo "console.log(\"{$line}\");";
}
}
echo "\r\n//]]>\r\n</script>";
@d48
d48 / object.js
Created April 20, 2012 08:29
js object with sample leading comma structure
{
"validthis" : true
, "laxcomma" : true
, "laxbreak" : true
, "browser" : true
, "boss" : true
, "expr" : true
, "asi" : true
}
@d48
d48 / ssl.md
Created June 6, 2012 19:58 — forked from 8bitDesigner/ssl.md
Getting Apache SSL working locally

Lovingly skimmed from this guide

  1. Find your local host name, and hang onto it for later use
$ hostname
  1. Create a self-signed SSL cert:
openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes \
@d48
d48 / numberWithCommas.js
Created June 28, 2012 22:12
number with commas
numberWithCommas: function(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
@d48
d48 / formatCurrency.js
Created June 28, 2012 22:22
no cents from format currency
formatCurrency: function(value, noCents) {
if (!isPrice.test(value)) {
return value;
}
noCents = noCents || false;
var precision = 2
, price = parseFloat( Math.abs(value) ).toFixed(precision)
, priceArray = String(price).split('.')
@d48
d48 / prs-via-jquery.js
Created August 28, 2012 17:11
all my pull requests on github via jquery
// go to https://github.com/dashboard/pulls
$('.listing .js-navigation-open').each(
function(key, value) {
console.log('https://github.com' + $(value).attr('href'));
});
@d48
d48 / facebook-login.sh
Created August 28, 2012 17:21 — forked from hubgit/facebook-login.sh
Login to Github using cURL
#!/bin/bash
EMAIL='YOUR_EMAIL' # edit this
PASS='YOUR_PASSWORD' # edit this
COOKIES='cookies.txt'
USER_AGENT='Firefox/3.5'
curl -X POST 'https://github.com/login' --verbose --user-agent $USER_AGENT --data-urlencode "name=${EMAIL}" --data-urlencode "pass=${PASS}" --cookie $COOKIES --cookie-jar $COOKIES
curl -X GET 'https://github.com/dashboard/pulls' --verbose --user-agent $USER_AGENT --cookie $COOKIES --cookie-jar $COOKIES
@d48
d48 / obj-method-public.js
Created December 3, 2012 04:10
to make javascript object method public
var hey = {};
(function() {
function woot() {
return 'hi';
}
function who() {
return 'me';
}
@d48
d48 / ie.shims.js
Created December 3, 2012 04:50 — forked from dhm116/ie.shims.js
IE7/8 Javascript method shims
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@d48
d48 / addEvent-removeEvent.js
Last active December 11, 2015 22:28
rewrite addEvent function signature to work with removeEvent using variable that points to function
function openHandler(widgetTypeId, userWidgetId, displayOrder, savePrefUrl) {
// some stuff
Utils.addEvent(btnSave, 'click', function () {
btnSaveClick(widgetTypeId, userWidgetId, displayOrder, savePrefUrl);
});
}
function btnSaveClick(typeId, widgetId, order, url) {
// definition