Skip to content

Instantly share code, notes, and snippets.

View medfreeman's full-sized avatar

Mehdi Lahlou medfreeman

  • Geneva, Switzerland
View GitHub Profile
#!/bin/bash
#
# provision.sh
#
# This file is specified in Vagrantfile and is loaded by Vagrant as the primary
# provisioning script whenever the commands `vagrant up`, `vagrant provision`,
# or `vagrant reload` are used. It provides all of the default packages and
# configurations included with Varying Vagrant Vagrants.
# By storing the date now, we can calculate the duration of provisioning at the
@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
*/
@medfreeman
medfreeman / maintenance.yml
Created April 3, 2017 15:07
Trellis maintenance playbook
---
- include: variable-check.yml
vars:
playbook: maintenance.yml
- name: Enable or disable maintenance mode
hosts: web:&{{ env }}
remote_user: "{{ web_user }}"
vars:
@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
# 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 / 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)
@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 / 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 / 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 / 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) {