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: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: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: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: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: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})/;