Skip to content

Instantly share code, notes, and snippets.

View Lewiscowles1986's full-sized avatar
🤓

Lewis Cowles Lewiscowles1986

🤓
View GitHub Profile
@Lewiscowles1986
Lewiscowles1986 / adapter-passthrough
Last active March 11, 2019 20:27
Allows passthrough for bridges, wireless access-point's and range extenders
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
ADAPTER="eth0"
# Allow overriding from eth0 by passing in a single argument
@Lewiscowles1986
Lewiscowles1986 / README.md
Last active March 7, 2019 07:01
Lazy load from an intelligent place

Lazy Loading (the smart way)

  1. Not all times when we have a Team will we want a list of User's or, approvers
  2. When we select UserApprover entries we want it to be per-team where deleted is False
  3. When we select FinancialApprover entries we want it to be per-team where deleted is False
  4. We may wish to select both UserApprover and FinancialApprover entries for a Team

Data model (simplified)

image

@Lewiscowles1986
Lewiscowles1986 / countries-without-postcodes.inc.php
Created December 16, 2015 08:52
Countries without postcodes (PHP) (conversion of https://gist.github.com/kennwilson/3902548 to PHP)
<?php
return [
[ "Angola", "AO" ],
[ "Antigua and Barbuda", "AG" ],
[ "Aruba", "AW" ],
[ "Bahamas", "BS" ],
[ "Belize", "BZ" ],
[ "Benin", "BJ" ],
[ "Botswana", "BW" ],
@Lewiscowles1986
Lewiscowles1986 / login.js
Created December 1, 2018 08:28
Sitespeed.io preScript for logging in using username+password before running tests.
module.exports = {
run(context) {
return context.runWithDriver((driver) => {
return driver.get(context.options.loginUrl)
.then(() => {
const webdriver = context.webdriver;
const until = webdriver.until;
const By = webdriver.By;
const userName = context.options.username || 'admin';
@Lewiscowles1986
Lewiscowles1986 / README.md
Last active November 24, 2018 18:28
Get IP of running docker container

Get docker container IP address by name

Installation

mkdir -p $HOME/bin
wget -O ~/bin/docker-container-ip https://gist.github.com/Lewiscowles1986/2c80f1e510152b461eae5c501a00a195/raw/6b60245035ee63a025db20e287f89d74db08b356/docker-network-ip
chmod +x ~/bin/docker-container-ip
@Lewiscowles1986
Lewiscowles1986 / scroll-position-hide-fb.js
Created October 23, 2018 18:57
Hide / show element depending on scroll position
(function(target, threshold, elem) {
listener = () => {
if (target.scrollY > threshold) {
elem.style.opacity = 1;
} else {
elem.style.opacity = 0;
}
};
target.addEventListener(
'scroll',
@Lewiscowles1986
Lewiscowles1986 / count-lines
Created October 7, 2018 14:57
Count lines in files
#!/bin/python
"""
This utility allows you to count the number of lines in files
by default just .py files, but accepts command-line arguments.
This utility does miss files and folders beginning with '.'
so don't use them!
usage: {script} {path} [extensions] [exclude]
@Lewiscowles1986
Lewiscowles1986 / FindJemalloc.cmake
Created January 15, 2017 16:35
Find Jemalloc library (CMake)
#
# Find the JEMALLOC client includes and library
#
# This module defines
# JEMALLOC_INCLUDE_DIR, where to find jemalloc.h
# JEMALLOC_LIBRARIES, the libraries to link against
# JEMALLOC_FOUND, if false, you cannot build anything that requires JEMALLOC
# also defined, but not for general use are
@Lewiscowles1986
Lewiscowles1986 / index.php
Last active September 23, 2018 17:22
WordPress media Taxonomies
<?php
/*
Plugin Name: CODESIGN2 Media Taxonomy Modifications
Plugin URI: http://www.codesign2.co.uk
Description: We think it's a real shame that media can be a little unweildy, and not make much sense; on larger sites it's debilitating, so we made this plugin. Enjoy
Author: CODESIGN2
Version: 1.3.6
Author URI: http://www.codesign2.co.uk/
*/
@Lewiscowles1986
Lewiscowles1986 / closestNumberArray.js
Created August 26, 2018 05:28 — forked from vipickering/closestNumberArray.js
Javascript: Find The Closest Number In Array To A Specific Value
var array = [];
function closest(array,num){
var i=0;
var minDiff=1000;
var ans;
for(i in array){
var m=Math.abs(num-array[i]);
if(m<minDiff){
minDiff=m;