Skip to content

Instantly share code, notes, and snippets.

@klpx
klpx / gist:8538052
Created January 21, 2014 11:01
vk chat autoplayer
window.SONG_NO = 0;
setInterval(function () {
if (!$('#gp_play') || !$('#gp_play').hasClass('playing')) {
$($('.post_audio .play_btn_wrap')[window.SONG_NO]).click();
window.SONG_NO++;
}
}, 5000);
@klpx
klpx / EditDistance.scala
Created April 21, 2016 08:29 — forked from tixxit/EditDistance.scala
Short Levenshtein distance implementation in Scala
package net.tixxit.levenshtein
import scala.math.min
object EditDistance {
def editDist[A](a: Iterable[A], b: Iterable[A]) =
((0 to b.size).toList /: a)((prev, x) =>
(prev zip prev.tail zip b).scanLeft(prev.head + 1) {
case (h, ((d, v), y)) => min(min(h + 1, v + 1), d + (if (x == y) 0 else 1))
}) last
@klpx
klpx / unique_index_migration.sql
Last active September 30, 2016 09:55
Postgres migration to new unique index
/*
We have:
*/
CREATE TABLE data (id BIGINT, name VARCHAR);
CREATE UNIQUE INDEX ON data (name);
INSERT INTO data (id, name) VALUES (1, 'Alex'), (2, 'Bob'), (3, 'alex'), (4, 'AleX');
/*
If we put (3, 'Alex') then we get error:
*/
@klpx
klpx / splitEither.scala
Last active June 18, 2019 16:25
Akka Streams. Graph for Split Either[L,R] to L and R flows
/**
Copy left Alexander Hasselbach
Usage:
val E = b.add(splitEither[Throwable,Int])
val parsed = b.add(Flow[Either[Throwable,Int]])
val valids = b.add(Flow[Int])
val invalids = b.add(Flow[Throwable])
@klpx
klpx / mergeEither.scala
Last active April 18, 2017 12:28
Akka Streams. Graph for merge L and R flows into Either[L,R] flow
/**
Copy left Alexander Hasselbach
Usage:
val E = b.add(mergeEither[Throwable,Int])
val parsed = b.add(Flow[Either[Throwable,Int]])
val valids = b.add(Flow[Int])
val invalids = b.add(Flow[Throwable])
import scala.util.Try
/**
* Адаптированная версия c https://rosettacode.org/wiki/Natural_sorting#Scala
*/
object NaturalOrdering extends Ordering[String] {
def compare(a: String, b: String): Int = {
val aNumTry = Try(BigDecimal(a))
val bNumTry = Try(BigDecimal(b))
@klpx
klpx / vivado-installer-stuck.md
Created July 8, 2022 10:09
Vivado 2022.1 installation gets stuck at ‘Generating installed device list’

Just like Lukas Prokop, I ran into an issue installing Vivado 2022.1 on Ubuntu 22.04. The error looks just like in their article: https://lukas-prokop.at/articles/2021-02-02-vivado-install-stuck

His article gives a recipe to fix 2018.1 version but it's not exactly fit for 2022.1, though an underlying issue is probably the same. Fix is very similar as well, and I'm trying to give more generalized approach.

Fix

The idea is to fix LD_LIBRARY_PATH environment varible for commands the installer runs.

@klpx
klpx / configs.tf
Created December 21, 2022 15:47
Terraform script to breakdown kube config into specific configs to use each in its directory using direnv
# Put this script in `~/.kube/` directory
# > terraform init
# > terraform apply
locals {
# preferences
context2nicename_preference = {
"long-cluster-main" = "longcl"
}
# Directory in which a directory is created for each context from .kube/config