Skip to content

Instantly share code, notes, and snippets.

View JV17's full-sized avatar
๐Ÿ 
Working from home

Jorge JV17

๐Ÿ 
Working from home
View GitHub Profile
@JV17
JV17 / swift
Last active February 3, 2020 01:49
Calculating how many days it will take to update all the servers in the grid
// Find the lowest number of days that will require to update all the serves on the grid.
// Where every server with the value of 1 is updated and can update any other server that is above, below, next or previous.
// A server that requires an update is represented by 0 value and an updated server is represented by 1 value.
// Any server that needs to be updated will take 1 day to update.
// sameple grid -- result should be 3
let grid: [[Int]] = [[0, 1, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 1],
[1, 0, 1, 1],
@JV17
JV17 / gist:1c876ae0b3063fdd356a
Last active August 29, 2015 14:22
Check for stored cookies
NSLog(@"\n\n***************\n\n");
// creating and accessing stored cookies
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
// looping over all stored cookies & printing the relevant content
for (cookie in [cookieJar cookies]) {
NSLog(@"\n\n%@", cookie);
NSLog(@"name: %@", cookie.name);
@JV17
JV17 / gist:204ebda13ff2ee4070af
Last active August 29, 2015 14:20
getting date from string
func getTimeFromString(timeStr: String, timeZoneStr: String) -> String {
if(!timeStr.isEmpty && !timeZoneStr.isEmpty) {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "EEE, d MMM yyyy HH:mm:ss Z"
dateFormatter.timeZone = NSTimeZone(name: timeZoneStr)
let date: NSDate = dateFormatter.dateFromString(timeStr)!
let formatter = NSDateFormatter()
formatter.timeStyle = .ShortStyle
@JV17
JV17 / gist:481782f6807fc4acdac4
Last active August 29, 2015 14:18
Find first unique number in a list (NSArray) - Objective-C
- (NSNumber *)firstUniqueNumberFromArray:(NSArray *)array
{
// if there is no list we return nil
if(!array || array.count == 0)
return nil;
NSNumber *number;
// if there is 1 number in the list or is there 2 numbers and they are not equal then we return the first number from the list
if(array.count == 1 || (array.count == 2 && [[array objectAtIndex:0] longValue] != [[array objectAtIndex:1] longValue]))
@JV17
JV17 / gist:fe8bbff56868acdb5f68
Created April 2, 2015 15:10
Merge sort in Objective-C
#pragma mark - Merge Sort
- (NSMutableArray *)mergeSorting:(NSMutableArray *)array
{
if(array.count == 1 || !array)
return array;
NSMutableArray *firstHalfArr = [self splitFirstHalfOfArray:array];
NSMutableArray *secondHalfArr = [self splitSecondHalfOfArra:array];
firstHalfArr = [self mergeSorting:firstHalfArr];
@JV17
JV17 / gist:cd7e9c9f308485b5850a
Last active August 29, 2015 14:17
quicksort in objective-c
// quicksort implementation
- (NSMutableArray *)quickSorting:(NSMutableArray *)array withLow:(int)low andHigh:(int)high
{
if(array)
{
if(low < high)
{
int pivot_location = [self partitionArray:array withLow:low andHigh:high];
[self quickSorting:array withLow:low andHigh:(pivot_location)];
[self quickSorting:array withLow:(pivot_location + 1) andHigh:high];
@JV17
JV17 / gist:60c830042a8a01927353
Last active August 29, 2015 14:17
Find the number that occurs once in an array or list in Objective-C
/*
* Helper function to find the number that only occurs once in our list
* @param, receives a list as a NSArray
* @return, returns the number that occours once in the array
*/
- (NSNumber *)firstUniqueNumberFromArray:(NSArray *)array
{
// first we need to declare our return type.
NSNumber *onceNum;
@JV17
JV17 / gist:13fc863104605f3e519d
Last active August 29, 2015 14:17
a templated sorted array of single link lists
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int const SIZE = 5;
@JV17
JV17 / gist:5eb71eb39c14ce08f528
Last active August 29, 2015 14:17
a sorted array of single link lists
#include <iostream>
#include <algorithm>
using namespace std;
const int SIZE = 5;
class Node {
int _data;
Node *_next;
@JV17
JV17 / gist:cad0c524c2a868e195d3
Last active August 29, 2015 14:17
An Unsorted and Sorted Array of Lists
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
const int SIZE = 5;
int main(int argc, const char * argv[]) {
// insert code here...