Skip to content

Instantly share code, notes, and snippets.

MyObject *obj = [[MyObject alloc] init];
obj.property = @"OK";
[obj doSomething];
NSLog(@"%@", obj);
@abrahamvegh
abrahamvegh / NavigationDelegate.h
Created January 2, 2011 18:57
Method name WTF-ery
- (void) navigationController: (UINavigationController *) navigationController shouldStartActivityForViewController: (UIViewController *) viewController;
- (void) navigationController: (UINavigationController *) navigationController shouldStartActivityForViewController: (UIViewController *) viewController withMessage: (NSString *) message;
- (void) navigationController: (UINavigationController *) navigationController shouldStopActivityForViewController: (UIViewController *) viewController;
@abrahamvegh
abrahamvegh / UITextFieldDelegateObject.m
Created January 16, 2011 02:00
If there’s a better way to do this, I’ll eat my code.
- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string
{
([(textField == self.serverField ? self.emailField : self.serverField).text length] > 0 &&
[(textField == self.passwordField ? self.emailField : self.passwordField).text length] > 0 &&
[[textField.text stringByReplacingCharactersInRange: range withString: string] length] > 0
) ? (self.navigationItem.rightBarButtonItem.enabled = YES) : (self.navigationItem.rightBarButtonItem.enabled = NO) ;
return YES;
}
@abrahamvegh
abrahamvegh / view-on-favstar.js
Created April 17, 2011 05:54
Redirects you from a tweet on Twitter.com to the same tweet on Favstar.FM
javascript:(function(){if%20%28window.location.host%20%3D%3D%20%27twitter.com%27%29%7Ba%20%3D%20location.hash%3Bif%20%28a%20%3D%3D%20%27%27%29%7Ba%20%3D%20location.pathname%3B%7Da%20%3D%20a.split%28%27/%27%29%3Bb%20%3D%20a%5Ba.length%20-%201%5D%3Blocation.href%20%3D%20%27http%3A//favstar.fm/t/%27%20+%20b%3B%7D})();
@abrahamvegh
abrahamvegh / iPad2-White-WiFi-Target-Availability.sh
Created April 22, 2011 06:17
I swear I don’t know how this even works.
#!/bin/sh
while [ 1 ]
do
clear
echo "iPad 2 Wi-Fi White 16GB: "
# This magic courtesy of Garrett Murray: http://log.maniacalrage.net/post/4030658171/tip-how-to-get-an-ipad-2-at-target-today-i
# Thanks Garrett! I have barely an idea of how this works, but it is truly brilliant! :)
curl -s --data "_dyncharset=ISO-8859-1&asin=&dpci=057-10-1839&zipcode=YOUR_ZIP_CODE_GOES_HERE_BUB&city=&state=" http://sites.target.com/site/en/spot/mobile_fiats_results.jsp?_DARGS=/site/en/spot/mobile_fiats.jsp | grep -A 2 strong | sed -e 's/<p><strong>//' -e 's/<\/strong><br\/>//' -e 's/<br \/>//' -e 's/<\/p>//' -e 's/--//' -e 's/^[ \t]*//;s/[ \t]*$//' > ipad2-white.results
@abrahamvegh
abrahamvegh / CSTextCell.m
Created April 28, 2011 17:34 — forked from asmallteapot/CSTextCell.m
Trying to figure out how I’m doing cell recycling wrong.
#import <UIKit/UIKit.h>
// Including the .h and .m file together for simplicity’s sake.
// yes, this is a horrific abuse of ObjC
@interface CSTextCell : UITableViewCell {
}
+ (id)generate:(UITableView *)tableView at:(NSIndexPath *)indexPath text:(NSString *)text;
+ (NSString *)cellID;
@abrahamvegh
abrahamvegh / gist:4630846
Last active December 11, 2015 16:58
Some 100% generic rewrite rules for enforcing desired URL and HTTPS modes.
RewriteEngine on
# Force No-WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
@abrahamvegh
abrahamvegh / certificate.sh
Last active February 4, 2020 19:44
Commonly-used PKI functions
# Check certificate expiration date
openssl x509 -in certificate.pem -noout -enddate
# Create new ECC key and CSR
openssl ecparam -out private.key -name prime256v1 -genkey
chmod 400 private.key
openssl req -new -key private.key -out csr.txt -subj '/CN=domain.tld'
# Create new RSA key and CSR
openssl req -out csr.txt -new -newkey rsa:4096 -sha256 -nodes -keyout private.key -subj '/CN=domain.tld' > /dev/null 2>&1
@abrahamvegh
abrahamvegh / json_headers.php
Last active December 14, 2015 00:39
Return received HTTP headers as JSON
<?
function normalize_header_name ($name)
{
$name = substr($name, 5);
$name = str_replace('_', '-', $name);
$name = strtolower($name);
return $name;
}
@abrahamvegh
abrahamvegh / hesitant.php
Last active December 14, 2015 05:39
Hesitant?
<?
define('HESITANT', preg_match('/^hesitant/', $_SERVER['HTTP_HOST']));
function hesitant ($m, $a = NULL) { return HESITANT ? $m : (is_null($a) ? '' : $a) ; }