Skip to content

Instantly share code, notes, and snippets.

Gurpartap Singh Gurpartap

Block or report user

Report or block Gurpartap

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Gurpartap
Gurpartap / one-way-hashing-function.swift
Created Apr 28, 2019
Swift port of Apple's one-way hashing function for setting SKMutablePayment's applicationUsername
View one-way-hashing-function.swift
// Objective-C version available here:
// https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/RequestPayment.html#//apple_ref/doc/uid/TP40008267-CH4-SW6
// Usage:
//
// let userID = "146001"
// print(hashedValueForAccountName(userID))
//
// Output:
//
@Gurpartap
Gurpartap / cursored_resp.go
Created Sep 9, 2018
#golang jsonparser with twitter api responses
View cursored_resp.go
package twitter_api
import (
"fmt"
"strconv"
"github.com/buger/jsonparser"
)
/*
@Gurpartap
Gurpartap / ExampleClient.swift
Last active Aug 27, 2018
gRPC Status Details (custom error data) with Swift (grpc-objc)
View ExampleClient.swift
func ping() {
let req = PingRequest()
ExampleService.ping(with: req) { (response, error) in
if let error = error {
var title = "Unknown error"
var message = error.localizedDescription
for detail in try! RPCStatus.from(error)?.details ?? [] {
switch detail {
@Gurpartap
Gurpartap / database.rs
Last active Aug 1, 2018
diesel example w/ r2d2 pool
View database.rs
use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::result::Error as DieselError;
use models::User;
use schema::users;
pub fn establish_connection(database_url: String) -> Pool<ConnectionManager<PgConnection>> {
let manager = ConnectionManager::<PgConnection>::new(database_url);
Pool::builder()
.max_size(5)
@Gurpartap
Gurpartap / UITableView+ObservableArray_RxSwift.swift
Last active Feb 19, 2018
rx_autoUpdater for ObservableArray-RxSwift
View UITableView+ObservableArray_RxSwift.swift
import UIKit
import RxSwift
import ObservableArray_RxSwift
extension UITableView {
public func rx_autoUpdater(source: Observable<ArrayChangeEvent>) -> Disposable {
return source
.scan((0, nil)) { (a: (Int, ArrayChangeEvent?), ev) in
(a.0 + ev.insertedIndices.count - ev.deletedIndices.count, ev)
}
View lock_operation.sql
SELECT
operation.*
FROM
operations operation
LEFT JOIN LATERAL (
SELECT
_r.state
FROM
operations_results _r
WHERE
@Gurpartap
Gurpartap / 1-port-22-bsnl.sh
Last active Oct 28, 2017
Proof of port 22 blocked by BSNL
View 1-port-22-bsnl.sh
# With BSNL Broadband (8Mbps 2841 plan), outgoing connections on
# *port 22* (ssh) consistently time out. This happens on all servers,
# not necessarily github.com.
$ telnet github.com 22
Trying 192.30.255.112...
telnet: connect to address 192.30.255.112: Operation timed out
Trying 192.30.255.113...
telnet: connect to address 192.30.255.113: Operation timed out
telnet: Unable to connect to remote host
@Gurpartap
Gurpartap / 1_schema.sql
Last active Mar 24, 2017
select x where latest y of x is z
View 1_schema.sql
create table tasks (
id serial primary key,
name text not null
);
create table results (
id serial primary key,
created_at timestamptz default now() not null,
state text default null,
task_id int references tasks(id)
@Gurpartap
Gurpartap / authorize-api-request.go
Last active Dec 2, 2016
Authorize api request with api key and secret
View authorize-api-request.go
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"net/http"
"time"
)
@Gurpartap
Gurpartap / maybe.go
Created Oct 9, 2016
Maybe Monad in Go
View maybe.go
// https://play.golang.org/p/P5DDZrcXZB
package main
import "fmt"
type Monad interface {
Bind(func(interface{}, Monad) Monad) Monad
Return(interface{}) Monad
}
You can’t perform that action at this time.