Skip to content

Instantly share code, notes, and snippets.

# 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
@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)
//
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 / 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"); }
@eJamesLin
eJamesLin / CoreDataMagicalRecordDemo.m
Last active April 12, 2017 05:47
CoreData MagicalRecord Demo
#import "ViewController.h"
#import <MagicalRecord/MagicalRecord.h>
#import "Artist+CoreDataClass.h"
@interface ViewController ()
@end
@implementation ViewController
//
// ViewController.m
// RunLoop
//
// Created by cj on 2017/4/26.
// Copyright © 2017年 cj. All rights reserved.
//
#import "ViewController.h"
#import <AFNetworking/AFNetworking.h>
import UIKit
class ClosureButton: UIButton {
var actionClosure: (() -> Void)?
@objc func closureAction() {
actionClosure?()
}
func addClosure(for controlEvents: UIControlEvents, closure: (() -> Void)) {
// Xcode 10.2 to Xcode 11 Beta
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
@eJamesLin
eJamesLin / getpr.sh
Created February 21, 2020 11:38
Get remote PR
#!/bin/sh
branch="pull/$1/head:pr/$1"
echo $branch
local_branch="pr/$1"
echo $local_branch
git fetch upstream $branch
git checkout $local_branch