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 / 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.
*
@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 / 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 / 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 / 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,