Skip to content

Instantly share code, notes, and snippets.

@yrps
yrps / -
Created August 10, 2014 08:00
bash script for Pete
#!/bin/bash
# script to set the default boot partition to Windows
# intended for Fedora20 with Grub2
# https://ask.fedoraproject.org/en/question/9257/dual-boot-fedora-16-windows/
# the configuration file of the bootloader
conf=/boot/grub2/grub.cfg
echo "Examining $conf..."
@yrps
yrps / gitify.sh
Last active March 31, 2016 06:50
bash script to convert archives to git tree
#!/usr/bin/sh
set -o errexit
archdir=$(pwd)/arch-to-git/archives
repodir=$(pwd)/arch-to-git/repo
mkdir -p "$archdir" "$repodir"
pushd "$archdir"
@yrps
yrps / hash-2-letter-words.sh
Created July 21, 2015 04:21
"Manual brute force password attack for you to perform- I chose a password and hashed it using md5"
#!/bin/bash
target=0d149b90e7394297301c90191ae775f0
read -r -d '' words <<WORDS
ad ah am an as at aw ax ay
be by do go ha he hi if in is
it me my no of oh on or ow
ox pi so to uh um up us we
WORDS
@yrps
yrps / decr-bash.sh
Created July 25, 2015 06:40
encrypt an ASCII message with an RSA public key; decrypt with the private key
#!/bin/bash
if [ "$#" -lt 0 -o "$#" -gt 3 ];then
echo -e "\nUsage: decr [<input file>] [<RSA's d>] [<RSA's n>]\n"
echo -e 'input file is "ciphermessage" by default'
echo -e 'private key is 5783-and-7031 by default\n'
exit 1
fi
# default private key is 5783-and-7031
@yrps
yrps / primroots.sh
Last active August 29, 2015 14:27
Determine whether a number is a primitive root of a given prime.
#!/bin/bash
# ncoop 2015/08/13
set -uoe pipefail
IFS=$'\n\t'
usage() {
cat << EOF
Determine whether a number is a primitive root of a given prime.
@yrps
yrps / TwoSums.java
Created September 26, 2015 08:38
O(n) solutions finding two elements in a series that add to a given sum
import java.util.Arrays;
import java.util.HashSet;
/**
* Demonstrates O(n) solutions to the problem of finding two elements in a series that add to a given sum.
* @author ncoop
*/
public class TwoSums {
/**
* Given an unsigned integer array <b>a</b> and a target unsigned integer <b>k</b>, returns a two-element int array
@yrps
yrps / roman.py
Created November 23, 2015 07:05
Regexp-based conversion from Roman numerals to decimal
#!/bin/python3
__author__ = 'ncoop'
from re import search, VERBOSE, IGNORECASE
roman_pattern = '''
^
# M: thousands
((?P<m1000>M)|(?P<m2000>MM)|(?P<m3000>MMM))?
@yrps
yrps / eagle.sh
Created November 23, 2015 07:08
ImageMagick to make my avatar
#!/bin/bash
# ImageMagick script to generate github/bitbucket avatar
# http://www.imagemagick.org/Usage/draw/
out=${HOME}/Documents/eagle.png
side=420
tile=60
marg=30
canvas="#f0f0f0"
@yrps
yrps / matrix-convert.rb
Last active December 4, 2015 22:54
extend Ruby's standard Matrix module to facilitate Rational matrices
require 'matrix'
class Matrix
# Attempt to recast each entry of the matrix to clazz
def to(clazz)
self.each_with_index do |entry, i, j|
self[i, j] = send(clazz.name.to_sym, entry)
end
end
end
@yrps
yrps / clean_ru.py
Created December 31, 2015 05:34
remove non-existent files from user's recently-used.xbel (XFCE4)
#!/usr/bin/env python3
def parseArgs():
from sys import stderr
import argparse
from os.path import expanduser, isfile
parser = argparse.ArgumentParser()
parser.add_argument(
'-f', '--file', help='file to be cleaned',