Skip to content

Instantly share code, notes, and snippets.

View berdosi's full-sized avatar

Bálint Erdősi berdosi

View GitHub Profile
@berdosi
berdosi / pseudorandom.sql
Last active May 31, 2020 12:20
PostgreSQL functions to get the n-th pseudorandom number generated by random() based on a given seed.
CREATE FUNCTION pseudorandom(seed DOUBLE PRECISION, n int)
RETURNS DOUBLE PRECISION AS $$
-- Set the seed (optional). When recursing, this is obviously not done.
SELECT CASE WHEN seed IS NOT NULL THEN setseed(seed) END;
-- recurse until counter reaches 0
SELECT CASE WHEN n>0 THEN pseudorandom(NULL, n-1) END;
-- run random() once. When counter reached 0, this will be the returned.
@berdosi
berdosi / GPX_to_GIS.sql
Last active February 11, 2020 23:11
PostgreSQL: Get the trackpoints from a table containing GPX data into PostGIS geometry.
-- i_am_spatial.raw_gpx_data's gpx_xml column contains GPX data stored as XML.
-- below query lists the trackpoints from this table, along with the file_id they belong to.
--
-- PostGIS is necessary to have the geometry data type available. Otherwise, the outermost SELECT can be removed.
SELECT
file_id,SELECT
file_id,
point_time,
lat,
@berdosi
berdosi / RenameFilesMatchingPattern.ps1
Last active January 28, 2020 10:10
Powershell snippet to do something with items with matching names in a directory
Get-ChildItem |
Where-Object -Property "Name" -Like "*remove this part from the filename*" | # filtering
ForEach-Object {
# action to do. Case in point: rename the file. Note the parentheeses around the two parameters.
Move-Item ($_.Name) ([System.Text.RegularExpressions.Regex]::Replace($_.Name, "remove this part from the filename", ""))
}
@berdosi
berdosi / arrow.svg
Created September 17, 2019 22:11
basic commented picture of an arrow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@berdosi
berdosi / tagImages.sh
Last active July 24, 2019 19:19
set image comment to labels detected via AWS
#!/bin/sh
MAXLABELCOUNT=4
MINCONFIDENCE=90
mkdir smallpics
# create smaller versions, that are both small and big enough for image recognition
parallel convert {} -resize 2048x2048 -quality 90 smallpics/{} ::: *.jpg
import time
def donothingDecorator(f):
""" Make a function returning some string return it prepended with the string's length. """
def wrapper(*args, **kwargs):
#print("ogwell")
returnvalue = str(f(*args, **kwargs))
return str(len(returnvalue)) + " " + returnvalue
return wrapper
@berdosi
berdosi / makeIndex.sh
Last active May 29, 2019 21:19
generate a very basic overview of the pictures in a folder.
#!/bin/bash
# make a quick overview of the pictures in a folder
# I'm using this for Amazon S3, to have preview of the items I have in Deep Glacier
# create an empty folder: index/
# make folder: index/thumbnails
# generate thumbnails for files
# generate index.html
# - generate metadata.js
# - add thumbnails
# - add metadata (todo)
<Multi_key> <colon> <parenright> : "☺" # Compose : )
<Multi_key> <minus> <less> : "←" U2190 # Compose - <
<Multi_key> <minus> <greater> : "→" U2192 # Compose ->
<Multi_key> <o> <o> : "…" U2026 # Compose
<Multi_key> <asterisk> <asterisk> : "★"
<Multi_key> <asciitilde> <asciitilde> : "≈" U2248
<Multi_key> <s> <n> <o> : "☃" # Snowman!
@berdosi
berdosi / showOnce.php
Created April 14, 2019 22:09
Create single-use links for files. Code from 2012-10-08. There are probably more robust solutions than this: it is okay to read, it is less okay to use.
<?php
/* Result of some quick night-coding, so don't expect much.
There should be a show.db sqlite3 database with a schema like
in line 22.
If there isn't a new one is created with helloworld as a default password.
New passwords can be created, they are stored as sha1() hashes.
One can create a new link on show.php?mode=admin; the file names are paths on the web server.
The links are going to look like this: show.php?session=SESSION
@berdosi
berdosi / checkFacebookMessages.js
Created April 14, 2019 22:02
Check Facebook messages and do stuff with them. Code from 2015-07-31, probably defunct.
(new MutationObserver(function (mutation) { // create a mutationobserver for checking any new nodes added to the chats
mutation.forEach(function (m) { // each mutation shall be iterated.
for (var node of m.addedNodes) { // each item may contain the added nodes
message = node.textContent;
if (( message.substr(0, 4) == 'jscr') && confirm("evaluate?")) { // if message matches some conditions
// do stuff with the message
console.log(message.substr(4, 40));
}
}
})