Skip to content

Instantly share code, notes, and snippets.

View erlendaakre's full-sized avatar

Erlend Aakre erlendaakre

View GitHub Profile
import scala.annotation.tailrec
object VarLenEncoding extends App {
val testData = List(("", ""), ("XYZ", "XYZ"), ("AAABC", "A3BC"), ("XXXX", "X4"))
def encode(s: String): String = split(s, Nil).map(f => if (f.length == 1) f else s"${f.head}${f.length}").mkString
def decode(s: String): String = ???
@tailrec def split(s: String, acc: List[String]): List[String] = {
package org.aakretech.trekwar2.server.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
Basic
=====
[Shift]+[Mod]+[Enter] - launch terminal.
[Mod]+[b] - show/hide bar.
[Mod]+[p] - dmenu for running programs like the x-www-browser.
[Mod]+[Enter] - push acive window from stack to master, or pulls last used window from stack onto master.
[Mod] + [j / k] - focus on next/previous window in current tag.
@erlendaakre
erlendaakre / hunter-io-grab-emails.js
Created June 15, 2017 13:20
Get emails from hunter.io search result page
// ==UserScript==
// @name Get emails from hunter.io search result page
// @namespace http://frostvoid.com
// @version 1.0
// @match https://hunter.io/search*
// @grant GM_registerMenuCommand
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
@erlendaakre
erlendaakre / memWordIndex.html
Last active May 24, 2017 08:01
AngularJS memorable word into indexed list of characters - https://codepen.io/frostvoid/pen/MmLVBN
<html ng-app>
<body>
<div class="container">Enter your memorable word: <input type="text" ng-model="memword"/></div>
<div class="container">
<h5>memorable word character list</h5>
<span ng-repeat="c in memword track by $index">{{$index+1}} - {{c}}<br/></span>
</div>
@erlendaakre
erlendaakre / RecursiveFileFindBehaviour.scala
Created October 4, 2016 10:57
Recursively find all files in a directory and subdirectories
trait RecursiveFileFindBehaviour {
import java.io.File
/**
* Recursively finds all the files in the file system under a given directory
*
* @param dir the directory to find all files in
* @param filesFound always use Set.empty when calling, used internally for keeping track of discovered files
* @return A set of files from the specified directory and all subdirectories found in tree
*/
def findFiles(dir: File, filesFound: Set[File] = Set.empty): Set[File] = {
@erlendaakre
erlendaakre / bitbucket-hide-outdated-comments.js
Last active July 19, 2016 11:03
Tampermonkey script to make it easier to distinguish outdated vs live comments in bitbucket pull requests
// ==UserScript==
// @name Bitbucket hide outdated comments
// @namespace http://frostvoid.com
// @version 1.0
// @match http://your-bitbucket.com:8080/*
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
/* jshint -W097 */
(function() {
@erlendaakre
erlendaakre / FindByID.js
Created May 12, 2015 14:07
MongoDB script to find an object in any collection with a specific objectID
// --------------------- arguments --------------------
var objectID = ObjectId("53623ef33004e212edccab08"); // Change this
var findMultiple = true;
// ----------------------- code -----------------------
var stack = [];
db.getCollectionNames().forEach(function (collName) {
var docs = db.getCollection(collName).find();
docs.forEach(function (doc) {
doc._FROM = collName;
@erlendaakre
erlendaakre / gitSync.sh
Last active April 15, 2023 16:29
Script to sync ALL public GitHub repositories for a github user (for keeping a local backup of your github account)
#!/bin/bash
# --------------------------- Settings -------------------------
gitUsername="erlendaakre"
# ----------------------------- Code ---------------------------
echo "Getting list of all public repositories for user $gitUsername"
array=($(curl -s 1 https://api.github.com/users/$gitUsername/repos | grep '\"name\"\|clone' | sed 's/.*: \"//' | sed 's/\",$//' | xargs echo))
arrayLength=${#array[@]}
reposFound=$(($arrayLength/2))
i=0