Skip to content

Instantly share code, notes, and snippets.

View haojianzong's full-sized avatar

jakehao haojianzong

View GitHub Profile
@haojianzong
haojianzong / DecimalTextFieldCoordinator.swift
Last active October 21, 2023 08:43
UITextField with groupingSeparator when inputting number, tested with localization support.
import Foundation
import UIKit
// Implements UITextFieldDelegate to support input features like showing thousand separator
// Useful for financial App currency number input, tested for multiple localizations, copy and paste numbers into the field.
// Usage:
//
// 1. Setup
// let textField = UITextField()
// let coordinator = DecimalTextFieldCoordinator(balanceTextField)
@haojianzong
haojianzong / gist:f93b635e521a1aa2344b07c8782b2df6
Created May 30, 2021 07:15
Convert iOS version string into number - Swift
// Why do you want a numeric version? Because number format is easier to use than string.
// For example, you may want to write a NSPredicate for Core Data fetch for different version:
// NSPredicate(format: "clientVersionNumber < %@", "2070500") // 2.7.5
// This gist assume the version digit is limitted to 4.
public static var versionString: String {
return (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "1.0"
}
// Only support 4 digits, invalid string will return 0, longer digits will be dropped
@haojianzong
haojianzong / LayoutUtility.swift
Last active April 9, 2022 09:46
A missing Auto Layout helper for UIKit
import Foundation
import UIKit
// A small utility for NSLayoutDimension shortcuts
public protocol PinObject {
var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var leadingAnchor: NSLayoutXAxisAnchor { get }
var trailingAnchor: NSLayoutXAxisAnchor { get }
@haojianzong
haojianzong / file_sizes_group_by_type
Created March 31, 2016 09:49
Bash sum file sizes in folder group by file type
#!/bin/bash
types=($(find . -type f -name '*.*' | sed 's|.*\.||' | sort -u))
IFS=$'\n';
for type in ${types[@]}; do
sum=$(find . -type f -name "*.$type" -exec du -ch {} + | grep total$)
echo "$type : $sum"
done
@haojianzong
haojianzong / svn-moves-with-synx.txt
Created February 29, 2016 03:41
Svn move bridge for synx
#!/bin/sh
# This script move files from an old directory into a new dirctory
# using the file hierarchy from a reference directory, while preserving svn
# log history.
# The purpose is to organize files in one place and do 'svn mv' after
# you have finished organizing. In this way you don't need to worry about other
# developers commiting files while you are moving files around.
@haojianzong
haojianzong / GIF-Screencast-OSX.md
Last active August 29, 2015 14:27 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@haojianzong
haojianzong / gist:35619027a1e60754cf99
Created May 17, 2015 03:51
A Category to Set LocalizedString for Xib Files in User Define Runtime Attributes
//
// UIView+JZLocalizedIB.m
//
// Created by haojianzong on 12/5/17.
//
// A Category to Set LocalizedString for Xib Files in User Define Runtime Attributes
#import <UIKit/UIKit.h>
#import "JZLocaleUtils.h"
@haojianzong
haojianzong / JZBrief
Created January 19, 2015 03:38
NSString routine that generates a fix length brief
static NSInteger mYStringlength = 60;
- (NSString *)brief:(NSString *)text
{
NSRange stringRange = {0, MIN([text length], mYStringlength)};
stringRange = [text rangeOfComposedCharacterSequencesForRange:stringRange];
NSString *shortBrief = [text substringWithRange:stringRange];
NSString *firstLine =[[self.text componentsSeparatedByString: @"\n"] objectAtIndex:0];
@haojianzong
haojianzong / gist:c7ab2b71a4f955b1bbdb
Created December 28, 2014 03:36
jQuery Auto Active Menu
// this function will active menu using href match
// Author: http://www.paulund.co.uk/use-jquery-to-highlight-active-menu-item
function auto_active_menu() {¬
var url = window.location.href;¬
// Work for relative and absolute hrefs¬
$('.menu a').filter(function() {
return this.href == url;¬
}).addClass('active');¬
}
//
// StickyHeaderFlowLayout.h
// Wombat
//
// Created by Todd Laney on 1/9/13.
// Copyright (c) 2013 ToddLa. All rights reserved.
//
// Modified from http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using THANKS!
//