Skip to content

Instantly share code, notes, and snippets.

View medfreeman's full-sized avatar

Mehdi Lahlou medfreeman

  • Geneva, Switzerland
View GitHub Profile
diff --git a/node_modules/@types/koa/index.d.ts b/node_modules/@types/koa/index.d.ts
index df6d5f8..64557e0 100644
--- a/node_modules/@types/koa/index.d.ts
+++ b/node_modules/@types/koa/index.d.ts
@@ -310,7 +310,7 @@ declare interface ContextDelegatedResponse {
/**
* Get/Set response body.
*/
- body: any;
+ body: unknown;
@medfreeman
medfreeman / 30-seconds-of-code.d.ts
Created September 4, 2019 16:06
30-seconds-of-code `isEmpty`function typescript definition
declare module '30-seconds-of-code' {
// tslint:disable-next-line: no-any
export function isEmpty<T extends any, P extends string>(
value: T
): T extends object ? (P extends keyof T ? false : true) : T extends string ? boolean : true;
}
@medfreeman
medfreeman / generator.sh
Created July 26, 2019 10:29 — forked from lierdakil/generator.sh
Proper, if limited, type for Function.bind
#!/bin/bash
max=10
end=""
t=" "
echo "interface Bind {"
echo "${t}<T extends (...args: any[]) => any>(this: T, thisArg: any): T$end"
for i in `seq 1 $max`; do
echo -n "${t}<T extends ("
#!/bin/bash
# install istio, add-ons, and roles
# https://cloud.google.com/kubernetes-engine/docs/tutorials/istio-on-gke
ISTIO_HOME="/Applications/istio-0.4.0"
# required dashboard access and istio roles
kubectl apply \
-f ./other/kube-system-cluster-admin.yaml \
@medfreeman
medfreeman / lodashGetAlternative.js
Created May 24, 2017 14:24 — forked from jeneg/lodashGetAlternative.js
Alternative to lodash get method _.get()
function get(obj, path, def) {
var fullPath = path
.replace(/\[/g, '.')
.replace(/]/g, '')
.split('.')
.filter(Boolean);
return fullPath.every(everyFunc) ? obj : def;
function everyFunc(step) {
@medfreeman
medfreeman / example.js
Created May 15, 2017 23:19 — forked from colingourlay/example.js
Lodash / Underscore sort object keys. Like _.sortBy(), but on keys instead of values, returning an object, not an array. Defaults to alphanumeric sort.
var obj = {b: 3, c: 2, a: 1};
_.sortKeysBy(obj);
// {a: 1, b: 3, c: 2}
_.sortKeysBy(obj, function (value, key) {
return value;
});
// {a: 1, c: 2, b: 3}
@medfreeman
medfreeman / xregexp-lookbehind2.js
Created May 4, 2017 16:59 — forked from slevithan/xregexp-lookbehind2.js
Simulating lookbehind in JavaScript (take 2)
// Simulating infinite-length leading lookbehind in JavaScript. Uses XRegExp.
// Captures within lookbehind are not included in match results. Lazy
// repetition in lookbehind may lead to unexpected results.
(function (XRegExp) {
function prepareLb(lb) {
// Allow mode modifier before lookbehind
var parts = /^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*)\)$/.exec(lb);
return {
@medfreeman
medfreeman / letsencrypt_2016.md
Created April 27, 2017 20:49 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two modes when you don't want Certbot to edit your configuration:

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80) to renew certificates.

In the following, we're setting up mydomain.com to be served from /var/www/mydomain, and challenges will be served from /var/www/letsencrypt.

@medfreeman
medfreeman / Syncthing.ps1
Last active February 12, 2025 09:23
Powershell script to install syncthing, syncthing inotify and QSyncthingtray, and start them at boot as current user. From Windows 7 x64 onwards (PS 3.0).
Add-Type -AssemblyName System.IO.Compression.FileSystem
function downloadFile
{
# Courtesy of Jason Niver / https://blogs.msdn.microsoft.com/jasonn/2008/06/13/downloading-files-from-the-internet-in-powershell-with-progress/
param([string]$url, [string]$targetFile)
"Downloading $url"
$uri = New-Object "System.Uri" "$url"
$request = [System.Net.HttpWebRequest]::Create($uri)
# applescript
# add login item
osascript -e 'tell application "System Events" to make login item at end with properties {name: "Notes",path:"/Applications/Notes.app", hidden:false}'
# delete login item
osascript -e 'tell application "System Events" to delete login item "itemname"'
# list loginitems
osascript -e 'tell application "System Events" to get the name of every login item'