Skip to content

Instantly share code, notes, and snippets.

View Steven24K's full-sized avatar
🤹‍♂️
Enjoying life

Steven Steven24K

🤹‍♂️
Enjoying life
View GitHub Profile
@Steven24K
Steven24K / tslint.json
Created December 7, 2018 10:55
A standar tslint file with all options set to false.
{
"jsRules": {
"align": false,
"arrow-parens": false,
"arrow-return-shorthand": false,
"ban": false,
"ban-comma-operator": false,
"binary-expression-operand-order": false,
"class-name": false,
"comment-format": false,
@Steven24K
Steven24K / getLocalIP.js
Created December 20, 2018 13:03
A Javascript function that returns the users local IP adress
function getLocalIP()
{
var ip = [];
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || false;
if (window.RTCPeerConnection)
{
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
pc.createDataChannel('');
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
@Steven24K
Steven24K / Fun.ts
Created March 4, 2020 08:24
Monadic operators for category theory
export interface Func<a, b> {
f: (_: a) => b
then: <c>(this: Func<a, b>, g: Func<b, c>) => Func<a, c>
repeat: (this: Func<a, a>) => Func<number, Func<a, a>>
repeatUntil: (this: Func<a, a>) => Func<Func<a, boolean>, Func<a, a>>
}
export let Func = <a, b>(f: (_: a) => b): Func<a, b> => {
return {
f: f,
@Steven24K
Steven24K / boolean-logic.php
Created March 25, 2020 09:56
An experiment for comparing boolean expressions in PHP
<?php
function toString($value) {
if ($value === TRUE) return 'TRUE';
if ($value === FALSE) return 'FALSE';
if ($value === null) return 'null';
if (is_string($value)) return '"' . $value . '"';
return $value;
}
@Steven24K
Steven24K / ForceDirectedGraph.ts
Created March 26, 2020 14:38
A Force directed graph layouting algorithm based on Fruchterman and Reingold's principle, written in Typescript.
/**
* Force directed graph layout algorithm according to Fruchterman and Reingold's principle.
* The algorithm can be summarized as follows:
* algorithm SPRING(G:graph);
* place vertices of G in random locations;
* repeat N times
* calculate the force on each vertex;
* move the vertex c4
* draw graph on canvas, plotter or any drawing tool.
*
{
"description": "The array of models of the application.",
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"required": [
"name",
"attributes",
"permissions"
@Steven24K
Steven24K / simple-grid.css
Created May 8, 2020 13:14
Just a simple reponsive CSS grid system
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
import csv
import os
from os import listdir
from os.path import isfile, join
from glob import glob
from pathlib import Path
import shutil
import datetime
import functools
@Steven24K
Steven24K / LinkedList.cs
Created January 4, 2021 15:43
An immuatable linked list in C#
public interface IList<T>
{
public bool isEmpty { get; set; }
public IList<T> Add(T v);
public U Reduce<U>(Func<T, U, U> f, U init);
public IList<U> Map<U>(Func<T, U> f);
}
public class Node<T> : IList<T>
{
@Steven24K
Steven24K / simple-paginator.ts
Created February 18, 2021 15:59
A basic paginator written in Typescript. This is usefull when the backend does not support pagination, but you still need some sort of pagination functionality.
export interface Page<T> {
items: T[]
index: number
total_pages: number
page_size: number
current_page: number
}
export const getPage = <T>(list: T[], page_index: number, page_size: number): Page<T> => {