Skip to content

Instantly share code, notes, and snippets.

View oshikryu's full-sized avatar

Ryuta Oshikiri oshikryu

  • San Francisco, CA
View GitHub Profile
@oshikryu
oshikryu / gist:5491584
Last active October 16, 2020 10:14
youtube parsing
function getYoutubeKey(linkText) {
// var linkText = $('#modal #vidEmbedKey').val();
var reYoutubeKey = /^[a-zA-Z0-9\-]{11}$/;
if (reYoutubeKey.test(linkText)) {
return linkText;
}
var reYoutubeUrl = /http\:\/\/www\.youtube\.com\/watch\?v=([\w-]{11})/;
var httpsreYoutubeUrl = /https\:\/\/www\.youtube\.com\/watch\?v=([\w-]{11})/;
@oshikryu
oshikryu / gist:5491777
Created April 30, 2013 20:40
Handy dandy javascript formatting functions
String.prototype.format = function () {
var re = /\{\d+\}/g, args = arguments;
return this.replace(re, function (x) {return args[x.match(/\d+/)]; });
};
// Number.toRad method
if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
}
@oshikryu
oshikryu / gist:5491798
Created April 30, 2013 20:43
parse hash tags
// parse a string input or text body for #
//
function parseHashTags(words) {
var str_array = words.split(" ");
var pattern = /^\#/gi;
// the specific str_array element being processed
var part = "";
// rebuilt string of original title with hyperlinked words
@oshikryu
oshikryu / gist:5491807
Created April 30, 2013 20:44
youtube player facebook watch posting
// handle the facebook api watch functions for the youtube player
// removes the posted watch if it does not meet the requirements
var ytPlayerInterval, ytplayer;
function handleAPIWatch(){
try {
($('#modal_content object embed')[0]) ? ytplayer = $('#modal_content object embed')[0] : ytplayer = "";
var time = ytplayer.getCurrentTime();
if(ytplayer.getCurrentTime() >= (ytplayer.getDuration() / 2)) {
// console.log("out after 50");
if (fbstart) {
@oshikryu
oshikryu / gist:5491811
Created April 30, 2013 20:46
validate price from input
var validatePrice = /((\d+\.|\.)[0-9]{1,2})|\d+/;
if (!validatePrice.test($('#marketPrice').val())) {
alert_error('your price must be a numeric value');
return false;
}
@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});
@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 / 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: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 / 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