Skip to content

Instantly share code, notes, and snippets.

View oshikryu's full-sized avatar

Ryuta Oshikiri oshikryu

  • San Francisco, CA
View GitHub Profile
w next word
e end of word
b is back a word
dd line
split buffer
ctr +l w + v
@oshikryu
oshikryu / renderlegend.coffee
Created February 6, 2014 23:48
renders a legend given a quantile scale of colors
@colorScale = d3.scale.quantile()
.domain([0, .01, .1, .2, .3, .5, .8, 1.3, 2.1, 3.3])
.range(@colors)
_renderLegend: ->
# quantizes colors and adds an extra 0
_legendData = [0].concat(@colorScale.quantiles())
_legendData.unshift(0)
@oshikryu
oshikryu / rowarrayblanks.coffee
Created February 4, 2014 18:14
Fill row array blanks in table
_fillRowArrayBlanks: ->
curLen = @displayedArray.length
diff = @watchSamples - curLen
filler = []
for i in [0...diff]
filler[i] = [
point: '-'
pinned: true
]
@oshikryu
oshikryu / resize.coffee
Created January 30, 2014 19:19
resize legend based on width and bbox pos
_spaceLines: ->
keys = d3.selectAll('.key')[0]
extraRows = 0
_lineSpacer = (d, i) =>
keyPos = keys[i].getBBox().x
keyEdge = keyPos + keys[i].getBBox().width
edge = @w - @m*2
@oshikryu
oshikryu / csvtostring.coffee
Created January 27, 2014 21:30
convert csv string to file download
window.URL = window.URL || window.webkitURL
blob = new Blob([csvString], {type: 'text/plain'})
objectURL = window.URL.createObjectURL(blob)
@$el.find('.confirm').parent().attr("href", window.URL.createObjectURL(blob))
@$el.find('.confirm').parent().attr("download", @_checkFileName())
@oshikryu
oshikryu / transformfeed.coffee
Created January 23, 2014 19:08
Takes an array of time/value pairs and intelligently samples based on a given base frequency
_transformFeedData: (feed) ->
processedFeed = {}
intervalWindow = []
timeStep = {}
metaCounter = 1
timeStep = @_getTimeStep feed[0].time, feed[1].time
initialDate = new Date(feed[0].time).getTime()
metaCounter = @_getMetaCount initialDate, timeStep
@oshikryu
oshikryu / gist:8060638
Last active December 31, 2015 23:29
An attempt to automatically scroll an svg when a d3 tree node is added
_scrollContainer: ->
targets = d3.select(d3.selectAll('g.node.selection').pop()).node()
return unless targets
selectionCoord = targets.pop().getBoundingClientRect()
selectedTarget = d3.select('g.selected')
selectedTarget = _.compact selectedTarget[0]
return unless selectedTarget.length > 0
selectedCoord = selectedTarget[0].getBoundingClientRect()
bottomCoord = Math.max selectionCoord.bottom, selectedCoord.bottom
@oshikryu
oshikryu / flare.json
Last active June 25, 2016 08:44
d3 collapsible tree layout with route highlighting
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
@oshikryu
oshikryu / gist:5589507
Created May 16, 2013 05:00
downvote everything on a reddit page
i = setInterval(function() {e = $(".down")[0]; if(e) e.onclick(); else clearInterval(i);}, 500);
@oshikryu
oshikryu / gist:5527756
Last active December 17, 2015 01:19
sandbox
$(function () {
// generated timestamps
t = ['1/1/2010 00:00', '1/1/2010 01:00','1/2/2010 23:00']; // (hourly data for two days)
// generated values
vals = [34, 15, 28, 16, 8, 47, 35, 41, 1, 24, 13, 19, 18, 27, 32, 6, 39, 25, 9, 14, 22, 40, 38, 48, 36, 12, 3, 31, 43, 29, 42, 2, 21, 23, 11, 44, 30, 10, 49, 33, 17, 37, 7, 4, 45, 46, 50, 5, 26, 20]; // random list of values - two days in length
// declaring model
var graphVals = new Backbone.Model({time: t, value: vals});