Skip to content

Instantly share code, notes, and snippets.

View phx's full-sized avatar

phoenix phx

View GitHub Profile
@phx
phx / apple-epoch.sh
Created September 8, 2013 08:14
Get Apple Epoch Time from Unix Epoch Time
#/bin/bash
# 1) create function to get current Unix Epoch Time
EPOCHTIME () { date -u +%s; }
# $ EPOCHTIME
# 1378623423
# $ EPOCHTIME
# 1378623429
# 2) get Unix Epoch Time at 12am on January 1, 2001, as STATIC variable
@phx
phx / sms-to-csv.sh
Last active November 23, 2020 17:38
Dump iOS SMS/iMessage database to CSV.
#/bin/bash
# not an actual script - these are only commands, but the script would be basically the same.
# requires jailbroken iOS device
# get into the filesystem
ssh root:alpine@iphone
# update your package list, and install sqlite
apt-get update
@phx
phx / nix>win
Created August 14, 2013 07:45
popular *nix commands ported to windows cmd.exe environment.
# touch
## doesn't work on read-only files
type nul >>file & copy file +,,
## for read-only files, use the following:
:touch
if not exist "%~1" type nul >>"%~1"& goto :eof
set _ATTRIBUTES=%~a1
if "%~a1"=="%_ATTRIBUTES:r=%" (copy "%~1"+,,) else attrib -r "%~1" & copy "%~1"+,, & attrib +r "%~1"
@phx
phx / if-exists.cmd
Created August 14, 2013 06:06
check to see whether a file exists in cmd.exe
if exist {insert file name here} (
rem file exists
) else (
rem file doesn't exist
)
# or on a single line (if only a single action needs to occur):
if exist {insert file name here} {action}
# a quick little example testing for both files and/or directories:
@phx
phx / if-exists.sh
Created August 13, 2013 19:04
check to see if file/directory exists
!#/bin/bash
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
# for directories:
if [ -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY exists.
fi
@phx
phx / ssl curl download
Created August 9, 2013 15:16
download file over ssl connection using curl
#!/bin/bash
curl -o lgllc.tar.gz -b cookies.txt --user-agent "Mozilla/5.0" --user user:pass -k https://[host]:[port]/[filename]
@phx
phx / clear leopard dns cache
Created June 25, 2013 14:25
clear dns cache in osx 10.6 leopard and snow leopard.
sudo dscacheutil -flushcache
@phx
phx / clear lion dns cache
Created June 25, 2013 14:14
clear dns cache in osx 10.7+ lion and mountain lion
sudo killall -HUP mDNSResponder
@phx
phx / sed newline
Created June 23, 2013 04:44
(bsd sed): target 3 sections of regex pattern, and further target one specific section to copy to new line.
#!/bin/bash
nl=$'\n'; cat "hello.txt" | sed -E "s/(<img.+src=\")(.+)(\".+)/\1\\$nl\2\\$nl\3/g"
@phx
phx / mp3-to-m4r iphone ringtone creator
Created June 21, 2013 04:55
(for use with jailbroken iphones): this is one of those things that may sound like a scenic route to most people who have "an app for that," but for command line ninjas, this is must-have knowledge. this one-liner will dump an mp3 file to wav, then convert the wav to m4r, which can be easily copied over to the iphone's file system via scp/sftp/etc.
#!/bin/bash
mplayer -vo null -vc null -ao pcm:fast:file=file.wav file.mp3; faac -b 128 -c 44100 -w file.wav