Skip to content

Instantly share code, notes, and snippets.

View m-coding's full-sized avatar

michelle m-coding

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@m-coding
m-coding / github.css
Created February 9, 2016 22:17 — forked from theconektd/github.css
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@m-coding
m-coding / firebase_detect_data.js
Created February 15, 2016 02:25 — forked from anantn/firebase_detect_data.js
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
@m-coding
m-coding / panTo.js
Created February 25, 2016 23:48 — forked from lpdumas/panTo.js
Simple pan method for Google map API v3 to pan the map with a certain offset. In this case, used within a custom infoWindow class.
CustomInfoWindow.prototype.panMap = function(marker, map) {
var offsetX = 100
var offsetY = 75
var scale = Math.pow(2,map.getZoom())
var center = map.getProjection().fromLatLngToPoint(marker.getPosition())
var newCenterPoint = new google.maps.Point(
center.x - offsetX/scale,
center.y + offsetY/scale
)
@m-coding
m-coding / getTwitterBearer.js
Created February 28, 2016 06:10 — forked from sulmanen/getTwitterBearer.js
Get twitter API 1.1 bearer token
var request = require('request');
var consumer_key = 'YOUR_CONSUMER_KEY';
var consumer_secret = 'YOUR_CONSUMER_SECRET';
var enc_secret = new Buffer(consumer_key + ':' + consumer_secret).toString('base64');
var oauthOptions = {
url: 'https://api.twitter.com/oauth2/token',
headers: {'Authorization': 'Basic ' + enc_secret, 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
body: 'grant_type=client_credentials'
};
@m-coding
m-coding / createBearerToken.js
Created February 28, 2016 06:10 — forked from elmariachi111/createBearerToken.js
A Javascript file that requests a Twitter bearer token for application only authentication (https://dev.twitter.com/docs/auth/application-only-auth). Depends on mikeals request library (https://github.com/mikeal/request) (npm install request)
var R = require("request");
var key = process.env.TWITTER_CONSUMER_KEY;
var secret = process.env.TWITTER_CONSUMER_SECRET;
var cat = key +":"+secret;
var credentials = new Buffer(cat).toString('base64');
var url = 'https://api.twitter.com/oauth2/token';
R({ url: url,
@m-coding
m-coding / twitter_oauth_curl.php
Created February 29, 2016 03:38 — forked from m13z/twitter_oauth_curl.php
Super simple PHP twitter oauth request without user context (https://dev.twitter.com/docs/auth/application-only-auth)
/*
* using curl
*/
$key = 'YOUR_KEY_HERE';
$secret = 'YOUR_SECRET_HERE';
$api_endpoint = 'https://api.twitter.com/1.1/users/show.json?screen_name=marcosfernandez'; // endpoint must support "Application-only authentication"
// request token
$basic_credentials = base64_encode($key.':'.$secret);
@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 + "'])";
}
};