Skip to content

Instantly share code, notes, and snippets.


Andrew Barba AndrewBarba

View GitHub Profile
AndrewBarba / AsyncMap.swift
Created Jun 20, 2021
Concurrent async version of map on any Sequence
View AsyncMap.swift
extension Sequence {
func mapAsync<T>(_ handler: @escaping (Element) async -> T) async -> [T] {
return await withTaskGroup(of: (Int, T).self) { group in
var results: [Int: T] = [:]
for (index, item) in self.enumerated() {
group.async { (index, await handler(item)) }
for await (index, transformed) in group {
results[index] = transformed
AndrewBarba / EpsonDeviceNameToSeries.swift
Created May 25, 2017
Convert Epson printer device name to series enum
View EpsonDeviceNameToSeries.swift
func printerSeries(for name: String) -> Int32 {
switch name.uppercased() {
case "TM-M10":
return EPOS2_TM_M10.rawValue
case "TM-M30":
return EPOS2_TM_M30.rawValue
case "TM-P20":
return EPOS2_TM_P20.rawValue
case "TM-P60":
return EPOS2_TM_P60.rawValue
AndrewBarba / cs6740-space-boilerplate.js
Last active Feb 11, 2016
A boilerplate for the cs6740 space colonization problem written in Javascript. Abstracts away parsing and organizing the data so you can focus on the algorithm needed to solve the challenge.
View cs6740-space-boilerplate.js
'use strict';
* Returns the cheapest way to colonize the given species
* The first argument is an Array of species, and the second argument
* is an array of discounts.
* A single species in the array, accesed like species[0], has 2 properties:
* - cost: Int - the cost to bring 1 of these species without a discount
* - needToBring: Int - the number of species I need to bring
View Dispatch.swift
// Dispatch.swift
// Created by Andrew Barba on 8/25/15.
import Foundation
public struct Dispatch {
AndrewBarba / make-xcode-fast
Created Apr 14, 2015
Make Xcode (with Cocoapods) faster by cleaning Pods, workspaces, and derived data folders
View make-xcode-fast
rm -rf Pods
rm -rf *.lock
rm -rf *.xcworkspace
rm -rf ~/Library/Caches/*
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod install
AndrewBarba / UIColorMake
Last active Aug 29, 2015
Objective-C macro for easily creating UIColor instances with RGB values between 0 and 255
View UIColorMake
* Example: UIColor *teal = UIColorMake(9.0, 171.0, 161.0, 1.0)
__UIColorMake(CGFloat r, CGFloat g, CGFloat b, CGFloat a)
return [UIColor colorWithRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:a];
#define UIColorMake __UIColorMake
View Formatted Phone Number String
* @updated: 2014-07-29
* @source:
static NSCharacterSet* set = nil;
set = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
View jQuery TouchClick
/*** ANDREW BARBA ***/
/**** April 2013 ****/
// A replacement for jQuery's .click() event that
// automatically supports taps on mobile devices
// and clicks on desktops
jQuery.fn.touchClick = function(fnc)