Skip to content

Instantly share code, notes, and snippets.

View Dashing-Daniel-Li's full-sized avatar

Daniel Li Dashing-Daniel-Li

View GitHub Profile
@lesleh
lesleh / chunkArray.java
Last active March 10, 2024 20:16
Java function to split an array into chunks of equal size. The last chunk may be smaller than the rest.
// Example usage:
//
// int[] numbers = {1, 2, 3, 4, 5, 6, 7};
// int[][] chunks = chunkArray(numbers, 3);
//
// chunks now contains [
// [1, 2, 3],
// [4, 5, 6],
// [7]
// ]
anonymous
anonymous / UIColor+Helper.swift
Created September 13, 2015 14:04
UIColor from Hex String in Swift
import UIKit
extension UIColor {
convenience init(hex: String, alpha: CGFloat = 1) {
assert(hex[hex.startIndex] == "#", "Expected hex string of format #RRGGBB")
let scanner = NSScanner(string: hex)
scanner.scanLocation = 1 // skip #
var rgb: UInt32 = 0