Skip to content

Instantly share code, notes, and snippets.

View tbeseda's full-sized avatar
🦬

Taylor Beseda tbeseda

🦬
View GitHub Profile
var myJSON = {
foo : 'bar',
lorem : 'ipsum',
bar : 'foo',
ipsum : 'lorem'
}
// commas first
var myJSON = {
foo : 'bar'
javascript:var%20links=document.getElementsByTagName('head')[0].getElementsByTagName('link');for(var%20i=0;i%3Clinks.length;i++){if(links[i].getAttribute('rel')=='apple-touch-icon'){links[i].parentNode.removeChild(links[i])}; break;};var%20s=document.createElement('link');s.setAttribute('rel', 'apple-touch-icon');s.setAttribute('href',prompt('Touch icon URL?','http://'));document.getElementsByTagName('head')%5B0%5D.appendChild(s);void(s);
@tbeseda
tbeseda / Snoopy
Created September 13, 2010 18:30
javascript:(function()%7Bvar%20d%3Ddocument%2Cs%2Ce%3Bvar%20el%3Dd.getElementById('snpy')%3Bif(typeof%20Snoopy!%3D'undefined')%7BSnoopy.toggle()%3Breturn%7Delse%20if(el)%7Bel.className%3D%2Fclosed%2F.test(el.className)%3Fel.className.replace('closed'%2C'')%3Ael.className%2B'%20closed'%3Breturn%7Ds%3Dd.createElement('link')%3Bs.setAttribute('href'%2C'http%3A%2F%2Fsnoopy-assets.allmarkedup.com%2Fsnoopy-min.css')%3Bs.setAttribute('rel'%2C'stylesheet')%3Bs.setAttribute('type'%2C'text%2Fcss')%3Bd.getElementsByTagName('head')%5B0%5D.appendChild(s)%3Be%3Dd.createElement('script')%3Be.setAttribute('src'%2C'http%3A%2F%2Fsnoopy-assets.allmarkedup.com%2Fsnoopy-min.js')%3Bd.getElementsByTagName('body')%5B0%5D.appendChild(e)%7D)()%3B
var player = 'your gamertag';
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.bungie.net%2FStats%2FReach%2FCareerStats%2Fdefault.aspx%3Fplayer%3D"+player+"%22%20and%20xpath%3D'%2F%2Fspan%5B%40id%3D%22ctl00_mainContent_kdLabel%22%5D'&format=json&diagnostics=true&callback=?", function(data){
var kdr = data.query.results.span.content;
alert('My Halo Reach Kill/Death ration is:' + kdr);
});
<?
// get a quote for digest email signature... o_O
$ch = curl_init('http://iheartquotes.com/api/v1/random?source=art&max_lines=2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
list($quote) = explode('[', $output);
// yeah, that just happened...
?>
@tbeseda
tbeseda / GoogleSite_incrementPage.js
Created October 27, 2010 20:37
Google App Script incrementPage creates a new subpage of a specified page that has a title of the next increment
function incrementPage(parentURL, pageHTML) {
var parentPage = SitesApp.getPageByUrl(parentURL)
,childPages = parentPage.getAllDescendants()
,biggest = 1000;
for(i=0; i<childPages.length; i++) {
var currentName = childPages[i].getName();
if(isNaN(currentName))
continue;
+currentName; // make it a number
<?
$host = 'http://api.untappd.com/v1/user_feed/tbeseda?api_key=1234';
$process = curl_init($host);
curl_setopt($process, CURLOPT_USERPWD, 'user:pass');
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
print_r($return);
?>
@tbeseda
tbeseda / fit.js
Created January 6, 2011 00:09
truncate a string to a set number of chars and add ellipses with respect for non-word characters.
function fit(str, nMaxChars) {
var n = nMaxChars - 1,
strRX = /\s|\.|,/,
tmp_str = str.slice(0, n),
final_str;
if (str.length <= n) return str;
function getLastChar(str) {
return str.slice(str.length-1, str.length);
@tbeseda
tbeseda / canvas-bgStripe.js
Created January 19, 2011 00:00
Use js to create a canvas image to create a pinstripe background.
function bgStripe() {
if (!!!document.createElement('canvas').getContext)
return;
var canvas = document.createElement("canvas");
canvas.width = 6;
canvas.height = 1;
var ctx = canvas.getContext("2d");
ctx.fillStyle = 'black';
ctx.fillRect(0,0,2,1);
ctx.fillStyle = 'rgba(30,30,30,1)';
@tbeseda
tbeseda / json_dates.rb
Created February 18, 2011 18:18
Only Chrome natively parses ISO8601 into js Date objects. Duck punch an ISO8601 string with this utility js function, or Rails solution.
# If you're building the JSON provider with Rails,
# add to the as_json method of TimeWtihZone by adding
# this file to your config/initializers/
class ActiveSupport::TimeWithZone
def as_json(options = {})
strftime('%Y/%m/%d %H:%M:%S %z')
end
end