Skip to content

Instantly share code, notes, and snippets.

@cmdoptesc
cmdoptesc / get-selected-text
Last active December 20, 2015 13:19
getSelectedText
var getSelectedText = function() {
var txt = "";
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
txt = document.selection.createRange().text;
}
return txt;
};
@cmdoptesc
cmdoptesc / color-palettes
Created August 8, 2013 07:08
colors schemes combinations
http://design-seeds.com/
http://www.colourlovers.com/palettes/most-loved/past-month/
@cmdoptesc
cmdoptesc / Readme.md
Last active March 12, 2016 09:52
muniNow Quick Demo

muniNow Demo

muniNow aims to be a nicer NextMuni by giving users the ability to see when the soonest Muni bus is arriving at a glance.

Live demo on Bl.ocks.org

Powered by D3, built at Catalyst/Hack Reactor as a personal project. And many thanks to Mike and Adnan.

al lin, aug. 2013

@cmdoptesc
cmdoptesc / Readme.md
Last active March 4, 2018 01:53
JavaScript D3: Drawing Concentric Arcs
@cmdoptesc
cmdoptesc / Readme.md
Last active February 12, 2018 16:51
JavaScript D3: Arc tween transitions using attrTween and attr methods

D3: Arcs Tweening Animation

view on bl.ocks.org

Click on the grey circles. The green arcs will transition using attr, whereas the red ones will use the attrTween method.

If you have not seen/read Bostock's arc tween example, it's probably the best place to start. Secondly, I've posted up a basic example of drawing static, concentric arcs (gist), which might be helpful before adding on tweens/animations.

Below is some annotated source code from my experience playing with arcs. The biggest issue I came across was understanding the role of the arcTween helper function in relation to attrTween. Unlike attr, which takes a value as its second argument, attrTween requires a helper function, arcTween, which will be called during the intermediary animation ticks. This method was used for my [muniNow project](http

@cmdoptesc
cmdoptesc / nodejs-express-cors.js
Created August 21, 2013 06:39
Node.js Express CORS settings / cross origin resource sharing / XMLHttpRequest Origin is not allowed by Access-Control-Allow-Origin
// Express CORS middleware.. so much easier than trying to get Restify to work
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Accept, Origin, Referer, User-Agent, Content-Type, Authorization');
// intercept OPTIONS method
if (req.method === 'OPTIONS') {
res.send(200);
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
stroke-opacity: .5;
stroke-width: .5px;
}
@cmdoptesc
cmdoptesc / quicksort.js
Created September 9, 2013 06:49
QuickSort In Place (in JavaScript)
// quicksort using new arrays is easy, but surprisingly, there weren't too many examples
// in javascript of in-place quick sort...
// the outer function is simply just a wrapper that copies the original array;
// you can just use lines 12-37 if preserving the original array isn't important
function quickSortInPlace(unsortedArray) {
var unsorted = unsortedArray.slice(); // copy the original array
@cmdoptesc
cmdoptesc / Readme.md
Last active November 26, 2021 17:38
D3: Open Hours (.csv parsing)

D3: Open Hours

view on bl.ocks.org
github repo

D3 visualisation utilising D3's text/CSV to read/parse a CSV file with restaurant information and display which restaurants are currently open.

Users can drag the time (red line) to display restaurants open at other hours.