Skip to content

Instantly share code, notes, and snippets.

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

hrj hrj

πŸ”­
observing
View GitHub Profile
@hrj
hrj / PropertiesProcessor.xtend
Created September 19, 2013 06:11
@properties annotation for Xtend
package properties
import org.eclipse.xtend.lib.macro.AbstractClassProcessor
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
import static extension properties.ASTExtensions.*
/**
import java.util.Arrays
object Util {
import concurrent._
import ExecutionContext.Implicits.global
def par(f1 : => Unit, f2 : => Unit) {
val fut1 = future { f1 }
val fut2 = future { f2 }
Await.ready(fut1.zip(fut2), duration.Duration.Inf)
}
@hrj
hrj / followPoints.py
Created October 27, 2013 13:12
Blender script to make an object follow points on a curve
import bpy
import mathutils
C = bpy.context
def insertKeyFrames(obj, curve):
points = curve.data.splines[0].points
duration = curve.data.path_duration
N = len(points)
framesPerPoint = duration / (N-1)
@hrj
hrj / warm.sh
Created July 4, 2014 03:26
warm.sh | A red+green tint effect for the entire screen
#!/bin/bash
# Call with a percentage value from 0 to 100
# 0 means only red and green, 50 means half of blue is shown through
# if you don't give any arguments the calibration is cleared
if [[ -z "$1" ]]; then
echo Clearing all calibrations
xcalib -clear
else
@hrj
hrj / sha1check.sh
Created January 9, 2015 12:39
shortcut for sha1sum and check
## call sha1sum and check whether the hash matches
## Syntax: sha1check <hash> <filename>
## Just copy paste the follow line into ~/.zshrc or ~/.bashrc
function sha1check() { echo $1 $2 | sha1sum -c; }
@hrj
hrj / test.kts
Created February 19, 2015 19:10
Scala v/s Kotlin
var count = 0
var totalTime = 0L
fun test() {
val start = System.currentTimeMillis()
val x = (1L..5000000L) map {it * 40} reduce {a,b -> (a*b)%19 + 1}
val end = System.currentTimeMillis()
@hrj
hrj / WikipediaAnalysis.md
Last active August 29, 2015 14:16
Analysis of Wikipedia performance issue

Navigating to Wikipedia home page was causing a massive slowdown of the browser. After analysis the problem turned out to be due to a long chain of causes.

A] Whenever mouse is hovered on an element, the element and its descendants are invalidated.

This is a known and important issue, but will take time to fix. Issue #89. See Update below.

B] Invalidation causes re-layouting of the whole DOM tree

As a consequence of A, every mouse move causes the body element to be invalidated, and also its descendants. By itself, this is correct behaviour. (Not really, see update below).

C] Re-layouting of inline-blocks was causing new instances of RInlineBlock to be created.

This is bad but by itself it is not terribly inefficient. However, it causes more trouble...

@hrj
hrj / dbShow.kts
Last active July 20, 2019 17:12
DBF Show
import net.iryndin.jdbf.reader.*
import net.iryndin.jdbf.core.*
val fis = java.io.FileInputStream(args[0])
val reader = DbfReader(fis)
val md = reader.getMetadata()
val fields = md.getFields()
@hrj
hrj / alias.md
Last active November 29, 2023 09:50
pwd alias hell

TL;DR

When you are in a shell in Linux, you may be led to believe you are in directory xyz but might actually be in directory pqr.


Demonstration

In a terminal,

@hrj
hrj / shserv.py
Created August 12, 2015 05:44
Multi-threaded server using python
#!/usr/bin/python
import SocketServer
import BaseHTTPServer
import SimpleHTTPServer
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass