Skip to content

Instantly share code, notes, and snippets.

@bahamas10
bahamas10 / getyugioh.sh
Created July 30, 2013 05:12
download all yugioh the abridged series
#!/usr/bin/env bash
l=${1:-http://yugiohabridged.com/?p=videos&t=ygotas}
links=$(curl -sS "$l" | grep '<a name')
while read link; do
pagelink=$(perl -nle '/href="([^&]+)&/ && print $1' <<< "$link")
title=$(perl -nle '/name="([^"]+)"/ && print $1' <<< "$link")
echo -e "\n\n---- $title ----\n"
echo "> page link = $pagelink"
vidlink=$(curl -sS "$pagelink" | grep iframe | perl -nle '/src="([^"]+)"/ && print $1')
@bahamas10
bahamas10 / oneliner.bash
Created August 20, 2013 02:30
download pump it up step mania
curl -s http://www.pumpproplus.com/v3/simfile-categories.aspx | grep simfile-list.aspx | perl -ne '/href="([^"]+)">([^<]+)/ && printf("%s %s\n", $1, $2)' | while read -r url name; do name=$(tr -d '[[:cntrl:]]' <<< "$name"); echo "$name"; curl -s "http://www.pumpproplus.com/v3/$url" | grep '"center"><a' | perl -ne '/href="([^"]+)">([^<]+)/ && printf("%s %s\n", $1, $2)' | while read -r _url _name; do echo $_name; __url=$(curl -s "http://www.pumpproplus.com/v3/$_url" | grep -vi video |grep zip | perl -nle "/href=\'([^\']+)\'/ && print \$1"); path=$name/$_name.zip; echo $path; echo $__url; [[ -f "$path" ]] || curl "$__url" -o "$path" ;done; done
@bahamas10
bahamas10 / cast.c
Last active December 22, 2015 07:48
const modify clang vs gcc
#include <stdio.h>
int main(int argc, char **argv) {
const int i = 5;
*((int *)(&i)) = 6;
printf("i = %d\n", i);
return 0;
}
@bahamas10
bahamas10 / README.md
Last active December 23, 2015 02:29
zsh style trailing newline in bash

Trailing Newlines

In zsh, if a command lacks a trailing newline (like echo -n hello), an inverted percent sign with a newline is appended to the output so the prompt can be printed on its own line, not directly after the output. The bashrc in this example will emulate this behavior in bash.

Without fancynewline

dave @ [ manilla :: (Darwin) ] ~ $ echo hello
@bahamas10
bahamas10 / output.md
Last active March 3, 2019 15:15
bash print array
@bahamas10
bahamas10 / bashrc
Last active December 25, 2015 07:19
Billable amount in Joyent Manta
# Total the billable amount in Manta
mbillable() {
mget -q ~~/reports/usage/storage/latest |\
json storage.public.bytes storage.stor.bytes |\
awk '
{
s += $1;
}
END {
billable = (s / 1024 / 1024 / 1024) + 1;
@bahamas10
bahamas10 / cec-keypresses.sh
Last active January 16, 2022 13:02
use `cec-client` to fire events when keys are pressed
#!/usr/bin/env bash
#
# react to cec keypresses in the jankiest way possible
#
# Author: Dave Eddy <dave@daveeddy.com>
# Date: 10/15/2013
# Licens: MIT
# Tested on: Raspberry pi with libcec compiled from soure
onright() {
@bahamas10
bahamas10 / README.md
Last active December 26, 2015 20:08
manta-sync / node-ssh-agent possible issues

1. manta-sync is cloned and npm install is ran

dave @ [ arbiter :: (SunOS) ] ~ $ git clone git://github.com/bahamas10/node-manta-sync.git
Cloning into 'node-manta-sync'...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 15 (delta 6), reused 14 (delta 5)
Receiving objects: 100% (15/15), 6.52 KiB, done.
Resolving deltas: 100% (6/6), done.
@bahamas10
bahamas10 / count.bash
Created November 12, 2013 21:46
array counting in bash #bash@freenode
#!/usr/bin/env bash
# count how many times $1 appears in an array
count() {
local needle=$1 i=0 hay
shift
for hay in "$@"; do
[[ $needle == $hay ]] && ((i++))
done
echo "$i"
}
@bahamas10
bahamas10 / zsnapper.ini
Created November 15, 2013 19:50
zsnapper config
;;; Datasets ;;;
; Define datasets to be snapshotted. Each section should be named
; [datasets.<name>] where name is an alphanumeric word. Each section contains
; one or more match[] definitions. Each match[] should match one or more ZFS
; datasets.
;
; Wildcards (* and ?) can be used and are interpreted as common shell globs.
; Note that these match dataset names as reported by zfs list, not mountpoint
; in the filesystem.