Skip to content

Instantly share code, notes, and snippets.

Jon de la Motte jondlm

Block or report user

Report or block jondlm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jondlm
jondlm / diff_recursive.php
Last active Apr 17, 2019
Recursive array diff php
View diff_recursive.php
<?php
/*
* Recursively diff two arrays. This function expects the leaf levels to be
* arrays of strings or null
*/
function diff_recursive($array1, $array2) {
$difference=array();
foreach($array1 as $key => $value) {
if(is_array($value) && isset($array2[$key])){ // it's an array and both have the key
$new_diff = diff_recursive($value, $array2[$key]);
@jondlm
jondlm / kdebug.bash
Last active Feb 20, 2019
Kubernetes Fuzzy Helper Scripts
View kdebug.bash
#!/usr/bin/env bash
# vim: set syntax=sh:
set -e
if ! hash kubectl 2>/dev/null; then echo "Please install \`kubectl\` before running this command (https://kubernetes.io/docs/tasks/tools/install-kubectl/)"; exit 1; fi
if ! hash fzf 2>/dev/null; then echo "Please install \`fzf\` before running this command (https://github.com/junegunn/fzf#installation)"; exit 1; fi
selection=`kubectl get pods --all-namespaces | grep -v 'NAMESPACE' | fzf --header "Select a pod..."`
namespace=`echo "$selection" | awk '{ print $1 }'`
pod=`echo "$selection" | awk '{ print $2 }'`
@jondlm
jondlm / README.md
Last active Jan 3, 2018
React shallow render lifecycle breakdown
View README.md

React introduced shallow rendering in 0.13. This is an excellent feature that I wish was included earlier in React. It aims to solve the problem of unit testing components without going through a real, or jsdom mocked, DOM. I couldn't find any info online about what lifecycle events it actually fires. So I did some testing of my own. To reproduce, put component.js and test.js into a folder and run node test.js.

TLDR; shallow rendering only invokes the following lifecycle hooks (in order):

  1. getDefaultProps
  2. getInitialState
  3. componentWillMount stops here until re-render
  4. componentWillReceiveProps
  5. shouldComponentUpdate
  6. componentWillUpdate
@jondlm
jondlm / ensure-outlook.bash
Created Dec 18, 2017
Somtimes I forget to open Outlook in the morning, this helps as a cron task
View ensure-outlook.bash
#!/usr/bin/env bash
# vim: set syntax=sh
ps aux | grep -v "grep" | grep "Microsoft Outlook" > /dev/null
outlook_ret=$?
day=`date +%u`
# Make sure it's a weekday and Outlook is running
if [ "$day" -ge 1 -a "$day" -le 5 -a "$outlook_ret" -gt 0 ]; then
osascript -e 'display notification "Please start Outlook" with title "Nag Bot"'
@jondlm
jondlm / xmodmap.md
Last active Sep 13, 2017
Xmodmap swap caps lock and ctrl
View xmodmap.md

Create a file, like ~/.xmodmap and paste the following in it:

!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
@jondlm
jondlm / express-headers.js
Last active Apr 25, 2017
A little node server that logs the most recent request and response headers
View express-headers.js
const express = require('express')
const app = express()
const util = require('util')
app.get('*', function (req, res) {
process.stdout.write('\033c')
console.log('Request headers:')
console.log(util.inspect(req.headers, { colors: true }))
res.send('test')
@jondlm
jondlm / git-stuff.md
Last active Oct 18, 2016
Some useful git stuff
View git-stuff.md

Git Stuff

A collection of git utilities and scripts I've found useful at least once.

Aliases

List the 30 most recent branches you've committed to.

brr = for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
View keybase.md

Keybase proof

I hereby claim:

  • I am jondlm on github.
  • I am jondlm (https://keybase.io/jondlm) on keybase.
  • I have a public key ASC_5JYWh3CFrnJz3NXg7TvFiSOro4iFH_34JiJARHnMGQo

To claim this, I am signing this object:

@jondlm
jondlm / sql-server_row-count-and-size.sql
Last active Dec 28, 2015
Some general scripts for SQL Server to get a data about tables in your databases
View sql-server_row-count-and-size.sql
USE DatabaseName
GO
CREATE TABLE #temp_table (
table_name sysname ,
row_count INT,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50))
@jondlm
jondlm / jslint-header.js
Created Sep 16, 2013
Node / browserify / jQuery jslint header
View jslint-header.js
/*jslint
browser: true,
node: true */
/*global $ */
You can’t perform that action at this time.