Skip to content

Instantly share code, notes, and snippets.

View eddieespinal's full-sized avatar

Eddie Espinal eddieespinal

View GitHub Profile
@eddieespinal
eddieespinal / WeatherIcons.swift
Last active May 15, 2018 19:02
Yahoo weather codes enum
// Created by Eddie Espinal on 1/29/18.
import Foundation
enum Code2Icon: String {
case code0, code1, code2
case code3, code4, code37, code38, code39, code40, code47
case code5, code6, code7, code35
case code8, code10, code17, code18
case code9
case code11, code12
@eddieespinal
eddieespinal / 0_reuse_code.js
Created March 9, 2016 20:48
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
@eddieespinal
eddieespinal / cropCameraImage.swift
Last active April 14, 2021 08:16
Crops a Picture from AVCaptureSession to the bounds of the AVCaptureVideoPreviewLayer (so Preview = CameraImage) - Swift Version
//This is the swift version of the following gist by @shexbeer https://gist.github.com/shexbeer/cb069d36ca8ec5edb515
func cropCameraImage(original: UIImage, previewLayer: AVCaptureVideoPreviewLayer) -> UIImage? {
var image = UIImage()
let previewImageLayerBounds = previewLayer.bounds
let originalWidth = original.size.width
let originalHeight = original.size.height
let searchString = "this"
let baseString = "This is some string that contains the word \"this\" more than once. This substring has multiple cases. ThisthisThIs."
let attributed = NSMutableAttributedString(string: baseString)
var error: NSError?
let regex = NSRegularExpression(pattern: searchString, options: .CaseInsensitive, error: &error)
if let regexError = error {
println("Oh no! \(regexError)")
@eddieespinal
eddieespinal / ELLowBitrateManager
Last active November 16, 2015 13:27
This class helps detect if a song has a low bitrate version on the server.
//
// ELLowBitrateManager.swift
//
//
// Created by Eddie Espinal on 11/11/15.
// Copyright © 2015 EspinalLab, LLC. All rights reserved.
//
import UIKit
@eddieespinal
eddieespinal / checkWhetherFileExistsIn
Created November 10, 2015 20:25
**Use this function below to check whether file exists at specified url**
**Use this function below to check whether file exists at specified url**
+(void)checkWhetherFileExistsIn:(NSURL *)fileUrl Completion:(void (^)(BOOL success, NSString *fileSize ))completion
{
//MAKING A HEAD REQUEST
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileUrl];
request.HTTPMethod = @"HEAD";
request.timeoutInterval = 3;
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
@eddieespinal
eddieespinal / parseQueryString.m
Last active August 29, 2015 14:27
Query String to NSDictionary
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
NSArray *pairs = [query componentsSeparatedByString:@"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:@"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
@eddieespinal
eddieespinal / getISO8601Formatter
Created May 19, 2015 14:16
// These functions are not thread-safe, nor are the NSDateFormatter instances they return. // Make sure that this function and the formatter are called on only one thread at a time.
#pragma mark - DATE CONVERSION:
// These functions are not thread-safe, nor are the NSDateFormatter instances they return.
// Make sure that this function and the formatter are called on only one thread at a time.
static NSDateFormatter* getISO8601Formatter() {
static NSDateFormatter* sFormatter;
if (!sFormatter) {
// Thanks to DenNukem's answer in http://stackoverflow.com/questions/399527/
sFormatter = [[NSDateFormatter alloc] init];
@eddieespinal
eddieespinal / getSeason
Created May 4, 2015 18:05
Current Weather Season Objective-C
+ (NSString *)season
{
// Months 12, 01, 02
NSString *currentSeason = @"Winter";
NSDate *date = [[self alloc] init];
NSUInteger month = [date month];
if (month >=3 && month <= 5) {
currentSeason = @"Spring";
@eddieespinal
eddieespinal / UINavigationBar appearance
Created May 1, 2015 15:26
UINavigationBar appearance
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
NSDictionary *attributes = @{ NSFontAttributeName: [UIFont fontWithName:@"Futura" size:18],
NSForegroundColorAttributeName: [UIColor whiteColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x1f8dd6)];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];