Skip to content

Instantly share code, notes, and snippets.

View medfreeman's full-sized avatar

Mehdi Lahlou medfreeman

  • Geneva, Switzerland
View GitHub Profile
@medfreeman
medfreeman / MacOS-Multi-Version-Go-With-Homebrew.md
Created May 10, 2024 14:45 — forked from BigOokie/MacOS-Multi-Version-Go-With-Homebrew.md
Manage multiple versins of Go on MacOS with Homebrew

This process would likely apply to other Homebrew formula also.

First search for your desired package:

brew search go

You should get a list of results that include the below. Not "go" is very unspecific so you may get a lot of results:

@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.

# 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'
@medfreeman
medfreeman / PNGCrush.bat
Created April 18, 2017 16:46 — forked from Robmaister/PNGCrush.bat
A small batch utility that pngcrushes all the .png files in the current directory.
@echo off
CLS
FOR /F "tokens=*" %%G IN ('dir /A:-D /b *.png') DO (
MV %%G %%G.temp
pngcrush.exe %%G.temp %%G
DEL %%G.temp
)
PAUSE
@medfreeman
medfreeman / nav-menu-exporter-importer.php
Created October 1, 2016 14:16 — forked from hissy/nav-menu-exporter-importer.php
[WordPress Plugin] Nav Menu Exporter and Importer / Export and Import nav menus. Requires WordPress Importer plugin.
<?php
/*
Plugin Name: Nav Menu Exporter and Importer
Description: Export and Import nav menus. Requires WordPress Importer plugin
Author: hissy, megumi themes
Version: 0.1
Text Domain: nav-menu-exporter-importer
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/