Skip to content

Instantly share code, notes, and snippets.

@kopiro
kopiro / nQueenBT.js
Created September 14, 2022 09:19
N-Queen with Backtrack
function printBoard(board, method = "log") {
console[method](board.map((e) => e.join("")).join("\n"));
}
function createDiagonalMatrix(_) {
_.takenDiagonal = [];
_.diagonalMatrix = new Array(_.n).fill().map(() => new Array(_.n).fill(-1));
// first row
for (let y = 0; y < _.n; y++) {
@kopiro
kopiro / README.md
Created May 6, 2022 18:57 — forked from Informatic/README.md
openlgtv webOS hacking notes

This is just a dump of some interesting undocumented features of webOS (3.8 specifically, on early 2018 4k LG TV) and other development-related tips.

Homebrew app ideas

@kopiro
kopiro / defaults_diff.sh
Last active May 16, 2022 17:06
Get notification when preference from `defaults` change
cmd="defaults read"; left=$(eval $cmd); while true; do right=$(eval $cmd); diff <( printf '%s' "$left") <( printf '%s' "$right"); left="$right"; sleep 1; done
@kopiro
kopiro / TeliaWidget.js
Last active January 10, 2022 17:58
Telia Scriptable widget
// icon-color: purple; icon-glyph: newspaper;
/*
Telia Scriptable widget
Version: 0.0.1
You need to know your subscription ID from your Telia Plan
and grab a session cookie by logging in into the mobile-app
@kopiro
kopiro / telia_gb_left.sh
Last active January 14, 2022 21:06
Telia GB Left (XBar)
#!/bin/bash
# <xbar.title>Telia GB Left</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Flavio De Stefano</xbar.author>
# <xbar.author.github>kopiro</xbar.author.github>
# <xbar.var>string(SESSID=""): Session ID</xbar.var>
# <xbar.var>string(SUBSCRIPTION_ID=""): Subscription ID; if left blank, the first subscription found is gonna be used</xbar.var>
headers='-H "Accept: application/json" -H "X-IOS-Build: 4068" -H "ga-av: 10.10.4" -H "ga-aid: com.teliasonera.selfservice.telia" -H "User-Agent: com.teliasonera.selfservice.telia/10.10.4 (iOS 15.2; Apple)" -H "ga-an: Mitttelia"'
@kopiro
kopiro / atv4-kopiro.sh
Last active March 9, 2022 23:42
Aerial TV on Raspberry PI
#!/bin/bash
set -x
[[ $EUID -eq 0 ]] && {
echo "Do not run this as the root user"
exit 1
}
[[ -z "$XDG_CONFIG_HOME" ]] &&
/**
* Helper to sum an array
*/
function sum(array) {
return array.reduce((carry, e) => (carry += e), 0);
}
/**
* This procedure will build all possible combinations of K elements by making sure we never go into the
* branches where the sum of the sub-list is greater than T.
@kopiro
kopiro / geoguessr_flag_replacer.js
Created June 25, 2021 16:16
Geoguessr Flag replacer
const CCC = [{"name":"Afghanistan","alpha-2":"AF","country-code":"004"},{"name":"Åland Islands","alpha-2":"AX","country-code":"248"},{"name":"Albania","alpha-2":"AL","country-code":"008"},{"name":"Algeria","alpha-2":"DZ","country-code":"012"},{"name":"American Samoa","alpha-2":"AS","country-code":"016"},{"name":"Andorra","alpha-2":"AD","country-code":"020"},{"name":"Angola","alpha-2":"AO","country-code":"024"},{"name":"Anguilla","alpha-2":"AI","country-code":"660"},{"name":"Antarctica","alpha-2":"AQ","country-code":"010"},{"name":"Antigua and Barbuda","alpha-2":"AG","country-code":"028"},{"name":"Argentina","alpha-2":"AR","country-code":"032"},{"name":"Armenia","alpha-2":"AM","country-code":"051"},{"name":"Aruba","alpha-2":"AW","country-code":"533"},{"name":"Australia","alpha-2":"AU","country-code":"036"},{"name":"Austria","alpha-2":"AT","country-code":"040"},{"name":"Azerbaijan","alpha-2":"AZ","country-code":"031"},{"name":"Bahamas","alpha-2":"BS","country-code":"044"},{"name":"Bahrain","alpha-2":"BH","count
import json
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("socket.cryptohack.org", 13372))
s.recv(64)
s.sendall(b'{"option": "encrypt_data", "input_data": "0000000000000000000000000000000000000000000000000000000000000000"}')
data = json.loads(s.recv(64))
key = bytes.fromhex(data['encrypted_data'])
@kopiro
kopiro / switch-groups-hue.sh
Created March 15, 2021 19:12
Switch a Philips Hue group on/off
#!/bin/bash
key=''
url="http://Philips-Hue.local/api/$key/groups/3"
/usr/bin/curl "$url/action" -X PUT -d "{\"on\":$(/usr/bin/curl "$url" | /usr/local/bin/jq "if (.state.all_on) then false else true end")}"