Skip to content

Instantly share code, notes, and snippets.

View kelunik's full-sized avatar

Niklas Keller kelunik

View GitHub Profile
@LewisJEllis
LewisJEllis / getRelativeTimeString.ts
Last active March 6, 2024 13:31
Simplified getRelativeTimeString
// from https://twitter.com/Steve8708/status/1504131981444980739
// simplified to a function body of 8 tidy lines
// no loop needed, no 2d array of 3-tuples needed
// just 2 arrays, a findIndex call, and some indexing :)
export function getRelativeTimeString(
date: Date | number,
lang = "en"
): string {
const timeMs = typeof date === "number" ? date : date.getTime();
@bwoebi
bwoebi / text.md
Last active February 19, 2022 01:08
fread() on non-blocking sockets

Reading of non-blocking TCP sockets in PHP

As a short heads-up for those unfamiliar:

  • There is a PHP level buffer. Whenever more is actually read from the socket (default chunk size is 8192), than the user requests in his PHP code, the data is stored there.
  • There is an OS level buffer. There all incoming network data lands. The event loop only knows of that one and checks that one for being non-empty.

Trivial single read

The trivial reading function in PHP is fread($socket, $maxSize).

@halfnibble
halfnibble / HashFunction.ts
Last active October 13, 2023 11:35
Hash function to debug absolute paths sent to the update chunk hash method in webpack.
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
/**
* Interface for Webpack's hashFunction
*/
export interface IHashFunction {
update: (data: string | Buffer, encoding: string) => IHashFunction;
digest: (encoding: string) => string | Buffer;
@rampfox
rampfox / Chromium-at-startup.md
Last active February 27, 2024 12:49
How to open Chromium in full screen at startup on the Raspberry Pi

First, it seems that ~/.config/lxsession/LXDE-pi/autostart does not exist by default.

  1. copy the autostart
cp /etc/xdg/lxsession/LXDE-pi/autostart ~/.config/lxsession/LXDE-pi/
@theseer
theseer / confused.md
Created March 24, 2019 16:36
What happend to the `If-Modified-Since` header?

If-Modified-Since, PHP CLI Server and Firefox

Explanation

When sending the cache control header Cache-Control: no-cache, must-revalidate along with a Last-Modified timestamp, the browser is required to send along an If-Modified-Since header for the next request to the same URL.

The server then is entitled to return HTTP/1.1 304 Not modified in case the content didn't change and the stored copy may still be used.

Sample Code

@liamnewmarch
liamnewmarch / format-relative.js
Last active November 3, 2023 15:29
Relative time strings using the web platform
/**
* The target language. [Browser support is good][1] but "en-US" is a safe default.
*
* [1]: https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language
*
* @type {string}
*/
const { language = "en-US" } = navigator;
/**
@silkentrance
silkentrance / MyComponent.ts
Last active March 10, 2021 13:09
vue-router typescript integration fails
import Vue from 'vue';
import Component from 'vue-class-component';
@Component({
name : 'component'
})
export default class MyComponent extends Vue {
beforeCreate() {
@haskaalo
haskaalo / tarcheatsheet.md
Last active April 8, 2024 14:19
Tar usage / Tar Cheat Sheet

Tar Usage / Cheat Sheet

Compress a file or directory

e.g: tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -v: makes tar talk a lot. Verbose output shows you all the files being archived and much.
  • -f: Allows you to specify the filename of the archive.
@hikari-no-yume
hikari-no-yume / example.php
Created March 20, 2017 20:02
function chaining for PHP 7
<?php declare(strict_types=1);
require_once "✨.🐘";
✨($_)->strlen("foo")->var_dump($_);
@rambabusaravanan
rambabusaravanan / .gitconfig
Last active March 17, 2024 10:31
Git Diff and Merge Tool - IntelliJ IDEA
# Linux
# add the following to "~/.gitconfig" file
[merge]
tool = intellij
[mergetool "intellij"]
cmd = /usr/local/bin/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
trustExitCode = true
[diff]