Skip to content

Instantly share code, notes, and snippets.

View akozlik's full-sized avatar

Andrew Kozlik akozlik

View GitHub Profile
+ (UIColor *) colorFromHexString:(NSString *)hexString {
NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
if([cleanString length] == 3) {
cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
[cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
[cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
[cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
}
if([cleanString length] == 6) {
cleanString = [cleanString stringByAppendingString:@"ff"];
SELECT *, (3959 * acos(cos(radians('".$lat."')) * cos(radians(lat)) * cos( radians(long) - radians('".$lng."')) + sin(radians('".$lat."')) *
sin(radians(lat))))
AS distance
FROM carpark WHERE distance < 15 ORDER BY distance LIMIT 0 , 10
@akozlik
akozlik / 0_reuse_code.js
Created February 5, 2014 18:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@akozlik
akozlik / gist:8874959
Created February 8, 2014 00:51
Batch convert videos to mp4 using ffmpeg
for i in *.avi; do name=`echo $i | cut -d'.' -f1`; echo $name; ffmpeg -i $i $name.mp4 done
@akozlik
akozlik / gist:9296627
Created March 1, 2014 20:24
Useful MySQL command line instructions
// Dump an entire database
mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
// Dump specific tables from a database
mysqldump -u root -p [dbname] [table1] [table2] > [backupfile.sql]
// Restore database from sql file
mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
@akozlik
akozlik / gist:9555349
Created March 14, 2014 19:45
Dynamic Cell Height w/AutoLayout
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
static UITableViewCell *cell;
if (cell == nil) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ClueCell"];
}
[self configureCell:cell forIndexPath:indexPath];
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1.0f;
@akozlik
akozlik / gist:11241740
Created April 24, 2014 04:42
Zoom MapKit out to fit pins
-(void)zoomToFitMapAnnotations:(MKMapView*)mapView
{
if([mapView.annotations count] == 0)
return;
CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;
CLLocationCoordinate2D bottomRightCoord;
stop_id,stop_name,stop_lat,stop_lon,location_type
175,ROSEMONT SUPERSTOP, 28.6085340000, -81.4282110000,0
178,SPRINGS VILLAGE SHOPPING CTR, 28.6882790000, -81.4065090000,0
214,KOA ST AND MONTEREY RD, 28.1566130000, -81.4820430000,0
553,1700 17TH ST AND CONNECTICUT AVE, 28.2424240000, -81.2879670000,0
554,4500 US 192 HWY AND COMMERCE CENTER DR, 28.2548600000, -81.3190380000,0
555,ST CLOUD WAL-MART, 28.2541690000, -81.3148810000,0
556,4200 US 192 HWY AND KISSIMMEE PARK RD, 28.2508540000, -81.3130770000,0
561,2700 10TH ST AND LOUISIANA AVE, 28.2488240000, -81.2993230000,0
562,2400 10TH ST AND TENNESSEE AVE, 28.2488950000, -81.2964650000,0
@akozlik
akozlik / gist:12521fe329c69f28f9e9
Created January 27, 2015 15:10
iOS 7 and 8 notification backwards compatibility
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
@akozlik
akozlik / gist:2093209326b40e615aba
Created April 4, 2015 04:08
Loop through an array of objects with dates and group by week
$weeks = array();
$index = 0;
while (count($tmp_logs) > 0) {
$log = array_shift($tmp_logs);
$date = $log['date'];
$sunday = strtotime('last Sunday', $date);
$saturday = strtotime('Saturday 11:59pm', $date);
$done = false;