Skip to content

Instantly share code, notes, and snippets.

Eric Bailey nerflad

Block or report user

Report or block nerflad

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
nerflad /
Created Apr 3, 2016
Python 2: Get file linecount
import os
def file_len(fname): #get file linecount
if os.stat(fname).st_size == 0:
return 0
with open(fname) as f:
for i, l in enumerate(f):
return i+1
nerflad /
Last active Apr 3, 2016
Python 2: Convert base 10 number to desired base
# convert base10 number to desired base
def convertbase(num, base):
mods = []
while num >= base:
mods.append(num % base)
num = num / base
if num <= base:
nerflad /
Last active Apr 5, 2016
For use by the TSA instead of their $1.4m iOS app...
import os, datetime, random
while True:
print "ENTER to continue, or type 'quit'"
print ''
print(random.choice(('Left', 'Right')))
print ''
prompt = raw_input("")
if prompt == 'quit':
nerflad / Recursive int adder (py)
Last active Jun 24, 2016
Takes arguments of any basic data type, returning sum of all ints
View Recursive int adder (py)
#!/usr/bin/env python
def add_ints(*args):
return_sum = 0
for i in args:
if type(i) in [list, tuple]:
for list_key in i:
return_sum += add_ints(list_key)
if type(i) == dict:
nerflad / gpExtract.bat
Created Jul 1, 2016
Windows: backup Local Group Policy to directory
View gpExtract.bat
:: Requires Administrator
:: Copies entire GP object directory from system32 to current working directory
@echo off
setlocal EnableExtensions
set "dirname=.\policyobjects - %DATE% %TIME%"
takeown /a /f %systemroot%\system32\grouppolicy /r /d y
xcopy %systemroot%\system32\grouppolicy "%dirname%" /s /h /i /y
nerflad / get-wmic-time.bat
Created Jul 2, 2016
Windows: Get fancy formatted time from WMIC if you don't have access to Command Extensions (for native %date% and %time%)
View get-wmic-time.bat
:: This is not mine!
:: This is almost verbatim from an answer on stack exchange!
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do (
set "dt=%%a"
nerflad / readCfgs.bat
Created Jul 2, 2016
Read all .cfg files in cwd with nested FOR loop
View readCfgs.bat
@echo off
for %%A in (%~dp0*.cfg) do (
for /f %%B in (%%A) do (
set "varName=%%~nA"
set "!varName!="
set "!varName!=%%B"
goto :EOF
nerflad / deleteself.bat
Created Jul 14, 2016
Self Deleting Batch Script
View deleteself.bat
:: Delete self, handy for scripts you need manually
:: copy and deploy to lots of machines
:: Pretty sure I stole this from SS64.
set "batchPath=%~0"
echo Set objFSO = CreateObject( "Scripting.FileSystemObject" ) > "%~dp0temp.vbs"
echo objFSO.DeleteFile( "!batchPath!" ) >> "%~dp0temp.vbs"
echo objFSO.DeleteFile WScript.ScriptFullName >> "%~dp0temp.vbs"
echo WScript.Quit >> "%~dp0temp.vbs"
set currentbranch (git branch | awk '{print $2}' | grep -v -e '^$');
set otherbranches (git branch | awk '{print $1}' | grep -v -e '\*');
git pull;
for i in $otherbranches
git checkout $i
nerflad /
Created Jan 6, 2017
verifying meself...

Keybase proof

I hereby claim:

  • I am nerflad on github.
  • I am nerflad ( on keybase.
  • I have a public key ASBE5NCN6npxKEnnUgcgzM9q6-lBTBH7JoJpYnEC0X9Eigo

To claim this, I am signing this object:

You can’t perform that action at this time.