Skip to content

Instantly share code, notes, and snippets.

View mspanish's full-sized avatar

Stacey Reiman mspanish

View GitHub Profile
@scripting
scripting / correctedStatusMedia
Created July 1, 2014 14:13
Updated code snippet for a Scripting News blog post, with corrected code
//Goes with this blog post -- http://scripting.com/2014/07/01/twitterApiUpdatewithmedia.html#aIJWTS
var params = {
url: "https://api.twitter.com/1.1/statuses/update_with_media.json",
oauth: {
consumer_key: process.env.twitterConsumerKey,
consumer_secret: process.env.twitterConsumerSecret,
token: parsedUrl.query.oauth_token,
token_secret: parsedUrl.query.oauth_token_secret
//referenced in this blog post -- http://scripting.com/2014/07/01/twitterApiUpdatewithmedia.html
function tweetImage (status) {
var theCanvas = document.getElementById ("idCanvas");
var urlImage = theCanvas.toDataURL ();
var imgType = "image/png";
function encode (s) {
return (encodeURIComponent (s));
}
@babakhani
babakhani / jsgradient
Last active February 6, 2020 12:18
get array of color between two colors
//https://dl.dropboxusercontent.com/u/17365636/web/jsGradient.js
jsgradient = {
inputA : '',
inputB : '',
inputC : '',
gradientElement : '',
// Convert a hex color to an RGB array e.g. [r,g,b]
// Accepts the following formats: FFF, FFFFFF, #FFF, #FFFFFF
hexToRgb : function(hex){
@jimhigson
jimhigson / gist:7985923
Last active January 19, 2024 11:27
round svg path to one decimal place
/* round("M -0.09375,-3 A 1.001098,1.001098 0 1 0 0,-1 C 0.56412939,-1 1,-0.56412939 1,0 1,0.27245181 0.8799664,0.4950336 0.6875,0.6875 A 1.016466,1.016466 0 1 0 2.125,2.125 C 2.6563912,1.5936088 3,0.83211769 3,0 3,-1.6450096 1.6450096,-3 0,-3 a 1.0001,1.0001 0 0 0 -0.09375,0 z")
=> "M -0.1,-3 A 1,1 0 1 0 0,-1 C 0.6,-1 1,-0.6 1,0 1,0.3 0.9,0.5 0.7,0.7 A 1,1 0 1 0 2.1,2.1 C 2.7,1.6 3,0.8 3,0 3,-1.6 1.6,-3 0,-3 a 1,1 0 0 0 -0.1,0 z"
*/
function round (path) {
return path.replace(/[\d\.-][\d\.e-]*/g, function(n){return Math.round(n*10)/10})
}
@mspanish
mspanish / gist:7192053
Created October 28, 2013 06:06
Dust.js partial helper, sets new context
"partial": function( chunk, context, bodies, params ){
var partial_context = {};
/* optional : context fo server processed partial related data*/
var p_context = context.get("partial");
if(p_context || params) {
// add to the partial context
}
return bodies.block( chunk, dust.makeBase(partial_context));
}
@iwek
iwek / svg-image2.js
Created October 23, 2013 16:26
D3js click function to save SVG as dataurl in IMG tag, load into CANVAS and save as PNG dataurl, and auto download the actual PNG file.
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
@simonblee
simonblee / index.html
Last active December 21, 2015 01:28
Marionette with Dust templates example. Save `package.json` and `index.html` into the same directory. Run `npm install` and then open `index.html`. First the dust template is compiled, then a view is created which uses the compiled template, then the view is rendered and attached to the body DOM element. In production, it's recommended to pre-co…
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Marionette Dust Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="node_modules/lodash/lodash.js"></script>
<script type="text/javascript" src="node_modules/backbone/backbone.js"></script>
(function(global, undefined) {
"use strict";
var Pocket = (function() {
var https = require("https");
function Pocket(opt) {
this.consumer_key = opt.consumer_key;
this.access_token = opt.access_token;
}
@willurd
willurd / web-servers.md
Last active April 20, 2025 00:42
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000