Skip to content

Instantly share code, notes, and snippets.

View Gurpartap's full-sized avatar
:octocat:
Working from home

Gurpartap Singh Gurpartap

:octocat:
Working from home
View GitHub Profile
@Gurpartap
Gurpartap / select.playground
Created February 16, 2015 20:52
"select" non-nil elements.
// "select" non-nil elements.
var data: Array<String> = ["0", "a"]
var wrappedIntsWithOptionals = data.map { $0.toInt() } as Array<Int?>
println("wrappedIntsWithOptionals: \(wrappedIntsWithOptionals)")
// wrappedIntsWithOptionals: [Optional(0), nil]
// ## This works
@Gurpartap
Gurpartap / protocols.go
Last active August 29, 2015 14:27
Golang type interface implementation (protocol of Swift)
package main
import "fmt"
// protocol
type Specimen interface {
NumLegs() int
}
var Species = []Specimen{}
@Gurpartap
Gurpartap / items-for-sale.md
Last active September 17, 2015 07:13
Items for sale

Available:

  • Sony alpha NEX-5 14.2 MP Mirrorless Camera - Black — Kit w/ 16mm & 18-55mm Lenses, flash and spare battery (excellent working condition with some wear and tear)
  • PlayStation 3 God of War 3 Edition w/ GoW 3, Portal 2 and Red Dead Redemption (mint condition, only played RDR)
  • PSP (PlayStation Portable) — Silver w/ Hard casing, spare battery and games (Family Guy, God of War, Exterminator, etc.) (mint condition)
  • Creative Computer Speakers (basic speakers, never used)
  • Philips Computer Speakers (basic speakers, never used)
  • AudioEngine 5 Speakers w/ built-in amp (Studio Monitors) (needs repair for pops and crackles - common problem in this model)
  • 2007 PC w/ Q6600 2.4GHz, Asus P5K Deluxe Motherboard, AMD ATI 4800 512MB Graphics Card, 2GB GSkill RAM (needs repair; motherboard not posting - known problem with this MB model)
  • 2008 MacBook Pro 2.6GHz w/ spare MagSafe charger (needs new battery, keyboard up/down keys not responding)
@Gurpartap
Gurpartap / Godfather_.swift
Last active September 15, 2015 07:48 — forked from ivangodfather/gist:9f3ad527198ee513308e
For @Godfather_ on IRC
request(.GET, CUSTOMER_URL, parameters: params, encoding: .URL).responseJSON { (request, response, result) -> Void in
if let message = JSON(result.value ?? "")["message"].string ?? "Default value to make it nonOptional" {
switch(result) {
case .Success(let json):
if let customer = JSON(json)["customer"].dictionaryObject {
GlobalCache.sharedInstance.setCustomer(customer)
}
completion(succeed: response?.statusCode == 200, message: message)
case .Failure(_,_):
completion(succeed: false, message: message)
{
"data": {
"id": 14830193,
"type": "twitter_connection",
"attributes": {
"created_at": "2015-09-15T11:19:50.201187+05:30",
"updated_at": "2015-09-15T11:19:50.201187+05:30",
"screen_name": "Gurpartap"
}
}
@Gurpartap
Gurpartap / Podfile.rb
Last active December 11, 2015 09:26
gRPC issue #4350
source "https://github.com/CocoaPods/Specs.git"
platform :ios, "8.0"
use_frameworks!
inhibit_all_warnings!
pod "Protobuf", "~> 3.0.0-alpha-4.1"
pod "gRPC", git: "https://github.com/grpc/grpc"
pod "EchoSDK", path: "../proto"
@Gurpartap
Gurpartap / 1_playground.swift
Last active October 5, 2016 09:29
swift optionals in go? tcard/sgo#27
// 1. Like SGo
var regularVar: String
// This will _not compile_.
// print(regularVar)
// This will _not compile_.
// regularVar = nil
@Gurpartap
Gurpartap / maybe.go
Created October 9, 2016 14:29
Maybe Monad in Go
// https://play.golang.org/p/P5DDZrcXZB
package main
import "fmt"
type Monad interface {
Bind(func(interface{}, Monad) Monad) Monad
Return(interface{}) Monad
}
@Gurpartap
Gurpartap / authorize-api-request.go
Last active December 2, 2016 12:59
Authorize api request with api key and secret
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"net/http"
"time"
)