Skip to content

Instantly share code, notes, and snippets.

@eJamesLin
eJamesLin / NSStringRange.m
Last active November 8, 2016 17:18
Ways to get substring, and characterAtIndex as unichar
NSString *str = @"abca";
NSLog(@"%@", [str substringWithRange:NSMakeRange(0, 1)]); // "a"
NSLog(@"%@", [str substringWithRange:NSMakeRange(0, 3)]); // "abc"
NSLog(@"%@", [str substringWithRange:NSMakeRange(0, 4)]); // "abca"
unichar a = [str characterAtIndex:0];
unichar a3 = [str characterAtIndex:3];
NSLog(@"%C", a);
if (a == a3) { NSLog(@"equal"); }
//
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:1];
array[0] = @"0";
array[1] = @"1"; // won't crash... but not good
// C array, cannot be used as property
NSInteger matrix[3][3];
matrix[0][0] = 10;
NSLog(@"%s %@", __PRETTY_FUNCTION__, array);
NSLog(@"%s %ld", __PRETTY_FUNCTION__, matrix[0][0]); //10
@eJamesLin
eJamesLin / StringExtension.swift
Last active November 8, 2016 08:34
randomAccessCharactersArray of swift strings
extension String {
/*
Ref: http://oleb.net/blog/2014/07/swift-strings/
"Because of the way Swift strings are stored, the String type does not support random access to its Characters via an integer index — there is no direct equivalent to NSStringʼs characterAtIndex: method. Conceptually, a String can be seen as a doubly linked list of characters rather than an array."
By creating and storing a seperate array of the same sequence of characters,
we could hopefully achieve amortized O(1) time for random access.
*/
func randomAccessCharactersArray() -> [Character] {
return Array(self.characters)
# Version: 1.3
# Author: pantuts
# Description: Parse URLs in Youtube User's Playlist (Video Playlist not Favorites)
# Use python3 and later
# Agreement: You can use, modify, or redistribute this tool under
# the terms of GNU General Public License (GPLv3).
# This tool is for educational purposes only. Any damage you make will not affect the author.
# Usage: python3 youParse.py youtubeURLhere
import re