Skip to content

Instantly share code, notes, and snippets.

@ohaal
ohaal / algo.js
Created January 13, 2021 19:08
bad positive coord float compression
// use geohash instead!
function encodePositiveFloat(number) {
return compressInt(number
.toString()
.indexOf('.')
.toString()
.concat(number
.toString()
.replace(".", "")));
@ohaal
ohaal / norwegianholidaycalculator.java
Last active August 25, 2023 14:17
Sjekk om dato er norsk hellidag / arbeidsdag
/**
* Add X working days to a LocalDateTime
*
* @param startingDate
* @param workingDaysToAdd
* @return First working day after LocalDateTime with working days added
*/
public static LocalDateTime addWorkingDays(LocalDateTime startingDate, int workingDaysToAdd) {
int days = 0;
int workingDays = 0;
@ohaal
ohaal / clean-up-boot-partition-ubuntu.md
Created March 7, 2019 17:29 — forked from ipbastola/clean-up-boot-partition-ubuntu.md
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Reference

Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
@ohaal
ohaal / playallfromyoutubechannelofcurrentvideo.md
Created January 20, 2017 14:19
Go to playlist of all uploaded video of channel you are currently viewing

Add &feature=mfu_in_order&list=UL behind current video URL

@ohaal
ohaal / messageCurrencyConversion.js
Last active October 17, 2016 08:28
Convert currencies in a message to any other currency
function getValuesAndCurrencies(message) {
var regex = /([$|€|£])? ?(\d+(?:[,.]\d{1,2})?) ?(k)? ?\b(NOK|SEK|USD|CAD|EUR|GBP)?\b/gi;
var symbolToCurrency = { "$": "USD", "€": "EUR", "£": "GBP" };
var match, value, currency;
var result = [];
while (match = regex.exec(message)) {
value = parseFloat(match[2].replace(",", ".")) * (match[3].toLowerCase() == "k" ? 1000 : 1);
currency = (match[4] || symbolToCurrency[match[1]]) || "";
result.push([value, currency]);
}
@REM Just run this in cmd replacing the IP
FOR /L %i IN (1,1,254) DO ping -n 1 192.168.10.%i | FIND /i "Reply">>c:\temp\ipaddresses.txt
@ohaal
ohaal / last_wakeup.cmd
Created June 18, 2016 10:02
See what was the last source of computer waking up
powercfg -lastwake
@ohaal
ohaal / tail_f_equivalent.ps1
Created June 16, 2016 09:04
Roughly Tail -f equivalent in Powershell
Get-Content -Path <Filepath> -Wait
@ohaal
ohaal / countdown-string.js
Last active June 16, 2016 09:06
generate countdown string to a timestamp
var cdStamp = 1472301000000;
var cdDuration = cdStamp - (new Date().getTime());
cdDuration = cdDuration > 0 ? cdDuration : 0;
var cdTimes = [ 7, 24, 60, 60, 1000];
var cdUnit = ['uke', 'dag', 'time', 'minutt', 'sekund'];
var cdUnitEnd = [ 'r', 'er', 'r', 'er', 'er'];
var cdResult = cdTimes
.map((t, i, timeArr) => {
var unitMulti = timeArr.slice(i, timeArr.length).reduce((a,b) => a*b);
@ohaal
ohaal / oracle_locks.sql
Created June 13, 2016 08:03
Oracle SQL locks
-- source: http://psoug.org/snippet/LOCKS-View-Locked-Objects_866.htm
-- view all currently locked objects:
SELECT username U_NAME, owner OBJ_OWNER,
object_name, object_type, s.osuser,
DECODE(l.block,
0, 'Not Blocking',
1, 'Blocking',
2, 'Global') STATUS,
DECODE(v.locked_mode,