Skip to content

Instantly share code, notes, and snippets.

View m-coding's full-sized avatar

michelle m-coding

View GitHub Profile
@m-coding
m-coding / Backbone and JSONP
Created March 25, 2016 07:50 — forked from michielvaneerd/Backbone and JSONP
Fetching a Backbone collection with JSONP is really simple. It turns out you only need to override the sync method (to set the dataType to jsonp). In this case I also had to override the parse method, because the response consists of more than the models. This example uses the Discogs API to search for artists.
var Artist = Backbone.Model.extend();
var Artists = Backbone.Collection.extend({
model : Artist,
url : "http://api.discogs.com/database/search?type=artist",
sync : function(method, collection, options) {
// By setting the dataType to "jsonp", jQuery creates a function
// and adds it as a callback parameter to the request, e.g.:
// [url]&callback=jQuery19104472605645155031_1373700330157&q=bananarama
// If you want another name for the callback, also specify the
@m-coding
m-coding / 0_reuse_code.js
Created March 26, 2016 00:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@m-coding
m-coding / Handlebars- Backbone.js
Created March 29, 2016 06:59 — forked from amatiasq/Handlebars- Backbone.js
This allow Handlebars to look up Backbone Model's attributes: {{ user.address.street }} If user is a Backbone Model this will become user.get("address").street And if user.get("adress") is also a Backbone Model this will be produced: user.get("address").get("street")
Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
var result = '(' + parent + ' instanceof Backbone.Model ? ' + parent + '.get("' + name + '") : ' + parent;
if (/^[0-9]+$/.test(name)) {
return result + "[" + name + "])";
} else if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return result + "." + name + ')';
} else {
return result + "['" + name + "'])";
}
};
@m-coding
m-coding / custom-model-with-view.js
Created April 2, 2016 04:36 — forked from oroce/custom-model-with-view.js
backbone.js CustomModel with View
var customModel = new CustomModel();
var sampleView = new Backbone.View({
model: customModel
});
$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
// usage: $(‘div.unevenheights’).setAllToMaxHeight();
@m-coding
m-coding / regex-yyyy-mm-dd.js
Last active November 14, 2024 08:49
javascript regex to match date pattern YYYY-MM-DD
// allows YYYY/M/D and periods instead of slashes
// http://stackoverflow.com/questions/24989065/trying-to-validate-yyyy-mm-dd
/^\d{4}[\/.]\d{1,2}[\/.]\d{1,2}$/
// YYYY-MM-DD and YYYY-M-D
// http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
/^\d{4}\-\d{1,2}\-\d{1,2}$/
// YYYY-MM-DD
// https://gist.github.com/arth2o/8471150
@m-coding
m-coding / LocalStorage.js
Created April 12, 2016 07:38 — forked from picode7/LocalStorage.js
LocalStorage JavaScript Module
/**
* Check if localStorage is supported const isSupported: boolean
* Check if localStorage has an Item function hasItem(key: string): boolean
* Get the amount of space left in localStorage function getRemainingSpace(): number
* Get the maximum amount of space in localStorage function getMaximumSpace(): number
* Get the used space in localStorage function getUsedSpace(): number
* Backup Assosiative Array interface Backup
* Get a Backup of localStorage function getBackup(): Backup
* Apply a Backup to localStorage function applyBackup(backup: Backup, fClear: boolean = true, fOverwriteExisting: boolean = true)
* Dump all information of localStorage in the console function consoleInfo(fShowMaximumSize: boolean = false)
commit 6e59bfbc45983b8680f023ac07a34cabe80985e5
Author: Adam Jakubek <[email protected]>
Date: Mon Aug 13 01:24:39 2012 +0200
Prevent focus stealing when opening diverted URLs
This patch allows to override current Chrome's behavior, where opening a
link from an external application (e.g. mail client) causes Chrome's
window to steal focus.
It works by introducing a new command line switch
@m-coding
m-coding / fix_github_https_repo.sh
Created April 25, 2016 01:04 — forked from m14t/fix_github_https_repo.sh
Convert HTTPS github clones to use SSH
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
@m-coding
m-coding / About.md
Last active May 14, 2016 03:59
My Microsoft Visual Code Settings

I am trying out Microsoft's VS Code editor to see if it is good enough to replace Sublime.

Below is a work in progress of transferring settings I liked in Sublime.