Mirror Checking using a “live” md5sum

If you’ve “mirrored” some files and want to do an md5sum check recursively without an intermediate file (md5sum > file; md5sum -c file) you can do it in one easy step using this from the relative path where you are mirroring:


ssh find -type f -exec md5sum {} \\\; | sed sFFF | md5sum -c -

This will ssh to the machine, run the md5sum, pipe it to sed to remove the absolute path prefix to make the md5sum ‘file’ (stdin to the final md5sum) use relative paths.

Metallica - One-liner

I use Metallica one-word song titles as hostnames on my PCs, so to easily look through my MP3s and find 1-word song titles, I use this beauty:

ls * | sed -n 's/^.. - \([^ ]*\).mp3$/\1/p’ | sort -u

Assembly (UCR CS61)

It’s been a while since I’ve actually done anything with assembly code, but going through some old directories from UCR, I found some of my old assembly code. I feel like posting it to get something on the site, so here’s some of the assignments. It’s assembly for the artificial architecture called the “LC2″. If I recall correctly it was made by a professors (or a couple) at UCR and had an emulator and everything ready to rock! Last I heard they had moved on to the LC3 and who knows where they are now?! If this needs to be removed because of any similarity to current projects/classes being taught, please contact me and I will pull it down immediately!

Assignment 1


; Lab section -> 21

;R0 = Multiplicand
;R1 = Multiplier
;R2 = Counter (8)
;R3 = x8000 For MSB test
;R4 = temp holder for lots of things
;R5 = holds mask for shifting right
;R6 = holds mask for shifting right
;R7 = Holds shifted numbers in right-shift operation

.ORIG x3100
LD R0, DATA_ADDR1 ;loads data addresses and initializes values
LD R1, DATA_ADDR2
LDR R0, R0, 0 ;loads data from DATA_ADDR1
LDR R1, R1, 0 ;loads data from DATA_ADDR2

LD R2, COUNTER

SHIFT: ;shifts the multiplicand left
BRz DONE
ADD R1, R1, R1
ADD R2, R2, -1
BRp SHIFT

DONE: ;re-initializes the counter variables
LD R2, COUNTER

COMPARE:
BRz EXIT

COMPARE_LSB:
AND R4, R0, x0001
BRz COMPARE_MSB
ADD R0, R0, R1

COMPARE_MSB: ;compares most significant bit
LD R3, MSB
AND R4, R0, R3
BRn SHIFT_ONE ;shifts a 1 in if msb=1
BRzp SHIFT_ZERO ;shifts a 0 in if msb=0

SHIFT_ONE:
LD R3, SHFTCTR ;puts 15 in ctr variable
AND R7, R7, 0 ;clears R7 for holding result
AND R6, R6, 0 ;clears R6 for holding mask
AND R5, R5, 0 ;clears R5 for holding mask -1 bit
ADD R6, R6, 2 ;puts 2 in the mask
ADD R5, R5, 1 ;puts 1 in the mask-1

O:
AND R4, R6, R0 ;checks mask
BRz SKIP_O
ADD R7, R7, R5 ;adds mask-1 true
SKIP_O:
ADD R6, R6, R6 ;moves mask
ADD R5, R5, R5 ;moves mask-1
ADD R3, R3, -1 ;subtracts 1 from inner counter
BRp O
ADD R5, R5, R5 ;shifts mask last time
ADD R7, R7, R5 ;adds the 1 from mask
AND R0, R0, 0
ADD R0, R0, R7
ADD R2, R2, -1 ;subtracts 1 from outer counter
BR COMPARE

SHIFT_ZERO:
LD R3, SHFTCTR ;puts 15 in ctr variable
AND R7, R7, 0 ;clears R7 for holding result
AND R6, R6, 0 ;clears R6 for holding mask
AND R5, R5, 0 ;clears R5 for holding mask -1 bit
ADD R6, R6, 2 ;puts 2 in the mask
ADD R5, R5, 1 ;puts 1 in the mask-1

Z:
AND R4, R6, R0 ;checks mask
BRz SKIP_Z
ADD R7, R7, R5 ;adds mask-1 true
SKIP_Z:
ADD R6, R6, R6 ;moves mask
ADD R5, R5, R5 ;moves mask-1
ADD R3, R3, -1 ;subtracts 1 from inner counter
BRp Z
AND R0, R0, 0
ADD R0, R0, R7
ADD R2, R2, -1 ;subtracts 1 from outer counter
BR COMPARE

EXIT:
LD R5, RESULT_ADDR
STR R0, R5, 0
HALT

COUNTER .FILL x0008
NEG1 .FILL xFFFF
DATA_ADDR1 .FILL x4200
DATA_ADDR2 .FILL x4201
RESULT_ADDR .FILL x4500
MSB .FILL x8000
SHFTCTR .FILL x000F

.END

Assignment 2


; Lab section -> 21

;R0 = First number
;R1 = Second number
;R2 = Subtraction (add R0 to negative of R1)
;R3 = x8000 held for checking top bit
;R4 = temp storage
;R5 =
;R6 = x8000 if R0 is negative, 0 otherwise
;R7 = x8000 if R1 is negative, 0 otherwise

.ORIG x3504
LD R0, DATA_ADDR1 ;loads data addresses and initializes values
LD R1, DATA_ADDR2
LDR R0, R0, 0 ;loads data from DATA_ADDR1
LDR R1, R1, 0 ;loads data from DATA_ADDR2

LD R3, ISNEG

NOT R1, R1 ;converts num in R1 to negative
ADD R1, R1, x0001 ;for subtraction function

ADD R2, R1, R0 ;adds values to R2
LD R5, RESULT_ADDR ;gets result address
STR R2, R5, 0 ;loads R2 to result address

NOT R1, R1
ADD R1, R1, x0001

AND R4, R2, R3 ; RESULT CHECK
BRn NUU ;x8000 if negative
BRzp PUU

NUU:
AND R4, R0, R3 ; FIRST NUM CHECK
BRn NNU ;x8000 if negative
BRzp NPU

NNU:
AND R4, R1, R3 ;SECOND NUM CHECK
BRn NNN ;x8000 if negative
BRzp NNP

NPU:
AND R4, R1, R3 ;SECOND NUM CHECK
BRn NPN ;x8000 if negative
BRzp NPP

NNN:
AND R4, R4, 0
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

NNP:
;**N/A**
BR EXIT

NPN:
AND R4, R4, 0
ADD R4, R4, 1
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

NPP:
AND R4, R4, 0
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

PUU:
AND R4, R0, R3
BRn PNU
BRzp PPU

PNU:
AND R4, R1, R3
BRn PNN
BRzp PNP

PPU:
AND R4, R1, R3
BRn PPN
BRzp PPP

PNN:
AND R4, R4, 0
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

PNP:
AND R4, R4, 0
ADD R4, R4, 1
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

PPN:
;**N/A**
BR EXIT

PPP:
AND R4, R4, 0
LD R5, VALID_ADDR ;gets validity address
STR R4, R5, 0 ;loads R4 to validity address
BR EXIT

EXIT:
HALT

DATA_ADDR1 .FILL x3500
DATA_ADDR2 .FILL x3501
RESULT_ADDR .FILL x3502
VALID_ADDR .FILL x3503
ISNEG .FILL x8000

.END

Assigment 4


; Lab section -> 21

.ORIG x3100

AND R0, R0, 0
AND R1, R1, 0
AND R2, R2, 0
AND R3, R3, 0
AND R4, R4, 0
AND R5, R5, 0
AND R6, R6, 0
AND R7, R7, 0

LD R6, NEGNUM
LD R0, RETURN

GETNUM1:
GETC
ADD R7, R0, R6
ADD R7, R7, #3
BRz NEGATIVE
ADD R7, R0, R6
ADD R7, R7, #5
BRz POSITIVE
ADD R7, R0, R6
BRn GETNUM1
BRz GETNUM2
ADD R7, R7, #-10
BRnz GETNUM2
BRp GETNUM1
GETNUM2:
ADD R1, R0, R6
OUT
GETC
ADD R7, R0, R6
BRn GETNUM2
BRz GETNUM3
ADD R7, R7, #-10
BRnz GETNUM3
BRp GETNUM2
GETNUM3:
ADD R2, R0, R6
OUT
GETC
ADD R7, R0, R6
BRn GETNUM3
BRz GETNUM4
ADD R7, R7, #-10
BRnz GETNUM4
BRp GETNUM3
GETNUM4:
ADD R3, R0, R6
OUT
GETC
ADD R7, R0, R6
BRn GETNUM4
BRz DONE
ADD R7, R7, #-10
BRnz DONE
BRp GETNUM4
POSITIVE:
OUT
AND R5, R5, 0
BR GETNUM1
NEGATIVE:
OUT
AND R5, R5, 0
ADD R5, R5, 1
BR GETNUM1
DONE:
ADD R4, R0, R6
OUT
SKIP1:
LEA R0, STABLE
ADD R0, R0, R1
LDR R1, R0, 0

LEA R0, HTABLE
ADD R0, R0, R2
LDR R2, R0, 0

LEA R0, QTABLE
ADD R0, R0, R3
LDR R3, R0, 0

LEA R0, GTABLE
ADD R0, R0, R4
LDR R4, R0, 0

AND R0, R0, 0
ADD R0, R0, R1
ADD R0, R0, R2
ADD R0, R0, R3
ADD R0, R0, R4

AND R5, R5, 1
BRnz SKIP
NOT R0, R0
ADD R0, R0, 1
SKIP:
ADD R6, R0, 0
LD R0, RETURN
OUT

; ADD R7, R6, 0

LEA R1, MASKTABLE
LD R4, COUNTER
LD R5, NEG1
LD R3, MAKENUM
LOOP:
LDR R2, R1, 0
AND R2, R6, R2
BRnp ONE
ZERO:
AND R0, R0, 0
ADD R0, R0, R3
OUT
BR COUNT
ONE:
AND R0, R0, 0
ADD R0, R0, 1
ADD R0, R0, R3
OUT
COUNT:
ADD R1, R1, 1
ADD R4, R4, R5
BRp LOOP

EXIT:
HALT

MAKENUM .FILL #48
COUNTER .FILL #16
NEG1 .FILL xFFFF
RETURN .FILL $A
RETNEG .FILL $-A
NEGNUM .FILL #-48
STABLE .FILL 0
.FILL 1000
.FILL 2000
.FILL 3000
.FILL 4000
.FILL 5000
.FILL 6000
.FILL 7000
.FILL 8000
.FILL 9000
HTABLE .FILL 0
.FILL 100
.FILL 200
.FILL 300
.FILL 400
.FILL 500
.FILL 600
.FILL 700
.FILL 800
.FILL 900
QTABLE .FILL 0
.FILL 10
.FILL 20
.FILL 30
.FILL 40
.FILL 50
.FILL 60
.FILL 70
.FILL 80
.FILL 90
GTABLE .FILL 0
.FILL 1
.FILL 2
.FILL 3
.FILL 4
.FILL 5
.FILL 6
.FILL 7
.FILL 8
.FILL 9
MASKTABLE .FILL $8000
.FILL $4000
.FILL $2000
.FILL $1000
.FILL $0800
.FILL $0400
.FILL $0200
.FILL $0100
.FILL $0080
.FILL $0040
.FILL $0020
.FILL $0010
.FILL $0008
.FILL $0004
.FILL $0002
.FILL $0001
.END

Test


.ORIG x3100
LD R1, DATA_ADDR
LDR R1, R1, 0

LEA R2, 1
LD R6, NEG1
AND R4, R4, 0
LD R3, COUNTER

COMPARE:
BRz EXIT
AND R5, R1, R2
BRz OVER
ADD R4, R4, 1

OVER:
ADD R2, R2, R2
ADD R3, R3, R6
BRnzp COMPARE

EXIT:
LD R5, RESULT_ADDR
STR R4, R5, 0
HALT

COUNTER .FILL x10
NEG1 .FILL xFFFF
DATA_ADDR .FILL x30FE
RESULT_ADDR .FILL x30FF

.END

Combining PDFs in Linux

A while back I had a series of PDF documents that were in chapter forms. If my memory serves me correctly, it was the teacher book which included answers in college. I didn’t want 20 pdfs, I wanted only one. Here’s how to combine them all on the command line with ghost script installed:


gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=book.pdf ch00.pdf ch01.pdf ch02.pdf ch03.pdf ch04.pdf ch05.pdf ch06.pdf ch07.pdf ch08.pdf ch09.pdf ch10.pdf ch11.pdf ch12.pdf ch13.pdf ch14.pdf ch15.pdf ch16.pdf index.pdf biblio.pdf

That combines chapters 0-16, then index and bibliography (in that order) into book.pdf!

Auto SSH Key

This small script (basically a one-liner) will transfer your public ssh key (if in standard ~/.ssh/id_dsa.pb) and properly set permissions to the host passed as the first argument. This makes it so the only time you need your password (if using a passphrase-less ssh-key) will be when running this script. After that, you will have your ssh key access done automatically!

Example:
mmrosko@cure ~ $ sshme mmrosko@matmrosko.com
mmrosko@matmrosko.com’s password:
mmrosko@cure ~ $ ssh mmrosko@matmrosko.com
Last login: Tue Oct 30 22:47:42 2007 from ipXX.sd.sd.cox.net
mmrosko@vps ~$

FTP Sync

This script is useful to mirror a directory over FTP. I find this useful when I am working on web changes on an account I do not have SSH access or VIM. I have plans to add getopt support for more functionality. As of now, most of it is controlled via the environment variables found at the top.

Example usage for uploading local mirror:
$ ftpsync up /subdirectory/on/mirror

Picture Resizer

This is the first of many bash scripts I will keep updated and available. I will work on making them more featureful and bug-free if they gain popularity. They’re here mostly so I have a place to find them easily! This script is intended to be run from within a directory of images. It will make a similarly named directory within it full of 640×480 (or whatever you change the “$WIDTH” and “$HEIGHT” variables to) using imagemagick’s convert. Right now it will only accept one parameter which is an optional “resize only this picture” option. I may add getopt option parsing and more features if needed, but for now it serves my purposes well.

Bad Behavior has blocked 13 access attempts in the last 7 days.