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;
}
{
"description": "The array of models of the application.",
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"required": [
"name",
"attributes",
"permissions"
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 / wordpress-init-db.sql
Created April 19, 2021 12:08
A database dump to setup wordpress, site url localhost:5100, admin credentials: username: vidda, password: root
This file has been truncated, but you can view the full file.
-- MySQL dump 10.13 Distrib 8.0.23, for Win64 (x86_64)
--
-- Host: 127.0.0.1 Database: My Website
-- ------------------------------------------------------
-- Server version 5.7.33
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
@Steven24K
Steven24K / InnerHtmlWrapper.tsx
Created May 3, 2021 10:07
A little wrapper that can be used to keep track of the innerHtml inside react components.
import * as React from "react"
interface InnerHtmlWrapperProps {
text: string
className?: string
}
/**
* A component that puts the text inside a div using dangerouslySetInnerHTML to keep the html layout. Inside this component an internal ref is used to keep track of the content inside the div.
* When you are working with react you have full control over the DOM and the placement new HTML tags, manipulate attributes and event listeners. However when you deal with HTML encoded content you lose
@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> => {