Skip to content

Instantly share code, notes, and snippets.

View jhamberg's full-sized avatar

Jonatan Hamberg jhamberg

View GitHub Profile
@jhamberg
jhamberg / prepare.sh
Created June 26, 2020 09:07
Script for preparing and debloating React projects
#!/usr/bin/env bash
# Small convenience script for preparing a React project
# (C) 2019 - Jonatan Hamberg
copy_if_present() {
if [ -e "$1" ] && [ -e "$2" ]; then
cp "$1" "$2"
fi
}
@jhamberg
jhamberg / FixSearch.MD
Last active November 13, 2019 13:30
How to fix broken Windows 10 Search (1903)
  1. Check your Windows version by pressing Windows + R and entering winver
  2. Download the latest Servicing Stack Updates for your Windows version
  3. Open and install the .msu file
  4. Download and apply the KB4522355 update
  5. Reboot
  6. Open Command Prompt as an administrator and run sfc /scannow.
  7. Scan completes without errors, but C:\Windows\Logs\CBS\CBS.log should report multiple warnings like this:

Warning: Overlap: Directory ??\C:\ProgramData\Microsoft\Windows\Start Menu\ is owned twice or has its security set twice

  1. Reboot once more and your search should be working again
@jhamberg
jhamberg / random.js
Created October 31, 2019 19:13
Functional RNG in Javascript using LCG like Java's Random
function* Random(random) {
const m = [0xe66d, 0xdeec, 0x005];
let seed = [
((random) & 0xffff) ^ m[0],
((random / 2**16) & 0xffff) ^ m[1],
((random / 2**32) & 0xffff) ^ m[2]
];
function next(bits) {
@jhamberg
jhamberg / results.txt
Last active October 30, 2019 11:29
Results for TSP on a 8x8 grid starting from (6,2) with max 14 turns. Solver: https://github.com/jhamberg/city-solver
Ran 7082844992 iterations in 80513982 ms
Found 42 results!
----------
┌──────┐
│┌────┐│
││┌──┐││
│││┌┐│││
││││││││
││││└┘││
││█└──┘│
@jhamberg
jhamberg / NavigationUIExtension.java
Last active March 18, 2019 01:20
Transition animations for onNavDestinationSelected
import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.NavDestination;
import androidx.navigation.NavGraph;
import androidx.navigation.NavOptions;
// Example with default animations:
@jhamberg
jhamberg / PlayCrawler.java
Last active March 11, 2019 14:58
Find application category on Android without dependencies by parsing the HTML from Play Store
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Created by Jonatan Hamberg on 11.3.2019.
// (C) 2019 - University of Helsinki
public class PlayCrawler {
// Find an opening anchor tag "<a" followed by any number of non-closing characters (spaces
// or attributes) preceding an itemprop for genre "itemprop=\"genre\"". Following the genre,
@jhamberg
jhamberg / JaccardDistance.java
Last active March 11, 2019 14:52
Calculate the Jaccard Distance between two strings
import java.util.HashMap;
public class JaccardDistance {
public static double jaccard(String a, String b) {
HashMap<String, Integer> map = new HashMap<>();
// For each bigram in first string, add 1
for(int i=0; i < a.length()-1; i++) {
String bigram = "" + a.charAt(i) + a.charAt(i+1);
@jhamberg
jhamberg / createStore.js
Last active July 9, 2018 18:49
Redux (flux) in 12 lines of code with an example.
const createStore = reducer => {
const subscribers = [];
let state = reducer(undefined, {type: "__init"});
return {
dispatch: action => {
state = reducer(state, action);
subscribers.forEach(fun => fun());
},
subscribe: fun => subscribers.push(fun),
getState: () => state