Skip to content

Instantly share code, notes, and snippets.

@Gordin
Gordin / firestore_rest_api.ts
Last active February 8, 2023 17:40
Uses the REST API instead of the native firestore library to be able to get whole collections in batches, instead of the builtin listDocuments that always loads all documents. This assumes that you are inside a firebase project with an initialized app, otherwise generating the AccesToken won't work
import fetch from 'node-fetch'
import * as app from 'firebase-admin/app'
type ListDocumentResult = ExistingListDocumentResult | EmptyListDocumentResult
type json = any
interface ExistingListDocumentResult extends EmptyListDocumentResult{
fields: Record<string,any>
createTime: string,
updateTime: string
@Gordin
Gordin / chatGPT_income_of_person.py
Created December 5, 2022 14:07
When you ask ChatGPT to write a python function to estimate a persons net income, based on the most important social and economic factors
def estimate_net_income(gender: str, race: str, age: int,
education: str, occupation: str,
location: str, experience: int,
sexual_orientation: str,
disability_status: bool,
is_trans: bool,
family_status: str) -> float:
# Set base income to $40,000
income = 40000
@Gordin
Gordin / README.md
Last active November 19, 2022 16:54
Script that remaps Keys in Cyberpunk 2077 from qwertz to dvorak and shifts everything one key to the right (to play with ESDF)
  1. Have python installed
  2. Download remap.py and put it next to the config file inputUserMappings.xml (Should be in ...\Cyberpunk 2077\r6\config)
  3. Open a terminal, cd into the directory with the script, and run python remap.py
  4. It should create a new file called inputUserMappings2.xml
  5. Now rename inputUserMappings.xml to something else, and rename inputUserMappings2.xml to inputUserMappings.xml
@Gordin
Gordin / lid.sh
Created December 5, 2020 01:55
script, that moves windows to another monitor, when the lid of the notebook is closed. Run with `watch -n 0.5 ./lid.sh`
#!/usr/bin/env bash
LID_TMP='/tmp/lidscript.tmp'
# Read hoved windows from file
readarray moved_windows < $LID_TMP
# remove newlines after every element...
newMovedWindows=()
for i in "${!moved_windows[@]}"; do
without_newline=${moved_windows[$i]%$'\n'}
if [[ $without_newline != "" ]]; then
@Gordin
Gordin / encode.ps1
Created October 11, 2020 18:29
Normalize audio and upscale to 4K in one go with ffmpeg-normalize, using NVENC Encoder in Powershell
$files = Get-ChildItem "E:\obs\convert\"
foreach ($file in $files) {
$name = $file.name
ffmpeg-normalize $file.fullName -o "E:\obs\converted\${name}_4k.mkv" -e='-vf scale=3840:2160 -c:v hevc_nvenc -rc constqp -qp 14 -rc-lookahead 8' -pr
}
@Gordin
Gordin / .bashrc
Created June 19, 2020 14:36
Make Tab-Completion usable in WSL by removing Windows stuff from PATH
# If in WSL, remove all windows stuff from path, except Windows dir for explorer.exe
# This Speeds up Tab-completion A LOT. without this pressing TAB takes ~8.5 seconds, with this
# ~100ms. Change /mnt/\c\/ to something different if the Windows drive is mounted somewhere else...
C_DRIVE='/mnt/c'
if [ -d "$C_DRIVE" ]; then
export PATH=$(echo ${PATH} | \
awk -v RS=: -v ORS=: "/${C_DRIVE//\//\\/}/ {next} {print}" | sed 's/:*$//')
# Add C:\Windows back so you can do `explorer.exe .` to open an explorer at current directory
export PATH="$PATH:$C_DRIVE/Windows/"
fi
@Gordin
Gordin / covid_mortality.py
Last active March 21, 2020 14:55
Script to calculate mortality rate of COVID-19 in different countries based on data from https://coronavirus.jhu.edu/map.html
#!/usr/bin/env python3
# Little script to calculate the mortality rate of COVID-19 in different
# countries based on data from https://coronavirus.jhu.edu/map.html
# I extracted this from firefox dev tools. Returns country data as JSON
'''
curl 'https://services9.arcgis.com/N9p5hsImWXAccRNI/arcgis/rest/services/Z7biAeD8PAkqgmWhxG2A/FeatureServer/1/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Deaths%3E0)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Deaths%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Origin: https://www.arcgis.com' -H 'Connection: keep-alive' -H 'Referer: https://www.arcgis.com/apps/opsdashboard/index.html' -H 'TE: Trailers'
'''
# Build the same request in python
@Gordin
Gordin / cd_for_windows_paths.sh
Last active September 5, 2023 07:05
If you put this in your .bashrc/.zshrc you will be able to use cd to Windows style paths. This is probably only useful for WSL users.
cd() {
# Check if no arguments to make just typing cd<Enter> work
# Also check if the first argument starts with a - and let cd handle it
if [ $# -eq 0 ] || [[ $1 == -* ]]
then
builtin cd $@
return
fi
# If path exists, just cd into it
# (also, using $* and not $@ makes it so you don't have to escape spaces any more)
@Gordin
Gordin / twitter_asterisk_fix.rb
Created February 15, 2020 02:42
Fix for the twitter gem that allows Tweets with * in them
require "uri"
# The encoder method of the http gem needs to be overriden because of the twitter gem.
# Without that, there's an incompatibility between the simple_oauth gem which encodes asterisks and the http one which does not.
# Cf. https://github.com/httprb/form_data/issues/22 and https://github.com/sferik/twitter/issues/6# 77
# I added a check to see if this method has been called from inside the twitter gem, so that other libraries can still use the default behavior
HTTP::FormData::Urlencoded.encoder = lambda do |enum, enc = nil|
call_regex = Regexp.new(
'gems/twitter-\d+.\d+.\d+/lib/twitter/rest/request.rb:\d+:in `public_send\'')
if caller.any? call_regex
@Gordin
Gordin / no_librarian_while_playing_beat_saber.ahk
Created October 3, 2019 17:10
Disables the OVRLibrarian program from Oculus while Beat Saber is running. (Needs to be run as administrator)
#Persistent
SetTimer, beatsabercheck, 2000
process_name := "Beat Saber.exe"
Librarian := "C:\Program Files\Oculus\Support\oculus-librarian\OVRLibrarian.exe"
Librarian_bak := "C:\Program Files\Oculus\Support\oculus-librarian\OVRLibrarian_bak.exe"
beatsabercheck:
ifWinExist, ahk_exe %process_name%
{