Skip to content

Instantly share code, notes, and snippets.

View hrj's full-sized avatar
πŸ”­
observing

hrj hrj

πŸ”­
observing
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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())