Skip to content

Instantly share code, notes, and snippets.

View jdev7's full-sized avatar

Juan Navas jdev7

View GitHub Profile
@sushihangover
sushihangover / TidyJson.py
Created May 8, 2016 18:13
TextWranger Format Filter for Json (~/Library/Application Support/TextWrangler/Text Filters)
#!/usr/bin/python
import fileinput
import json
if __name__ == "__main__":
jsonStr = ''
for aline in fileinput.input():
jsonStr = jsonStr + ' ' + aline.strip()
jsonObj = json.loads(jsonStr)
@ericdke
ericdke / splitBy.swift
Last active July 10, 2023 09:55
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return 0.stride(to: self.count, by: subSize).map { startIndex in
let endIndex = startIndex.advancedBy(subSize, limit: self.count)
return Array(self[startIndex ..< endIndex])
}
}
}