Skip to content

Instantly share code, notes, and snippets.

View futureimperfect's full-sized avatar

James Barclay futureimperfect

View GitHub Profile

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

def weird_encoding(s):
assert(isinstance(s, str))
first = list(s[::-1])
for i, c in enumerate(s):
if c.isupper():
first[i] = first[i].upper()
elif c.islower():
first[i] = first[i].lower()
first = ''.join(first)
second = str(len(s))
@futureimperfect
futureimperfect / clean_up_whitespace.sh
Last active August 29, 2015 14:07
Clean Up Whitespace With find and sed
find . -regex '.*\.[mh]$' -exec sed -i '' 's/[ \t]*$//' {} \;
@futureimperfect
futureimperfect / get_os_x_minor_version.sh
Last active August 29, 2015 14:06
Get OS X Minor Version (Yosemite Compatible)
osversionlong=$(sw_vers -productVersion)
osversionshort=$(echo $osversionlong | python -c 'import sys; out = sys.stdin.read().split(".")[1]; print out')
echo "$osversionshort"
@futureimperfect
futureimperfect / complex_ldap_query.py
Created June 2, 2014 00:37
Complex LDAP Queries with python-ldap
import ldap
import sys
LDAP_URI = 'ldap://ldap.example.com'
SEARCH_BASE = 'ou=Example,dc=example,dc=com'
QUERY = '(&(nickname=M*)(employeeType=fulltime)(|(!(departmentNumber=5*))(loginShell=/bin/bash)))'
def ldap_search(ldap_uri, base, query):
'''
@futureimperfect
futureimperfect / complex_ldapsearch.sh
Last active August 29, 2015 14:01
Complex LDAP query with ldapsearch
ldapsearch -LLL -x -H ldap://ldap.example.com -b "ou=someou,dc=example,dc=com" '(&(nickname=M*)(employeeType=fulltime)(|(!(departmentNumber=5*))(loginShell=/bin/bash)))' mail | awk '/mail: / { print $2 }'
@futureimperfect
futureimperfect / java_vendor.py
Last active August 29, 2015 13:57
OS X Java Vendor (Oracle, Apple) One-Liner
python -c 'import os,plistlib; jv = plistlib.readPlist(os.path.join(os.path.realpath("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"), "Contents/Info.plist"))["CFBundleIdentifier"].split(".")[1]; print jv.capitalize()'
@futureimperfect
futureimperfect / query_ad_group_membership.sh
Created January 4, 2014 08:54
Query AD Group Membership Status with ldapsearch
#!/bin/bash
console_user="$(/usr/bin/stat -f%Su /dev/console)"
ldap_uri="ldap://example.com"
search_base="DC=example,DC=com"
group="Some Group"
is_member_of_group=`/usr/bin/ldapsearch -LLL -Q -H "$ldap_uri" -b "$search_base" "sAMAccountName=$console_user" sAMAccountName | $grep "OU=$group"` # -Q prevents the authentication prompt, works if kerberos ticket exists
if [[ "${#is_member_of_group}" -ne "0" ]]; then
echo "$console_user is a member of $group."
@futureimperfect
futureimperfect / guest_login_status.sh
Last active December 20, 2015 22:09
Determine Guest Login Status from CLI on OS X. Will return 1 if enabled and 0 if not.
/usr/bin/defaults read /Library/Preferences/com.apple.loginwindow | awk '/GuestEnabled/ { print $3 }' | sed 's/;//g'
@futureimperfect
futureimperfect / curl_speed_test.sh
Last active December 18, 2015 13:59
A cURL-based command-line download speed test. Add this to your ~/.bash_profile.
alias speedtest='echo "scale=2; `curl --progress-bar -w "%{speed_download}" http://speedtest.wdc01.softlayer.com/downloads/test10.zip -o /dev/null` / 131072" | bc | xargs -I {} echo {} mbps'