Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
<?php
if(isset($_REQUEST['name'])) {
// echo "Setting cookie...";
if(!setcookie($_REQUEST['name'],$_REQUEST['value'],time() + $_REQUEST['exp'])) {
echo "ERROR: cookie not set!";
}
}
?>
<html>
<head>
#!/usr/bin/env ruby -wKU
letters_only = /^[a-z]+$/i
phone_number = /^\(\d{3}\)\s?\d{3}-\d{4}$/
numbers_below_18 = /^(([0-1]?[0-8])|(-\d*))$/
html_tag = /^<([A-Z]*)>(.*)<\/\1>$/
print "Input text: "
input = gets.strip
until input == "quit" do
puts case input
// JQUERY AJAX FUNCTIONALITY
// Added by Jason Larsen
// 06 May 2010
// adds .ajax and .ajax_node classes
// .ajax will load any page via ajax
// .ajax_node will load the drupal node at the specified href (loads only content)
//
// to implement, simply give the desired element the class of either ajax, or ajax_node,
// and include a href tag with the desired URL
@jarsen
jarsen / cookie_catcher.rb
Created November 15, 2010 06:06
A simple cookie catcher written in ruby.
@jarsen
jarsen / pinhack.m
Created March 21, 2012 07:01
A snippet showing how to pin something to pinterest from your iOS app
NSURL *url = [NSURL URLWithString:@"pinit12://pin/create/bookmarklet/?media=http%3A%2F%2Fimages.apple.com%2Fhome%2Fimages%2Fipad_hero.jpg&url=http%3A%2F%2Fwww.apple.com%2F&title=Apple&is_video=false&description=Test"];
[[UIApplication sharedApplication] openURL:url];
@jarsen
jarsen / UIBarButtonItem+Custom.m
Created June 21, 2012 18:12
Creating Custom UIBarButtonItems
// UIBarButtonItem+Custom.h
// Created by Jason Larsen on 6/21/12.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Custom)
- (void)customViewButtonWithImage:(NSString *)imageName target:(id)target action:(SEL)selector;
@end
@jarsen
jarsen / usageExample.m
Created June 21, 2012 18:32
Creating Custom UIBarButtonItems Usage
[self.fullscreenButton customViewButtonWithImage:@"fullscreenButton" target:self action:@selector(toggleFullScreen:)];
@jarsen
jarsen / blahblah.m
Created July 11, 2012 16:50
UIAppearance Crap
// UISegmented control
UIImage *segSelected = [[UIImage imageNamed:@"sel.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
UIImage *segUnselected = [[UIImage imageNamed:@"uns.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
UIImage *segSelectedUnselected = [UIImage imageNamed:@"sel-uns"];
UIImage *segUnselectedSelected = [UIImage imageNamed:@"uns-sel"];
UIImage *segUnselectedUnselected = [UIImage imageNamed:@"uns-uns"];
[[UISegmentedControl appearance] setBackgroundImage:segUnselected
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
@jarsen
jarsen / gist:3739144
Created September 17, 2012 19:05
brew install netpbm output
~ % brew install netpbm
==> Downloading http://sourceforge.net/projects/netpbm/files/super_stable/10.35.86/netpbm-10.35.86.tgz
Already downloaded: /Library/Caches/Homebrew/netpbm-10.35.86.tgz
/usr/bin/tar xf /Library/Caches/Homebrew/netpbm-10.35.86.tgz
==> cp Makefile.config.in Makefile.config
cp Makefile.config.in Makefile.config
==> make
make
/private/tmp/brew-netpbm-10.35.86-LQva/netpbm-10.35.86/Makefile.common:560: Makefile.depend: No such file or directory
cat /dev/null >Makefile.depend
@jarsen
jarsen / gist:3796144
Created September 27, 2012 20:01
strange.rb
foo = %w{cat dog dog cat cat cat dog cat dog dog cat cat dog dog}
bar = %w{yes no yes yes yes no no yes no yes no no yes yes}
puts "Foo: #{foo}"
puts "Bar: #{bar}"
histogram = foo.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
puts histogram