Skip to content

Instantly share code, notes, and snippets.

View jzazove's full-sized avatar
💭
🎸

Jonathan Zazove jzazove

💭
🎸
View GitHub Profile
@jzazove
jzazove / gist:1479763
Created December 15, 2011 03:54
URL Friendly Javascript Regex
/* function to urlify a string */
var urlify = function(a){return a.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "-").replace(/^-+|-+$/g, '')};
/* usage example */
var str_a = "* The Best Wallpaper Magazine in the . ? & world! : Rjer9238131 & ";
urlify(str_a)
/* returns */
"the-best-wallpaper-magazine-in-the-world-rjer9238131"
@jzazove
jzazove / validate.js
Created January 26, 2012 15:07
Validating Email Addresses
function validateEmailAddress(s) {
var atSym = "@", dot = ".";
if (s.indexOf(atSym) === -1 || s.indexOf(" ") !== -1 || s.indexOf(atSym) > s.lastIndexOf(dot) || s.length - s.lastIndexOf(atSym) < 3 || s.lastIndexOf(atSym) + 1 === s.lastIndexOf(dot) || s.length - s.lastIndexOf(dot) <== 2 ) return false;
else return true;
}
@jzazove
jzazove / tos_oauth.php
Created August 3, 2012 19:28
Tip or Skip OAuth PHP Snippet
<?php
require 'OAuth.php';
$key = '<your_app_key>';
$secret = '<your_app_secret>';
$consumer = new OAuthConsumer($key, $secret);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;
$my_domain = 'http://www.mydomain.net';
@jzazove
jzazove / tos-oauth.js
Created August 3, 2012 19:33
Tip or Skip OAuth nodejs Snippet
Connecting to the Tip or Skip API with Node.js.
In your package.json, require the oauth module and install it with `npm update`:
```javascript
// ...
dependencies: {
"oauth": "x.x.x"
},
// ...
@jzazove
jzazove / tos-oauth.py
Created August 3, 2012 19:42
Tip or Skip OAuth Python Snippet
REQUEST_TOKEN_URL = 'https://tips.by/oauth/request_token'
ACCESS_TOKEN_URL = 'https://tips.by/oauth/access_token'
AUTHORIZATION_URL = 'https://tips.by/oauth/authorize'
CALLBACK_URL = '<your_encoded_callback_url>'
RESOURCE_URL = 'https://tips.by/api/1.0/product/5018324b18771ae13b000008/tip'
CONSUMER_KEY = '<consumer_key>'
CONSUMER_SECRET = '<consumer_secret>'
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
# Create our client.
@jzazove
jzazove / gist:4169358
Created November 29, 2012 14:13
Removing Safari URL Address Bar from Mobile when Orientation Changes Occur
(function() {
function s() {
var e = document.createElement("div");
e.style.height = "10001px";
document.body.appendChild(e);
setTimeout(function() {
window.scrollTo(0, 0);
document.body.removeChild(e);
}, 1);
@jzazove
jzazove / gist:5117415
Created March 8, 2013 15:52
Return random value of array
var randomValue = function(a){
return a[Math.floor(Math.random() * a.length)];
};
@jzazove
jzazove / .portfwd
Created May 22, 2013 20:36
Port forwarding to 80 and 443 on a mac
sudo ipfw -f flush
sudo ipfw add 1000 fwd 127.0.0.1,3000 tcp from any to me 80
sudo ipfw add 2000 fwd 127.0.0.1,3131 tcp from any to me 443
@jzazove
jzazove / cnn_splash.html
Created June 24, 2013 01:58
CNN.com recommendation
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>CNN.com - Breaking News, U.S., World, Weather, Entertainment &amp; Video News</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
<meta name="viewport" content="width=1024"/>
<meta property="fb:app_id" content="80401312489"/>
<meta property="fb:page_id" content="129343697106537"/>
<style type="text/css">
{"tips":[{"id":"52b3b3b4c49587b6761d6edd","name":"Interactive kaleidoscope floor #home #decor #cool #geekchic ","image":"http://d3t3tfuk4dded6.cloudfront.net/actionable/528d7909c49587b67618fbff/201310213754-0-interactive-kaleidoscope-floor-home-decor-cool-geekchic_570_361.jpg","thumbnail":"http://d3t3tfuk4dded6.cloudfront.net/actionable/528d7909c49587b67618fbff/201310213754-0-interactive-kaleidoscope-floor-home-decor-cool-geekchic_220_139.jpg","url":"http://","head":"528d7909c49587b67618fbff","type":"product","date":"2013-12-20T03:04:20.666Z","preload":"R0lGODdhBQADAPMAALS2tJ6loMOsk5ltfX9/lpGRjoFubpxyhnNshVxpeoB+fUo8RVtmdExta2V9bQAAACwAAAAABQADAAAECxAEMUgxByW1WHMRADs=","source":{"id":"4ec6b9c562fb694c0c000002","image":"http://d3t3tfuk4dded6.cloudfront.net/actor/4ec6b9c562fb694c0c000002/2012027213023-jz_430_461.jpg","preload":"R0lGODdhBQAFAPABAD9/I////ywAAAAABQAFAAACCAwQiWhsn2IBADs=","thumbnail":"http://d3t3tfuk4dded6.cloudfront.net/actor/4ec6b9c562fb694c0c000002/2012027213023-jz_187_200.jpg","type":"user","n