Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# You need stereovision package to run this. Try "sudo pip install stereovision"
import cv2
from stereovision.blockmatchers import StereoBM, StereoSGBM
from stereovision.calibration import StereoCalibration
from stereovision.stereo_cameras import CalibratedPair
from stereovision.ui_utils import STEREO_BM_FLAG, BMTuner
@nileshtrivedi
nileshtrivedi / deploy.rb
Last active January 16, 2016 21:01
Deploy a Play framework app with SSHKit
require 'sshkit'
require 'sshkit/dsl'
# Once "bundle install" has been run, this script can be run as "ruby deploy.rb staging" or "ruby deploy.rb prod"
if ARGV.first == "prod"
servers = ['deploy@prod1.example.com', 'deploy@prod2.example.com']
elsif ARGV.first == "staging"
servers = ['deploy@staging.example.com']
else
Verifying my Blockstack ID is secured with the address 15e4krfMSXCgWrRpo2FnVRy7DLQ7HuMBQm https://explorer.blockstack.org/address/15e4krfMSXCgWrRpo2FnVRy7DLQ7HuMBQm
@nileshtrivedi
nileshtrivedi / ed25519.sql
Last active February 3, 2023 08:59
ed25519 digital signature methods in PostgreSQL via PL/Python
CREATE EXTENSION IF NOT EXISTS plpythonu;
CREATE FUNCTION py_create_ed25519_keypair ()
RETURNS varchar[]
AS $$
import axolotl_curve25519 as curve
import os
import base64
randm32 = os.urandom(32)
@nileshtrivedi
nileshtrivedi / sm.rb
Created February 2, 2018 06:22
Multiplication of two state machines
a = {a: [:b, :c], b: [:c]}
def get_edges(sm)
res = []
sm.each do |s, e|
e.each do |d|
res.push([s,d])
end
end
res
@nileshtrivedi
nileshtrivedi / programming.md
Last active December 8, 2020 08:25
Programming: Mostly A Hate Story

Programming: Mostly A Hate Story

I wanted to do digital signatures validation, preferably ed25519, inside PostgreSQL triggers. Here is how it went:

Surely pgcrypto must be supporting it, right? Most Postgres cloud hosting providers already support pgcrypto so this would be perfect. Right?

Well, pgcrypto only supports PGP and that too excludes digital signatures. Let's give PGP a try anyway and see how far can we go.

Installed gpg to generate the keys and the experience is less than pleasant. Sometimes it gets stuck at the passphrase prompt. The keys are too big, but still I can make pgcrypto's pgp_pub_encrypt and pgp_pub_decrypt methods work. Just remeber to convert keys in ASCII to binary and vice-versa using armor()/dearmor(). I hate the big key size in RSA, even though GPG defaults to 2048-bit keys and not the more secure 4096-bit ones. Let's look into ed25519 now.

Keybase proof

I hereby claim:

  • I am nileshtrivedi on github.
  • I am nileshtrivedi (https://keybase.io/nileshtrivedi) on keybase.
  • I have a public key ASDS2qJDEl9_uy-LwMNZItAdCCU9ct2v6V57tlhS80cErgo

To claim this, I am signing this object:

@nileshtrivedi
nileshtrivedi / txn.sql
Created March 16, 2018 09:26
Transaction validation in database with Python (INCOMPLETE)
CREATE EXTENSION IF NOT EXISTS plpythonu;
-- plpython is untrusted. Access needs to be controlled carefully
CREATE OR REPLACE FUNCTION py_test () RETURNS varchar AS $$
return 'hi'
$$ LANGUAGE plpythonu;
CREATE OR REPLACE FUNCTION py_create_ed25519_keypair ()
RETURNS varchar[]
@nileshtrivedi
nileshtrivedi / sample.py
Created June 18, 2018 06:22
Cloud Firestore - Python example
# This script can be used standalone
# So it doesn't depend on filesystem or Google Cloud for the credentials
from google.cloud import firestore
from google.oauth2 import service_account
key = 'your_credentials_json_string'
info = json.loads(key)
creds = service_account.Credentials.from_service_account_info(info)
@nileshtrivedi
nileshtrivedi / MainActivity.java
Last active January 8, 2019 12:05
HyperTrack Onboarding
HyperTrackCore.requestLocationPermissions(this, new LocationPermissionCallback() {
@Override
public void onLocationPermissionGranted() {
// Handle location permission granted
}
@Override
public void onLocationPermissionDenied() {
// Handle location permission denied
}