Skip to content

Instantly share code, notes, and snippets.

View selimb's full-sized avatar

Selim Belhaouane selimb

  • Montreal, Canada
View GitHub Profile
@selimb
selimb / convex-hull.test.ts
Created October 4, 2024 19:20
Typescript tests for Convex Hull Algorithm
/** Typescript tests for https://www.nayuki.io/page/convex-hull-algorithm */
import { convexhull, Point } from "./convex-hull";
describe("convexhull", () => {
/*---- Fixed test vectors ----*/
test("empty", () => {
const points: Point[] = [];
const actual = convexhull.makeHull(points);
const expected: Point[] = [];
@selimb
selimb / trpc.ts
Created January 26, 2024 17:12
Bare-bones TRPC
#!/usr/bin/env -S npm exec ts-node -- --swc
import axios from "axios";
import { createServer, RequestListener } from "http";
const PORT = 3333;
const BASE_URL = `http://localhost:${PORT}/trpc`;
const ROUTE_NAME_PARAM = "route_name";
type Route<I, O> = {
fn: (params: I) => O;
@selimb
selimb / example_project.py
Last active August 17, 2024 17:37
FastAPI lifespan-scoped (singleton) dependencies
########
# app.py
########
# Example of how I use it in my project. This file cannot be run as-is.
# The only difference with the example in the fastapi_singleton module docstring is
# the use of a subclassed FastAPI application to define type annotations
import fastapi
import fastapi_singleton
@selimb
selimb / error
Created March 16, 2017 21:27
tox error
$ tox -e py27 -- tests/test_z_cmdline.py::test_alwayscopy
GLOB sdist-make: /Users/selimb/Projects/tox/setup.py
py27 create: /Users/selimb/Projects/tox/.tox/py27
py27 installdeps: pytest>=2.3.5, pytest-timeout
py27 inst: /Users/selimb/Projects/tox/.tox/dist/tox-2.6.1.dev1.zip
py27 installed: appdirs==1.4.3,packaging==16.8,pluggy==0.4.0,py==1.4.32,pyparsing==2.2.0,pytest==3.0.7,pytest-timeout==1.2.0,six==1.10.0,tox==2.6.1.dev1,virtualenv==15.1.0
py27 runtests: PYTHONHASHSEED='113965478'
py27 runtests: commands[0] | py.test --timeout=180 tests/test_z_cmdline.py::test_alwayscopy
=============================================================================== test session starts ===============================================================================
platform darwin -- Python 2.7.10, pytest-3.0.7, py-1.4.32, pluggy-0.4.0
@selimb
selimb / mkpass.js
Last active November 27, 2016 19:22
Generate password from SHA1 recipe
SHA1=function(l){function p(b,a){return b<<a|b>>>32-a}l+="€";for(var n=Math,c=[1518500249,1859775393,2400959708,3395469782,1732584193,4023233417,2562383102,271733878,3285377520,4294967295],s=n.ceil(l.length/4)+2,q=n.ceil(s/16),g=[],a=0,h=[],j,d,e,f,m,i,b,k;a<q;a++){g[a]=[];for(k=0;k<16;k++){function o(b,c){return l.charCodeAt(a*64+k*4+b)<<c}g[a][k]=o(0,24)|o(1,16)|o(2,8)|o(3,0)}}i=l.length*8-8;a=q-1;g[a][14]=i/(c[9]+1);g[a][14]=n.floor(g[a][14]);g[a][15]=i&c[9];for(a=0;a<q;a++){for(b=0;b<16;b++)h[b]=g[a][b];for(b=16;b<80;b++)h[b]=p(h[b-3]^h[b-8]^h[b-14]^h[b-16],1);j=c[4];d=c[5];e=c[6];f=c[7];m=c[8];for(b=0;b<80;b++){var r=n.floor(b/20),t=p(j,5)+(r<1?d&e^~d&f:r==2?d&e^d&f^e&f:d^e^f)+m+c[r]+h[b]&c[9];m=f;f=e;e=p(d,30);d=j;j=t}c[4]+=j;c[5]+=d;c[6]+=e;c[7]+=f;c[8]+=m}i="";for(z=4;z<9;z++)for(a=7;a>=0;a--)i+=((c[z]&c[9])>>>a*4&15).toString(16);return i};
var len = 10;
var pre = '';
var post = '';
var text = window.prompt('Enter master');
window.prompt('Copy dat shit', pre + SHA1(text).slice(0, len) + post);
@selimb
selimb / README.md
Created November 8, 2016 01:08
Fixing shift modified with Razer Naga for World of Warcraft

NumLock is bound to backslash: \

import os.path
import re
import sys
FILES = ['Date.cpp']
function_dicts = {}
def pluck_classname(filepath):
filename = os.path.basename(filepath)
classname = filename.split('.')[0]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
public void DoIt()
{
NXOpen.CAE.Iteration iteration;
NXOpen.CAE.BaseResultType[] resultTypes;
NXOpen.CAE.BaseResultType velocity, shStress, turbEnergy, turbDiss;
// NXOpen.CAE.Result.Quantity qtt;
iteration = (Iteration)this.solutionResult.GetLoadcases()[0].GetIterations()[0];
resultTypes = iteration.GetResultTypes();
foreach (NXOpen.CAE.BaseResultType resultType in resultTypes)
@selimb
selimb / ipython_notebook
Last active August 29, 2015 14:17
MECH544 Lab4 -- Pretty ass plots
{
"metadata": {
"name": "",
"signature": "sha256:c34996a1ca2e1b0e7373db4ee21a08e4854fd46d7e9e02beb3210cc176ea8573"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [