Skip to content

Instantly share code, notes, and snippets.

@mgadzhi
mgadzhi / locationClustering.kt
Created March 9, 2021 22:26
Simplified location clustering in Kotlin
import kotlin.math.*
// First, we need to define, what a 'distance' is
interface Distance<T> {
fun T.distance(to: T): Double
}
// Now let's define few concrete data classes that will be used to store the data
data class Location(val lat: Double, val lon: Double)
@mgadzhi
mgadzhi / dbscanV1.kt
Created March 9, 2021 22:11
First version of DBSCAN in Kotlin
import kotlin.math.*
// First, we need to define, what a 'distance' is
interface Distance<T> {
fun T.distance(to: T): Double
}
// Now let's define few concrete data classes that will be used to store the data
data class Location(val lat: Double, val lon: Double)
@mgadzhi
mgadzhi / forward.sh
Created April 15, 2016 16:24
SSH port forwarding
# There is no access from local computer to hostB
# There is an access from local computer to hostA
# There is an access from hostA to hostB
ssh -L 9000:<hostB>:<port> <hostA>
@mgadzhi
mgadzhi / curl_multi.py
Created May 14, 2015 11:01
curlMulti example
#!/usr/bin/env python
import pycurl
import select
def write(*args):
pass
@mgadzhi
mgadzhi / curl.py
Created May 14, 2015 10:35
pycurl example
#!/usr/bin/env python
from pycurl import Curl
def write(*args):
pass
if __name__ == '__main__':
$ find . -wholename '*.py' -type f | xargs -n1 -I {} bash -c 'echo {}; grep -R settings {}'
fn swap(arr: &mut Vec<int>, i: uint, j: uint) -> &Vec<int> {
let buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
arr
}
fn insertion_sort(arr: &mut Vec<int>) -> &Vec<int> {
for i in range(1, arr.len()) {
let key = arr[i];
echo "1234" | gpg --no-use-agent -o /dev/null --local-user <KEYID> -as - && echo "The correct passphrase was entered for this key"
@mgadzhi
mgadzhi / floats_range.mk
Created September 15, 2014 14:08
Produce range of floats in makefile
GROUPS := $(shell for i in `echo {0..95..5}`; do echo $$i | awk '{print $$i/100}'; done)
@mgadzhi
mgadzhi / bash_floats_range.sh
Last active August 29, 2015 14:06
Produce range of floats with step
for i in `echo {0..95..5}`; do echo $i | awk '{print $i/100}'; done