Skip to content

Instantly share code, notes, and snippets.

View yasirmturk's full-sized avatar
💻
the smart engineer

Yasir Türk yasirmturk

💻
the smart engineer
View GitHub Profile
@yasirmturk
yasirmturk / UIStackView+RemoveAll.swift
Created April 15, 2020 07:49
Remove all arranged subviews from UIStackView properly
import UIKit
extension UIStackView {
@discardableResult
func removeAllArrangedSubviews() -> [UIView] {
return arrangedSubviews.reduce([UIView]()) { $0 + [removeArrangedSubViewProperly($1)] }
}
func removeArrangedSubViewProperly(_ view: UIView) -> UIView {
removeArrangedSubview(view)
@lienista
lienista / practice-precendence-rule.js
Created October 23, 2018 02:11
(Algorithms in Javascript) Practice. A precedence rule is given as "P>E", which means that letter "P" is followed by letter "E". Write a function, given an array of precedence rules, that finds the word represented by the given rules. Note: Each represented word contains a set of unique characters, i.e. the word does not contain duplicate letters.
/*
we create 2 separate arrays of letters and count
the number of characters resulting from the
original precedence array.
we look up the index of each letter from first letter
array and follow the index of the next letter.
*/
function findWord(a){
console.log(a);
@maciekish
maciekish / UINavigationBar+CustomHeight.h
Created September 10, 2014 08:48
Custom UINavigationBar height working in iOS 7 and 8. To use, find your navigation bar reference and just setHeight:200 etc.
//
// UINavigationBar+CustomHeight.h
//
// Copyright (c) 2014 Maciej Swic
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@nicklockwood
nicklockwood / ARCHelper.h
Last active November 20, 2018 10:02
ARC Helper
//
// ARC Helper
//
// Version 2.2
//
// Created by Nick Lockwood on 05/01/2012.
// Copyright 2012 Charcoal Design
//
// Distributed under the permissive zlib license
// Get the latest version from here:
@yasirmturk
yasirmturk / gist:1408352
Created November 30, 2011 07:40
A generic core data function to save and commit our changes to DB
/*
* We can fetch a record, modify it and then call this save function to save our changes
*/
- (BOOL)saveToDb{
NSError *error = nil;
BOOL returnVal = ( [[self managedObjectContext] save:&error] );
if(error != nil)
NSLog(@"%@", error);
return returnVal;
}
@yasirmturk
yasirmturk / gist:1408350
Created November 30, 2011 07:39
A generic core data function to Get all records
/*
* Get all records
*/
-(NSArray*)getAllRecordsFromEntity:(NSString *)entity{
NSArray *arr = [self queryDBForEntity:entity predicate:nil sortByField:nil];
//NSLog(@"%@", arr);
return arr;
}
@yasirmturk
yasirmturk / gist:1408349
Created November 30, 2011 07:38
A generic core data function to Get a record based on the criteria
/*
* Get a record based on the criteria
*/
- (id)getRecordFromEntity:(NSString *)entity whereField:(NSString *)fieldName isEqualTo:(id)val
{
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %@)", fieldName, val];
//NSLog(@"(P: %@)", [pred predicateFormat]);
NSArray *arr = [self queryDBForEntity:entity predicate:pred sortByField:fieldName];
//NSLog(@"%@", arr);
if ([arr count] > 0)
@yasirmturk
yasirmturk / gist:1408346
Created November 30, 2011 07:37
A generic core data function to check whether a record already exists
/*
* Useful function to check whether a record already exists
*/
-(BOOL)doesRecordExistForEntity:(NSString *)entity fieldToCheck:(NSString *)fieldName valueToMatch:(id)val
{
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %@)", fieldName, val];
//NSLog(@"(P: %@)", [pred predicateFormat]);
NSArray *arr = [self queryDBForEntity:entity predicate:pred sortByField:fieldName];
//NSLog(@"%@", arr);
return ([arr count] > 0);
@yasirmturk
yasirmturk / gist:1408341
Created November 30, 2011 07:33
A generic core data function that deletes a given entity
/*
* Given an object delete it
*
* @param obj: obj to delete from database
* @returns: true if successful in deleting else returns false
*/
- (BOOL)deleteObject:(id)obj{
NSError *error;
if(obj != nil){
[[self managedObjectContext] deleteObject:obj];
@yasirmturk
yasirmturk / gist:1408338
Created November 30, 2011 07:31
A generic core data function that inserts a new row for the given entity & fill that row with given key/values
/*
* A generic function that inserts a new row for the given entity and fill that row with given key/values
*/
-(void)insertObjectForEntity:(NSString *)entityName objectsToInsert:(NSDictionary *)dictObjects
{
NSError *error;
NSManagedObject *objToInsert = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:[self managedObjectContext]];
for (id key in [dictObjects allKeys]) {
[objToInsert setValue:key forKey:[dictObjects objectForKey:key]];