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 / cursored_resp.go
Created September 9, 2018 06:31
#golang jsonparser with twitter api responses
package twitter_api
import (
"fmt"
"strconv"
"github.com/buger/jsonparser"
)
/*
@Gurpartap
Gurpartap / ExampleClient.swift
Last active August 27, 2018 14:19
gRPC Status Details (custom error data) with Swift (grpc-objc)
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 August 1, 2018 07:28
diesel example w/ r2d2 pool
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 February 19, 2018 12:56
rx_autoUpdater for ObservableArray-RxSwift
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)
}
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 October 28, 2017 10:53
Proof of port 22 blocked by BSNL
# 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 March 24, 2017 02:33
select x where latest y of x is z
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 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"
)
@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 / 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