Skip to content

Instantly share code, notes, and snippets.

View software-mariodiana's full-sized avatar

Mario Diana software-mariodiana

View GitHub Profile
@software-mariodiana
software-mariodiana / AsyncFileLoad.m
Last active December 20, 2015 06:19
Loading a file asynchronously to use as the data source for a UITableView.
// Let's not block while loading data from a file
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *path = [[NSBundle mainBundle] pathForResource:@"word_list" ofType:@"txt"];
NSError *error;
NSString *contents =
[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
self.tableData = [contents componentsSeparatedByString:@"\n"];
@software-mariodiana
software-mariodiana / PredicateRegexExample.m
Last active December 20, 2015 07:19
Cocoa's regular expressions are a little gnarly to use, and using an NSPredicate instead can make things easier. Here, given a list of (lowercase) words, we want to filter an array to return a new array that comprises only words beginning with a particular letter. We specify a regular expression, but we let NSPredicate take care of all the plumb…
// Assume all the words in the list are lowercase
- (NSArray *)filterListOfWords:(NSArray *)words byFirstLetter:(NSString *)aLetter
{
// Use NSPredicate to filter the words in the list
NSString *regex = [NSString stringWithFormat:@"^%@.*$", [aLetter lowercaseString]];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
NSArray *list = [words filteredArrayUsingPredicate:filter];
@software-mariodiana
software-mariodiana / Folder iteration (VBScript)
Last active December 21, 2015 09:29
Iterate through files in a folder and get the modification time for each INI file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFolder = fso.GetFolder("C:\Windows")
Wscript.Echo "Directory:" & vbNewLine & theFolder.Path
Set theFiles = theFolder.Files
For Each aFile in theFiles
' Note: You have to use the File System Object!
If UCase(fso.GetExtensionName(aFile.Name)) = "INI" Then
@software-mariodiana
software-mariodiana / CustomRoundRectButton.m
Last active December 24, 2015 13:09
How to create a bordered button in iOS 7 (similar to Apple's round rectangular buttons in iOS 7 apps).
/*
* MyCustomRoundRectButton.h
*/
#import <UIKit/UIKit.h>
@interface MyCustomRoundRectButton : UIButton
@end
@software-mariodiana
software-mariodiana / LocationInIOS7.m
Last active August 7, 2017 11:06
Reworking CoreLocation methods deprecated in iOS 7.
/*
* Several methods from CoreLocation were deprecated in iOS 7. Some were replaced
* by methods in other classes. Here are some very bare notes describing how to
* circumscribe a region and then use that region to do geofencing.
*/
static NSString *ExeterAppleStoreRegion = @"XYZMyAppExeterAppleStoreRegion";
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(50.72451, -3.52788);
CLLocationDistance radius = 30.0;
@software-mariodiana
software-mariodiana / POSLoggingOff.vb
Last active December 28, 2015 06:19
Turn off POS logging in RetailStore.
Imports System.Xml
Sub TurnOffPOSLoggingInFile(posConfigFilePath As String)
Dim doc As New XmlDocument()
doc.Load(posConfigFilePath)
' We want the "Add" nodes, which are the only child nodes at the end of this path
Dim posConfigurationNodes As XmlNodeList = doc.Item("configuration").Item("system.diagnostics").Item("switches").ChildNodes
@software-mariodiana
software-mariodiana / BottleRocket.py
Created June 4, 2014 18:21
A hello world example for using Bottle with Rocket.
from rocket import Rocket
from bottle import Bottle
from bottle import route
app = Bottle(__name__)
app.debug = True
@software-mariodiana
software-mariodiana / 0_reuse_code.js
Created June 5, 2014 16:13
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
@software-mariodiana
software-mariodiana / AsyncPlistLoad.m
Last active August 29, 2015 14:02
Instantiating an array by loading a plist file asynchronously, and using a block to notify the associated UITableView to reload its data.
/*
* Assume the following:
*
* - The Plist file is called: Names.plist
* - @property NSArray *tableData
* - Callback block messages UITableView with reloadData
*/
- (void)initizeDataWithTableViewCallback:(void(^)(void))reloadDataMessage
{
@software-mariodiana
software-mariodiana / UsingUILocalizedIndexCollation.m
Created June 7, 2014 19:08
How to use a UILocalizedIndexCollation to create a table with sections.
/*
* Assume the following:
*
* @property UILocalizedIndexCollation *collation;
* @property NSMutableArray *sections;
* @property NSArray *tableData;
*/
- (void)configureSectionData
{