Skip to content

Instantly share code, notes, and snippets.

shoehorning code

Sepehr Hosseini sepbot

shoehorning code
View GitHub Profile
View gist:d2a90613bf0c257e489376cf50ec9002
val ctx = Context.newBuilder()
@Language("Python") val script = """
import polyglot
def main(x):
return x + 1
use std::{env, io::Error as IoError, net::SocketAddr};
use futures_util::StreamExt;
use tokio::net::{TcpListener, TcpStream};
use tokio_tungstenite::accept_async;
use tungstenite::Error;
async fn handle_connection(raw_stream: TcpStream, addr: SocketAddr) -> tungstenite::Result<()> {
View ssh_log.ex
defmodule Test do
# runs command and logs outputs when they become available, mostly useful for long running commands that
# provide incremental output as the command progresses
def run_command_and_log!(host, conn, command) do
res = Enum.reduce(, command, channel_timeout: 10_000, exec_timeout: 3_600_000),
%{:status => nil,:stdout => [], :stderr => []},
fn (x, acc) ->
case x do
{:stdout, row} ->
sepbot / touch.ts
Created Feb 4, 2020
somehow implementing these touch event handlers from scratch yielded less code than using something like hammer.js
View touch.ts
import { XY } from './types';
export const setupTouch = (
container: HTMLElement,
animate: () => void,
tapped: (position: XY) => void,
panned: (delta: XY) => void,
pinched: (delta: number) => void,
) => {
const ctx = {
sepbot /
Created Oct 21, 2019
sklearn Polynomial Regression
class PolynomialRegression(BaseEstimator):
def __init__(self, degree=2):
self.features = PolynomialFeatures(degree=degree)
self.model = LinearRegression()
def get_params(self, deep=True):
return {'degree':}
def set_params(self, **params):
sepbot / build.gradle
Created Apr 23, 2017
Gradle Kotlin Typescript Typings API
View build.gradle
This is a quick dirty hack that will bootstrap a node/npm environment,
download whatever typings you declare and convert them to Kotlin using ts2kt.
It will then add those typings to the compile configuration.
It works, however I did not find it particularly useful as ts2kt did not support many things at
the time of writing. Hopefully something like this will not be required once kotlin/js
tooling has matured more.
apply plugin: KotlinTypings
sepbot / Main.kt
Created Apr 7, 2017
Kotlin: Serialize function to String. Deserialize back to function type. Invoke.
View Main.kt
fun main(args: Array<String>) {
val test = fun(p: String) : String {
return p + "transformed"
val out = ByteArrayOutputStream()
val outputStream = ObjectOutputStream(out)