Skip to content

Instantly share code, notes, and snippets.

@enjalot
enjalot / cors_server.py
Created June 10, 2012 06:19
Allow CORS with python simple http server
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or
@bellbind
bellbind / loader.html
Last active May 4, 2024 04:42
[threejs][html5]STL File Viewer with HTML5 File API
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>STL File Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
<script src="loader.js"></script>
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@mickaelandrieu
mickaelandrieu / quotes_json.js
Created November 26, 2013 12:50
Scrap a website with CasperJs, JSON output.
var links = [];
var quotes = [];
var tempUrl = [];
var infos = [];
var maxLinks = 10;
var firstUrl = 'http://www.imdb.com/search/title?at=0&num_votes=5000,&sort=user_rating,desc&start=1&title_type=tv_infoss';
var newUrl;
var x = require('casper').selectXPath;
@amysimmons
amysimmons / js-tricky-bits.md
Last active November 16, 2022 02:42
Understanding closures, callbacks and promises in JavaScript

#Understanding closures, callbacks and promises

For a code newbie like myself, callbacks, closures and promises are scary JavaScript concepts.

10 months into my full-time dev career, and I would struggle to explain these words to a peer.

So I decided it was time to face my fears, and try to get my head around each concept.

Here are the notes from my initial reading. I'll continue to refine them as my understanding improves.

@mickaelandrieu
mickaelandrieu / webservice.js
Created October 11, 2013 20:45
Use casperJs as a Webservice
/* from http://stackoverflow.com/questions/15852987/casperjs-passing-data-back-to-php/16489950#16489950
//define ip and port to web service
var ip_server = '127.0.0.1:8585';
//includes web server modules
var server = require('webserver').create();
//start web server
var service = server.listen(ip_server, function(request, response) {
@nickhudkins
nickhudkins / createFragmentContainer.js
Last active July 30, 2021 16:18
Data Masking with Apollo / GraphQL Anywhere
import React from 'react';
import { filter } from 'graphql-anywhere';
import hoistNonReactStatic from 'hoist-non-react-statics';
/*
* createFragmentContainer returns a component which expects props that match
* WrappedComponent's fragment names, and provides data masking
*/
export default function createFragmentContainer(WrappedComponent) {
@vitch
vitch / apply-styles.css
Created August 1, 2012 13:44
SVG background images on d3 fills
#graph svg g.us rect
{
fill: url(#tile-us) #cccccc;
}
#graph svg g.worldwide rect
{
fill: url(#tile-ww) #cccccc;
}
@oroce
oroce / app.js
Last active June 16, 2021 21:05
Redirect express while keeping params
/*
URLs:
http://localhost:3000/arrive?foo=bar&utm_source=smart-redir
*/
var redirect = require('redirect-with-params');
var express = require('express');
var app = express();
app.use(redirect({
@n1k0
n1k0 / 404checker.js
Created January 11, 2013 10:55
A CasperJS script to check for 404 & 500 internal links on a given website
/**
* This casper scipt checks for 404 internal links for a given root url.
*
* Usage:
*
* $ casperjs 404checker.js http://mysite.tld/
* $ casperjs 404checker.js http://mysite.tld/ --max-depth=42
*/
/*global URI*/