Skip to content

Instantly share code, notes, and snippets.

View supasympa's full-sized avatar
🎧
💻⌨️🖥 @barclaytweets

Lewis Barclay supasympa

🎧
💻⌨️🖥 @barclaytweets
  • Supa Sympa Ltd
  • London
View GitHub Profile
@supasympa
supasympa / propertyInspector.cs
Created April 21, 2011 16:32
Inspect the properties of an object and return the properties and the value followed by a line break (one level deep).
public static string Properties(object o, Type type, string linebreak)
{
StringBuilder sb = new StringBuilder();
foreach (var prop in type.GetProperties())
{
if (prop.CanRead)
{
var value = prop.GetValue(o, null);
if (value != null)
@supasympa
supasympa / localeNumberFormat.js
Created July 11, 2011 10:15
Javascript Locale Currency format
function localeNumberFormat(amount, currencySymbol, delimiter, decimalPlaces) {
// setup some default values
if (typeof decimalPlaces === 'undefined' || decimalPlaces === null) {
decimalPlaces = 0;
}
if (typeof decimalPlaces === 'undefined' || delimiter === null) { delimiter = ','; }
//check that the value can be recognised as an Floating point number
try {
amount = parseFloat(amount);
@supasympa
supasympa / prototypalInheritance.js
Created July 14, 2011 14:36
My example of prototypal inheritance in Javascript for when I forget!
/*
An example of prototypal inheritance in Javascript for when I forget!
*/
console.log('> inheritance.js');
function main(){
console.log('start main.');
@supasympa
supasympa / updateShareThisButtons.js
Created December 5, 2011 14:54
Some code to update ShareThis buttons with custom images - useful in SPAs or AJAX apps
function updateShareButtons(location, title, imgsrc) {
$('.share').hide();
$('.sharethis').html('');
var services = [
{type : 'facebook',
image : './css/img/social-facebook.png'},
{type : 'twitter',
image : './css/img/social-twitter.png'},
{type : 'email',
@supasympa
supasympa / ssh-config-shortcut
Created June 20, 2012 04:44
Adding a shortcut to ssh
Host gh
Hostname github.com
User git
IdentityFile ~/.ssh/somekey
@supasympa
supasympa / flexi-grid.less
Created March 25, 2013 21:49
LESS to create the classes required for creating a flexi grid.
@fixedCols :5;
@fixedRows :2;
.boxXxn(@X:5, @Y:2){
//iterate from 5 down to 0 X
.boxXY(@indexX, @indexY) when (@indexX > 0) and (@indexY > 0){
.box@{indexX}x@{indexY}{
width:((100 / @fixedCols) * @indexX) * 1%;
height:((100/ @fixedRows) * @indexY) * 1%;
@supasympa
supasympa / mustard-cutting-browserdetection.js
Created April 23, 2013 07:58
Test for minimal browser requirements when including jQuery
if ('querySelector' in document &&
'localStorage' in window &&
'addEventListener' in window) {
// bootstrap the JavaScript application
}
@supasympa
supasympa / StringFormat
Created July 2, 2013 14:34
A simple string format function replacing items in a string with their respective strings / numbers in a map.
define([],
function () {
var resolvePath = function (path, map) {
var pathParts, i, ctx;
ctx = map;
i = 0;
pathParts = path.split('.');
@supasympa
supasympa / model replacments
Created September 26, 2013 08:26
Replace a string with model object properties
var M = function(){
}
M.prototype = {
format : function(){
var s = "/data/mu/programs/{{programCode}}/campaign-mus/{{muid}}/validate";
var r = /{{[a-zA-Z_-]*}}/gi.exec(s);
var key = '';
while(r!==null){
@supasympa
supasympa / backbone click proxy
Created December 13, 2013 11:45
click proxy for backbone
//<a href="#/my/application/route" rel="" data-forproxy="{myproxy:data}">Some link</a>
var someView = {
events : {
'click a[rel="proxy"]' : clickProxy
},
clickProxy : function(e){
var $anc, proxyData, route;