Skip to content

Instantly share code, notes, and snippets.

View bhargavg's full-sized avatar

Bhargav Gurlanka bhargavg

View GitHub Profile
@bhargavg
bhargavg / LaunchProcessArgs.swift
Last active April 21, 2022 17:51
An interactive process
import Foundation
struct LaunchProcessArgs: OptionSet {
let rawValue: Int
static let attachStdIn = LaunchProcessArgs(rawValue: 1 << 0)
static let attachStdOut = LaunchProcessArgs(rawValue: 1 << 1)
static let attachStdErr = LaunchProcessArgs(rawValue: 1 << 2)
static let interactive: LaunchProcessArgs = [.attachStdIn, .attachStdOut, .attachStdErr]
(* Problem: Write a function that returns true
* when invoked with list of alternate 1's and 2's
*
* Example:
* matcher [1,2,1,2]
* matcher [1,2,1]
* matcher [1,2]
* matcher [1]
*
* all of the above should return true
@bhargavg
bhargavg / main.swift
Created September 25, 2016 07:08
Functional Integer List in Swift - Inspired by Programming Languages Lecture by Dan Grossman (Coursera)
indirect enum IntList {
case empty
case cons(Int, IntList)
}
extension IntList {
static func append(_ xs: IntList, _ ys: IntList) -> IntList{
switch xs {
case .empty: return ys;
case let .cons(head, tail): return .cons(head, append(tail, ys));
#!/bin/bash
#
# Faster toolchain build: skips as much as possible.
#
# To use this toolchain from the command line:"
# export TOOLCHAINS=$(whoami)
#
# we build to the same prefix every time (instead of building
# to a versioned prefix) because every time the prefix changes
# *everything* rebuilds.
_ _
| |__ | |__ __ _ _ __ __ _ __ ___ ____ _
| '_ \| '_ \ / _` | '__/ _` |/ _` \ \ / / _` |
| |_) | | | | (_| | | | (_| | (_| |\ V / (_| |
|_.__/|_| |_|\__,_|_| \__, |\__,_| \_/ \__, |
|___/ |___/
Just a dummy text file to have a proper titles for gists 😒
_ _
| |__ | |__ __ _ _ __ __ _ __ ___ ____ _
| '_ \| '_ \ / _` | '__/ _` |/ _` \ \ / / _` |
| |_) | | | | (_| | | | (_| | (_| |\ V / (_| |
|_.__/|_| |_|\__,_|_| \__, |\__,_| \_/ \__, |
|___/ |___/
Just a dummy text file to have a proper titles for gists 😒
_ _
| |__ | |__ __ _ _ __ __ _ __ ___ ____ _
| '_ \| '_ \ / _` | '__/ _` |/ _` \ \ / / _` |
| |_) | | | | (_| | | | (_| | (_| |\ V / (_| |
|_.__/|_| |_|\__,_|_| \__, |\__,_| \_/ \__, |
|___/ |___/
Just a dummy text file to have a proper titles for gists 😒
[
{
"name": {
"first_name": "Lex",
"last_name": "Luthor"
},
"age": 28,
"gender": "male",
"address": {
"street": "244 Clifton Place",
func makePerson(name: String) -> (age: Int) -> (status: MaritalStatus) -> (requestIDs: [Int]) -> (address: Address) -> Person {
return { age in { status in { requestIDs in { address in
Person(name: name, age: age, status: status, requestIDs: requestIDs, address: address)
}}}}
}
func makeAddress(flatNo: String) -> (buildingName: String) -> Address {
return { buildingName in
Address(flatNo: flatNo, buildingName: buildingName)
}
#!/bin/bash
#
# _ _
# | |__ | |__ __ _ _ __ __ _ __ ___ ____ _
# | '_ \| '_ \ / _` | '__/ _` |/ _` \ \ / / _` |
# | |_) | | | | (_| | | | (_| | (_| |\ V / (_| |
# |_.__/|_| |_|\__,_|_| \__, |\__,_| \_/ \__, |
# |___/ |___/
#
# title : script.sh