Skip to content

Instantly share code, notes, and snippets.

View mtavkhelidze's full-sized avatar
🇬🇪
OOP is an exceptionally bad idea which could only have originated in California.

Misha Tavkhelidze mtavkhelidze

🇬🇪
OOP is an exceptionally bad idea which could only have originated in California.
View GitHub Profile
@mtavkhelidze
mtavkhelidze / curry.js
Created August 10, 2018 06:46
Curry the hell out of any function (JavaScript)
/**
* Curry the hell out of any function.
*
* @param f function
* @returns function
*/
function curry(f) {
const arity = f.length;
// preserve original `this` in case we're curring a class method;
@mtavkhelidze
mtavkhelidze / range.js
Last active October 28, 2024 12:13
Fun with lazy evaluation in JavaScript.
/**
* @constructor
*/
function* range(from, until) {
let i = from;
const stop = until ? i => i >= until : () => false;
while (true) {
if (!stop(i)) {
yield i;
} else {
@mtavkhelidze
mtavkhelidze / example.ts
Created January 22, 2019 09:23 — forked from lierdakil/example.ts
An example of Functor in TypeScript. You can run this on https://www.typescriptlang.org/play/
interface Functor<T> {
map<U>(f: (x: T) => U): Functor<U>
}
class Box<T> implements Functor<T> {
value: T
constructor(x: T) {
this.value = x
}
map<U>(f: (x: T) => U): Box<U> {
@mtavkhelidze
mtavkhelidze / intellij.vmoptions
Created January 23, 2019 10:32
Help -> Edit Custom VM Options
# custom IntelliJ IDEA VM options
# https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
-ea
-Xms4096m
-Xmx8192m
-XX:CMSInitiatingOccupancyFraction=65
-XX:MaxMetaspaceSize=512m
-XX:MaxTenuringThreshold=1
@mtavkhelidze
mtavkhelidze / Alamofire.request.error.handling.swift
Created July 21, 2019 15:39 — forked from perlguy99/Alamofire.request.error.handling.swift
Alamofire Request Error Handling - From their documentation
Alamofire.request(urlString).responseJSON { response in
guard case let .failure(error) = response.result else { return }
if let error = error as? AFError {
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
@mtavkhelidze
mtavkhelidze / days-till
Last active October 26, 2019 11:45
Bash script to display number of days till a given date.
#!/usr/bin/env bash
till_date=$(echo $1 | tr -d "-")
echo ${till_date} | egrep -q "([0-9]){8,}"
(($? != 0)) && {
echo "Invalid date." 1>&2
echo "Usage: days-till YYYY-MM-DD" 1>&2
@mtavkhelidze
mtavkhelidze / vm.sh
Created October 31, 2019 10:36
Start/Stop VirtualBox VM in headless mode
#!/usr/bin/env bash
vmm=VBoxManage
function usage {
echo "Usage:" $(basename $0) "start|stop" "hostname" >/dev/stderr
}
function get_ip {
VBoxManage guestproperty enumerate $1 \
@mtavkhelidze
mtavkhelidze / ru_veterans.py
Last active April 9, 2020 19:28
Number of veterans in Russia (blue) with annual change (red).
# Number of veterans in Russia
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.axes import Axes
from matplotlib.figure import Figure
raw_data_source = "https://twower.livejournal.com/2408991.html"
import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame
from pandas.io.common import urlopen
import numpy as np
URL = "https://covidtracking.com/api/v1/states/daily.json"
ALPHA = 0.1
LOGARITHMIC = False
@mtavkhelidze
mtavkhelidze / MapReduce.scala
Created February 14, 2023 11:26 — forked from iravid/MapReduce.scala
Map-Reduce with ZIO
import $ivy.`dev.zio::zio:1.0.0-RC8-12`
import $ivy.`dev.zio::zio-streams:1.0.0-RC8-12`
import zio._, zio.stream._
object Step1 {
import java.nio.file.{Files, Paths, Path}
import scala.collection.JavaConverters._
import zio.blocking._