Skip to content

Instantly share code, notes, and snippets.

@qbein
qbein / ipadencode.rb
Created November 22, 2011 19:23
Convert a video file to format suitable for iPhone, iPad and Apple TV
#!/usr/bin/ruby
FILEPATH = ARGV[0]
OUTPUT_DIR = ARGV[1]
raise "Usage: ipadencode.rb FILEPATH OUTPUT_DIR" if FILEPATH.nil? || OUTPUT_DIR.nil?
raise "First argument must be a video file" unless File.exist?(FILEPATH)
raise "Second argument must be a directory" unless File.directory?(OUTPUT_DIR)
OUTPUT_FILE = File.basename(FILEPATH).gsub(/.[a-z0-9]{3,4}$/i, ".mp4")
@qbein
qbein / ssh-agent_bash_profile.sh
Created November 23, 2011 12:02
SSH Agent in Cygwin
export SSH_AUTH_SOCK=/tmp/.ssh-socket
ssh-add -l 2>&1 > /dev/null
if [ $? = 2 ]; then
# Exit status 2 means we could not add to agent
ssh-agent -s -a $SSH_AUTH_SOCK > /tmp/.ssh-script
./tmp/.ssh-script
echo $SSH_AGENT_PID > /tmp/.ssh-agent-pid
fi
@qbein
qbein / pagination.js
Last active January 14, 2017 08:51
Simple pagination function
function getPages(pageCount, current, padding, boundaryPadding) {
var start, end, pages;
start = current - padding;
end = current + padding;
if (start < 0) {
end += Math.abs(start) + 1;
}
if (end > pageCount) {
@qbein
qbein / gmail relay postfix
Last active August 29, 2015 14:15
Postfix gmail relay OS X 10.9 Maverics
/etc/postfix/main.cf:
# Use gmail as relayhost
relayhost = [smtp.gmail.com]:587
# Map outbound users from local [email protected] to real mail users
smtp_generic_maps = hash:/etc/postfix/generic
# Configure authentication for gmail's TLS requirements
smtp_tls_loglevel=1
smtp_tls_security_level=encrypt
@qbein
qbein / img-to-svg.js
Created March 17, 2015 21:41
Embeds an image in svg
var fs = require('fs'),
sizeOf = require('image-size');
function usage() {
console.log('usage: node img-to-svg.js {input}');
process.exit(1);
}
function template(data) {
return '<svg xmlns="http://www.w3.org/2000/svg" \n' +
@qbein
qbein / .bashrc
Created April 13, 2015 12:27
Bash function for making svn more usable
svn() {
case "$1" in
"log")
`which svn` log $2 | perl -l40pe 's/^-+/\n/'| less
;;
"diff")
`which svn` diff $2 | vim -R -
;;
"st" | "status")
`which svn` status $2 | grep '^\s*[\?MDRCIA!~]'
@qbein
qbein / netcat
Created July 11, 2015 10:01
Replay pcap/pcapng TCP traffic using netcat
For development it may be useful to be able to replay TCP traffic (e.g. HTTP). The dump can be created using WireShark or tcpdump:
$ tcpdump -s 0 port http -i en0 -w dump.pcap
To generate data files that can be replayed through netcat we use tcptrace:
$ tcptrace -e input.pcapng
Finally replay the HTTP traffic using netcat to host 192.168.1.1 port 80
$ cat a2b_contents.dat | nc -v 192.168.1.1 80
If you need to replay the raw network traffic, we need to do some massaging using tcpprep and tcprewrite before using tcpreplay to replay the raw packages. Note that due to limitation of tcprewrite this will not replay any traffic to the network: http://tcpreplay.synfin.net/wiki/FAQ#Doestcpreplaysupportsendingtraffictoaserver.
@qbein
qbein / bboyqq.markdown
Created December 16, 2016 22:08
bBOYQQ
@qbein
qbein / aws_glacier_delete_vault.md
Created January 21, 2018 09:33 — forked from veuncent/aws_glacier_delete_vault.md
Delete all archives in an AWS Vault

AWS Glacier: Delete vault

Follow these steps to remove all archives from an AWS vault. After this is finished, you will be able to delete the vault itself through the browser console.

Step 1 / Retrive inventory

This will create a job that collects required information about the vault.

$ aws glacier initiate-job --job-parameters '{"Type": "inventory-retrieval"}' --account-id YOUR_ACCOUNT_ID --region YOUR_REGION --vault-name YOUR_VAULT_NAME