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 / noapppreference.user.js
Created April 14, 2019 21:59
Userscript to disable opening youtube app when visiting the link from the browser.
// ==UserScript==
// @name removeappreference
// @namespace numen
// @include https://www.youtube.com/*
// @include https://youtube.com/*
// @include http://www.youtube.com/*
// @include http://youtube.com/*
// @include https://m.youtube.com/*
// @include http://m.youtube.com/*
// @version 1
@berdosi
berdosi / tar.ts
Last active October 12, 2018 18:21
Minimal implementation for the tar file format, based on https://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
/** Minimal implementation of the TAR file format.
* Reference:
* https://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
*/
export class Tar {
private data: Map<string, Blob> = new Map();
/** Add a file to the archive.
* @param {string} fileName - file name (including directory structure)
* @param {Blob} contents
@berdosi
berdosi / getJaccardSimilarity.js
Last active May 23, 2018 15:52
Calculate the Jaccard similarity index between two strings. Strings are treated as sets of words, and duplicate words are removed. (https://en.wikipedia.org/wiki/Jaccard_index)
function getJaccardSimilarity(item, otherItem) {
function makeUnique(prev, current, index) {
return (index === 1
? [prev].concat(prev !== current ? current : []) // handle when first two items are identical
: (prev.indexOf(current) > -1
? prev
: (prev.push(current), prev)))
}
const union = [].concat(item.split(/\s+/)).concat(otherItem.split(/\s+/)).reduce(makeUnique);
const otherUnique = otherItem.split(/\s+/).reduce(makeUnique);
@berdosi
berdosi / makeUnique.js
Created May 23, 2018 15:49
Remove duplicates from an array (to be used in Array.reduce()). If array.length may be 1, an emty array needs to be supplied as an initial value.
function makeUnique(prev, current, index) {
return (index === 1
? [prev].concat(prev !== current ? current : []) // handle when first two items are identical
: (prev.indexOf(current) > -1
? prev
: (prev.push(current), prev)))
}
@berdosi
berdosi / replaceTooLongTabs.js
Created May 22, 2018 16:58
replace 8 character long tabs in github wit shorter lines
[... document.querySelectorAll(".file td")]
.map(td =>
td.firstChild
? td.firstChild.textContent
= td.firstChild.textContent
.replace(
/^(\t+)/,
(match, p1) =>
" ".repeat(4).repeat(p1.length))
: "")
@berdosi
berdosi / GetBamoszData.js
Created March 25, 2018 22:48
get data from bamosz.hu
const rq = require("http");
const url = "http://www.bamosz.hu/alapoldal?isin=HU0000711353";
const htmlParser = require("htmlparser");
const parseHtml = function(html) {
return new Promise((resolve, reject) => {
(new htmlParser.Parser(
new htmlParser.DefaultHandler(
(error, dom) => {
@berdosi
berdosi / wordfrequency.sh
Last active December 2, 2017 19:32
List the words from a handful of HTML files by frequency.
cat *.html | sed -e 's/<[^>]\+>//g' -e 's/[ \t]\+/\n/g' -e 's/[-\.\\(\\):,;0-9+|]//g'|sort | uniq -ci | sort -h
cat *.html | \ # all the files' contents
sed -e 's/<[^>]\+>//g' \ # without tags (assumes they don't contain line breaks)
-e 's/[ \t]\+/\n/g' \ # replace tabs and spaces with line breaks
-e 's/[^a-z]//gi' | \ # remove some non-letters (
sort | \ # sort once to make uniq work
uniq -ci | \ # show occurrence counts, case insensitive
sort -h # sort by numbers
@berdosi
berdosi / nevnap.sh
Created February 17, 2017 20:46
Shell script to display the current name day
#!/bin/bash
# list from https://hu.wikipedia.org/wiki/Magyar_n%C3%A9vnapok_list%C3%A1ja_d%C3%A1tum_szerint
echo $(grep `date +%m/%d` $0) napja van
exit
01/01 Alpár Fruzsina Bazil
01/02 Ábel Gergely Vazul
01/03 Genovéva Gyöngyvér Benjámin Dzsenifer ((Jennifer))
01/04 Titusz Leona Angéla
01/05 Simon Emília
01/06 Gáspár Menyhért Boldizsár
@berdosi
berdosi / License for my Gists
Last active November 30, 2016 00:10
This license applies for all my public gists under gist.github.com/numen/
MIT License
Copyright (c) 2009-2016, Bálint Erdősi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
/* code based on pseudocode from https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm#Calculating_distance */
interface replacePair {
first: string;
second: string;
cost: number
}
class replacePairCollection {
replacePairs: Array<replacePair>;