Skip to content

Instantly share code, notes, and snippets.

@nightuser
nightuser / use_existing_session.patch
Last active October 17, 2024 17:01
Use existing Xorg session for chrome-remote-desktop
Add an option to use the existing Xorg session with
chrome-remote-desktop.
The original idea of the patch: https://superuser.com/a/850359
--- a/chrome-remote-desktop 2024-03-27 16:03:20.518579015 +0000
+++ b/chrome-remote-desktop 2024-03-27 16:17:58.241912847 +0000
@@ -110,6 +110,8 @@
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
FIRST_X_DISPLAY_NUMBER = 20
@smnbbrv
smnbbrv / memoize.decorator.ts
Last active February 5, 2023 13:28
Memoize decorator based on WeakMaps (respects non-primitive arguments by reference)
const globalCache = new WeakMap();
export function Memoize() {
return (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>) => {
if (descriptor.value != null) {
descriptor.value = getNewFunction(descriptor.value);
} else if (descriptor.get != null) {
descriptor.get = getNewFunction(descriptor.get);
} else {
throw new Error('Only put a Memoize decorator on a method or get accessor.');
@eddiemoore
eddiemoore / optionalKeys.d.ts
Created March 14, 2019 01:36
Typescript get optional keys from interface
type Undefined<T> = { [P in keyof T]: P extends undefined ? T[P] : never }
type FilterFlags<Base, Condition> = {
[Key in keyof Base]:
Base[Key] extends Condition ? Key : never
};
type AllowedNames<Base, Condition> =
FilterFlags<Base, Condition>[keyof Base];
@Francesco149
Francesco149 / docker-cross-device-link.md
Last active October 27, 2023 08:51
docker error creating new backup file '/var/lib/dpkg/status-old': Invalid cross-device link
@willfrew
willfrew / tuples.ts
Created August 15, 2018 12:53
Fun with tuple types in Typescript 3.0
type Head<T extends unknown[]> = T[0];
type FnWithArgs<T extends unknown[]> = (...args: T) => void;
type TailArgs<T> = T extends (x: unknown, ...args: infer T) => unknown ? T : never;
type Tail<T extends unknown[]> = TailArgs<FnWithArgs<T>>;
// Lol
type Decr<T extends number> =
T extends 10 ? 9 :
T extends 9 ? 8 :
@anvk
anvk / promises_reduce.js
Last active September 8, 2024 15:10
Sequential execution of Promises using reduce()
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
let final = [];
function workMyCollection(arr) {
@tansongyang
tansongyang / cartesian-product-lodash-fp.js
Last active October 8, 2023 23:45
An implementation of Cartesian product using lodash/fp
// Based on this gist: https://gist.github.com/ChrisJefferson/cb8db2a4c67a9506c56c
// JS Bin: https://jsbin.com/cefopi/edit?js,console
const cartesianProduct = (...rest) =>
_.reduce((a, b) =>
_.flatMap(x =>
_.map(y =>
x.concat([y])
)(b)
)(a)
)([[]])(rest);
@drmalex07
drmalex07 / README-setup-tunnel-as-systemd-service.md
Last active November 8, 2024 00:56
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/[email protected]. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@nucreativa
nucreativa / spinner.html
Created May 26, 2015 08:18
Simple CSS Spinner
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
<style>
.spinner {
margin: 100px auto;
@rtfpessoa
rtfpessoa / java-8-ami.md
Last active March 21, 2022 14:46
[Guide] Install Oracle Java (JDK) 8 on Amazon EC2 Ami