Skip to content

Instantly share code, notes, and snippets.

Avatar
👞
shoehorning code

Sepehr Hosseini sepbot

👞
shoehorning code
View GitHub Profile
View gist:d2a90613bf0c257e489376cf50ec9002
val ctx = Context.newBuilder()
.allowAllAccess(true)
.build()
@Language("Python") val script = """
import polyglot
@polyglot.export_value
def main(x):
return x + 1
""".trimIndent()
View main.rs
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(
SSHEx.stream(conn, command, channel_timeout: 10_000, exec_timeout: 3_600_000),
%{:status => nil,:stdout => [], :stderr => []},
fn (x, acc) ->
case x do
{:stdout, row} ->
@sepbot
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
sepbot / poly.py
Created Oct 21, 2019
sklearn Polynomial Regression
View poly.py
class PolynomialRegression(BaseEstimator):
def __init__(self, degree=2):
self.features = PolynomialFeatures(degree=degree)
self.model = LinearRegression()
def get_params(self, deep=True):
return {'degree': self.features.degree}
def set_params(self, **params):
@sepbot
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
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)
outputStream.writeObject(test)
outputStream.close()