Skip to content

Instantly share code, notes, and snippets.

@commanda
commanda / traverse.js
Created July 27, 2016 15:49
traverse a json-ish structure in javascript
function traverse(object, block)
{
for(var i in object)
{
block(typeof(object[i]) !== "object", i, object[i]);
if(object[i] !== null && typeof(object[i]) !== "string")
{
traverse(object[i], block);
}
}
@commanda
commanda / Traverse.m
Created July 27, 2016 15:51
traverse a json-ish structure in objective-c (and delete certain elements from it)
+ (BOOL)traverse:(NSObject *)obj comparisonBlock:(BOOL (^)(NSString *, NSObject *))comparisonBlock;
{
if([obj isKindOfClass:[NSMutableArray class]])
{
NSMutableArray *array = (NSMutableArray *)obj;
NSMutableArray *toDelete = [@[] mutableCopy];
for(NSObject *element in array)
{
@commanda
commanda / promises_reduce.js
Last active September 6, 2016 21:50 — forked from anvk/promises_reduce.js
Sequential execution of Promises using reduce()
function createPromiseForFunction(e, functionThatTakesOneItem)
{
return new Promise((resolve, reject) => {
resolve(functionThatTakesOneItem(e));
});
}

Keybase proof

I hereby claim:

  • I am commanda on github.
  • I am commanda (https://keybase.io/commanda) on keybase.
  • I have a public key whose fingerprint is 74DB ACD4 CD18 915F E6E2 7C50 4E57 2F26 885B CA13

To claim this, I am signing this object:

@commanda
commanda / UIView+AllSubviews.swift
Created December 20, 2018 20:55
get all subviews of a UIView, recursively
extension UIView {
var allSubviews: [UIView] {
return self.subviews.reduce(into: [self]) { array, subview in
array += subview.allSubviews
}
}
}
extension String {
var isHexColorString: Bool {
do {
let regex = try NSRegularExpression(pattern: "^#?[0-9A-Fa-f]{6}$")
return regex.matches(in: self, options: [], range: wholeRange).isEmpty == false
} catch {
return false
}
}
}