Skip to content

Instantly share code, notes, and snippets.

var charge = stripe.charges.create({
amount: 1000,
currency: "usd",
description: "Example charge",
source: 'tok_visa',
application_fee: 200,
stripe_account: 'acct_xyz'
}, function(err, charge) {
console.log(err, charge);
});
{
"Miles": 1073,
"Results": [
{
"Fees": 146.77381,
"Mode": 10,
"Dispatch": {
"Messages": null,
"Available": true
},
@crystalschang
crystalschang / gist:c7a026f88f5143aa1fed
Last active August 29, 2015 14:19
ElasticSearch on AWS

Setting up an ElasticSearch Cluster on AWS

Security groups

Create a “production-elastic-search” security group and add it to all of your ES instances. Add a custom rule to allow traffic between instances in that security group - otherwise, they will not be able to see each other and connect to the cluster.

Custom TCP Rule / Protocol: TCP / Port Range: 9200-9400 / Source: sg-xxxxxx (the same sg-xxxxx as “production-elastic-search"

(You may need to also allow your own IP to access this security group to aid in debugging.)

Config

@crystalschang
crystalschang / gist:4669454
Last active December 11, 2015 22:28
Add-to-cart box
// 1. Grab a list of all the stock options to populate the stock options
// Endpoint: /a/product/:productId/stock/options
var options =
{
"color":[{"3":"Black"},{"346220":"Tailored Grey"}],
"d15":[{"125699":"XS (US 0-2)"},{"125701":"MD (US 8-10)"},{"125702":"LG (US 12-14)"},{"125703":"XL (US 16)"}],
"d46":[{"93358":"31"}
]
}
@crystalschang
crystalschang / gist:4659561
Last active December 11, 2015 20:59
Filtering function for stock rows
/** Returns a new array of valid stock rows, given the input selections
* slimStockArray: the starting list of stocks, to be filtered
* keyOrder: mapping of keys to its index in slimStockArray, ex: {'color':0,'d3':1,'d4':2,'onhand':3}
* selections: object with the current user's selections, ex: {'color':'3', 'd4':'60425'}
**/
function filter(slimStockArray, keyOrder, selections) {
var result = new Array();
for(var i=0; i<slimStockArray.length; i++) {
var row = slimStockArray[i];
@crystalschang
crystalschang / gist:2552882
Created April 29, 2012 19:36
Sample json output for image
[
// First BAR
[
// First BEAT
{
"white": 16 // the number is the intensity level
},
// Second BEAT
{
"white": 6,
@crystalschang
crystalschang / gist:2522608
Last active October 3, 2015 20:37
Front-end canvas pixel analysis: Take an image url as an input, and render a pixelated version of the image on the canvas.
<!DOCTYPE html>
<html>
<head>
<script src="http://soo-jung.com/lib/jquery.js"></script>
<script src="jquery.getimagedata.min.js"></script>
<script>
$.getImageData({
url: 'https://www.hackerschool.com/assets/slideshow_01-540531c0d5690f948a4d5d02c5400827.jpg',
server: 'http://maxnov.com/getimagedata/getImageData.php',
success: function (image) {
{
"colors": {
"white": "violin.wav",
"red": ["red1.wav", "red2.wav"],
"green": "green.wav"
},
"bars": {
"1": [
"white",
"red",