Skip to content

Instantly share code, notes, and snippets.

View chrisjhoughton's full-sized avatar

Chris Houghton chrisjhoughton

  • Beacon
  • London, UK
View GitHub Profile
@chrisjhoughton
chrisjhoughton / multiline.js
Created March 6, 2014 13:47
DO NOT USE. CURRENTLY BUGGY. An extremely useful yet nasty function to pass native HTML into a JavaScript function. Compatible with IE8+
var multiline = function (fn) {
var reCommentContents = /\/\*\s*([\s\S]*?)\s*\*\//;
return reCommentContents.exec(fn.toString())[1];
};
var html = multiline(function(){/*
<div>
<marquee>HELLO</marquee>
</div>
*/});
@joshed-io
joshed-io / keen_client_noconflict.js
Last active December 29, 2015 21:09
Only add the Keen IO JS SDK to the page if it's not already there; otherwise configure a new client instance
// useful if you are injecting code into 3rd party websites that may already have Keen
// this code will use the Keen SDK on the page if found, or initialize it's own otherwise.
// this approach will work in the average case, but could break if the 3rd party website
// is modifying or configuring the Keen library in an unexpected way
// a more durable approach would be to use an iFrame containing only the SDK and pass it messages
var context = this;
var myKeenClient = null;

Greetings Front-end hopeful.

We would like you to spend no more than 4 hours of happy fun time turning a payload like this:

{
  "value": 34,
  "min": 0,
  "max": 200,
 "format": "currency",
@erans
erans / mongobackup.sh
Last active October 7, 2019 16:59
MongoDB ReplicaSet Backup Script on Google Compute Engine and Google Cloud Storage
# Path to boto config file, needed by gsutils
BOTO_CONFIG="/etc/boto.cfg"
# Path in which to create the backup (will get cleaned later)
BACKUP_PATH="/mnt/data/dump/"
# DB name
DB_NAME="mydatabase"
# Google Cloud Storage Bucket Name
@tamoyal
tamoyal / gist:2ea1fcdf99c819b4e07d
Last active February 13, 2020 11:24
Upgrade Postgres 9.3 to 9.4 on Ubuntu
# Be sure to save your config files. Optional but I do:
sudo cp /etc/postgresql/9.3/main/postgresql.conf ~
sudo cp /etc/postgresql/9.3/main/pg_hba.conf ~
# Package repo (for apt-get)
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
# Also probably optional but I like to update sources and upgrade
sudo apt-get update
@battlehorse
battlehorse / index.html
Created November 2, 2011 15:21
Demo script to convert Google Chart Tools charts into PNG images.
<html>
<head>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script>
<script>
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('iframe')[0].
contentDocument.getElementById('chartArea');
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
@proudlygeek
proudlygeek / client_cors.js
Created July 17, 2012 20:48
JSONP Vs. CORS
// http://jsfiddle.net/suBPQ/
$.ajax({
url: "http://api_test_server.proudlygeek.c9.io/",
success: function(data) {
console.log(data);
}
});​
@tamoyal
tamoyal / gist:10441108
Created April 11, 2014 04:39
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
@mikermcneil
mikermcneil / using-raw-socket-io-in-sails.js
Created September 17, 2013 18:32
Using raw socket.io functionality in a Sails.js controller
module.exports = {
/**
*
* Using raw socket.io functionality from a Sails.js controller
*
*/
index: function (req,res) {
@davidalexander
davidalexander / gist:1086455
Last active September 7, 2023 07:42
Magento Snippets

Magento Snippets

Download extension manually using pear/mage

Pear for 1.4, mage for 1.5. File downloaded into /downloader/.cache/community/

./pear download magento-community/Shipping_Agent
./mage download community Shipping_Agent

Clear cache/reindex