Skip to content

Instantly share code, notes, and snippets.

View hrj's full-sized avatar
🔭
observing

hrj hrj

🔭
observing
View GitHub Profile
@hrj
hrj / checkGet.jshell
Created June 9, 2020 03:49
Simple script to check java http client
import java.net.http.*
var targetPath = "https://duckduckgo.com/html"
var r = HttpRequest.newBuilder().uri(URI.create(targetPath)).build()
var hc = HttpClient.newHttpClient()
System.out.println("Sending request: " + r)
var resp = hc.send(r, HttpResponse.BodyHandlers.discarding())
@hrj
hrj / test.py
Created January 21, 2020 08:46
matrix test script
from matrix_client.api import MatrixHttpApi
matrix = MatrixHttpApi("http://localhost:8888")
room = matrix.create_room(alias="!abc")
event1 = matrix.send_message("!abc", "hello")
event2 = matrix.send_message("!abc","world")
all_event = matrix.get_room_messages("!abc","cv","f")
@hrj
hrj / gist:6864fe28cda172f865bb715c594fddaa
Last active January 6, 2019 07:12
Good Practices in Programming

Here's a distilled set of programming guidelines which I have learnt myself and suggested to others, over the course of 20 years.

Meta guideline : Readability

The main focus of these guidelines is to enhance readability. Sometimes, better readability might affect performance of the code for better / worse. In such cases, my suggestion is to compromise readibility only in the critical sections of the code.

Move specific state to the smallest scope possible

The evils of globally scoped state (variables) have been well documented. This is an inductive extension of the same argument.

By limiting the scope of state we make it easier to read / analyse the system.

@hrj
hrj / jlhttp.scala
Created October 24, 2018 07:15
sample jl http server
import net.freeutils.httpserver._
object LCFramework{
def main(args: scala.Array[String]) {
val port = 8888
val server = new HTTPServer(port)
val host = server.getVirtualHost(null)
host.addContext("/hello", (req, resp) => {
@hrj
hrj / importHDFC.scala
Created August 19, 2018 17:19
Import utilities for Indian bank statements into Abandon's shorthand format.
#!scala -save
!#
// From https://stackoverflow.com/questions/32488364/
object Parser {
def fromLine(line: String): List[String] = {
def recursive(
lineRemaining: String
, isWithinDoubleQuotes: Boolean
, valueAccumulator: String
@hrj
hrj / filter.js
Created February 14, 2018 08:24
Filter and sort results from AppBrain
var searchTerm = $ARG[0]
var auth = JSON.parse(readFully('appBrain.json'))
var query = encodeURIComponent(searchTerm)
print("searching for", searchTerm, query)
var command = "curl -o queryResult.json https://api.appbrain.com/v1/info/search?di=${auth.DI}&t=${auth.TOKEN}&query=${query}&sort=RELEVANCY&filter=FREE&limit=50"
print("command", command)
@hrj
hrj / dumpflif.c
Created May 28, 2017 14:26
dumpflif
/*
Example application of FLIF decoder using libflif_dec
Copyright (C) 2017 Harshad RJ
Based on the viewflif code.
License: Creative Commons CC0 1.0 Universal (Public Domain)
https://creativecommons.org/publicdomain/zero/1.0/legalcode
*/
@hrj
hrj / renders-pyra.csv
Created November 7, 2016 18:16
Benchmark results for FLIF lossy chroma patch
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 8 columns, instead of 1. in line 6.
BeigePyraBack.png.2624e1242871643a4cc9e0a3edc015d8.png.d80576b60a14f708468a147bc1ced015.png, 0, 300899, 13026, 12785, 0.001651469967328012, 0.0017180199502035975, 0.00007
BeigePyraBack.png.2624e1242871643a4cc9e0a3edc015d8.png.d80576b60a14f708468a147bc1ced015.png, 20, 300899, 16249, 15912, 0.0014276399742811918, 0.0014876299537718296, 0.00006
BeigePyraBack.png.2624e1242871643a4cc9e0a3edc015d8.png.d80576b60a14f708468a147bc1ced015.png, 40, 300899, 22041, 21626, 0.0011894300114363432, 0.0012190600391477346, 0.00003
BeigePyraBack.png.2624e1242871643a4cc9e0a3edc015d8.png.d80576b60a14f708468a147bc1ced015.png, 60, 300899, 27274, 26511, 0.0010326399933546782, 0.0010415699798613787, 0.00001
BeigePyraBack.png.2624e1242871643a4cc9e0a3edc015d8.png.d80576b60a14f708468a147bc1ced015.png, 80, 300899, 81539, 79640, 3.197799960616976E-4, 3.377299872227013E-4, 0.00002
BeigePyraBase.png.e82c2a43169481d4417c2005616bc48f.png, 0, 366612, 25649, 24886, 0.002077220007777214, 0.0022704401053488255, 0.00019
BeigePyraBase.png.e82c2a43169
@hrj
hrj / compare.scala
Last active November 4, 2016 19:19
DSSIM comparison for chroma lossiness PR to FLIF
import scala.sys.process._
import java.nio.file.Files
import java.nio.file.Paths
val flif1 = args(0)
val flif2 = args(1)
val imgBase = args(2)
val images = Seq("ls", "-1", imgBase).lineStream.filter(_.endsWith(".png")).toList
@hrj
hrj / dual_axis_three_ldr_sun_tracker.ino
Last active October 25, 2016 14:22 — forked from chetankothari/dual_axis_three_ldr_sun_tracker.ino
Dual axis sun tracker using three LDR and Arduino Uno
// Authored by the "HeadBanger" team at SHD India.
// Shared under MIT License
#include <Servo.h>
#define NUM_PINS 3
int sensorPins[NUM_PINS] = {A0, A1, A2};
int sensorValues[NUM_PINS] = {0, 0, 0};