commit 693f2986aee820aaf1639b149e98519ede1d7d6f Author: Steve Burdick Date: Fri Oct 2 14:30:40 2026 -0700 initial push diff --git a/10_envelope_puzzler/test.py b/10_envelope_puzzler/test.py new file mode 100644 index 0000000..10f71fc --- /dev/null +++ b/10_envelope_puzzler/test.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# 2013-01-31 sburdick +# To solve a Car Talk puzzler +# Goal is to distribute $1000 into 10 envelopes such that when asked for any quantity of whole dollars up to $1000, money can be distributed by paying with any combination of the 10 envelopes without changing their contents +# +# This test proves that distribution of 489,256,256,128,64,32,16,8,4,2,1 works. + + + +import sys + +# Fetch command line argument +try: + goal = int(sys.argv[1]) +except IndexError: + sys.exit("User did not supply an argument.") +except ValueError: + sys.exit("User's argument was not an integer.") + +# Validate integer given as command line argument (goal) +if (goal < 1) | (goal > 1000): + sys.exit("Integer was not within range of 1-1000") + +array = [489,256,256,128,64,32,16,8,4,2,1] + +remainder = goal +for x in array: + if remainder >= x: + # print str(remainder) + " - " + str(x) + " = " + str(remainder - x) + remainder -= x + if remainder == 0: + # sys.exit("I WON solving for " + str(goal) + "!") + sys.exit() +sys.exit("I LOST solving for " + str(goal) + "...") diff --git a/android-Shot-solver/solve.py b/android-Shot-solver/solve.py new file mode 100644 index 0000000..97bc21a --- /dev/null +++ b/android-Shot-solver/solve.py @@ -0,0 +1,157 @@ +#!/usr/bin/python + +# Solves puzzles for Android game Shot (http://www.androidzoom.com/android_games/brain_puzzle/shot-puzzle_xina.html) +# Populate matrix "puzzle" with 1s to represent ball locations + +import copy + +class wizard: + + def __init__(this,puzzle,trail): +# print "----------------------------------------------" +# print "New spawn started with this puzzle:" +# for i in puzzle: +# print i + balls = 0 + for x in puzzle: + for y in x: + if y == 1: + balls += 1 +# print "Total balls: " + str(balls) + if balls == 1: + columns = len(trail[0]) + rowcount = 0 + step = 0 +# print "ORIGINAL PUZZLE" + for i in trail: + rowcount += 1 + print i + if rowcount == columns: + rowcount = 0 + step += 1 +# print "STEP #" + str(step) +# print "END TRAIL" + exit("Win!") + countx = county = 0 + for x in puzzle: # for each row + for y in x: # for each column within each row + if y == 1: # if it found a ball + this.shootball(puzzle,countx,county,trail) + county += 1 + county = 0 + countx += 1 +# print "FAILED...death." +# print "Another wizard died" +# print "----------------------" + + def shootball(this,puzzle,ballx,bally,trail): + this.tryright(puzzle,ballx,bally,trail) + this.tryleft(puzzle,ballx,bally,trail) + this.tryup(puzzle,ballx,bally,trail) + this.trydown(puzzle,ballx,bally,trail) + + def tryright(this,puzzle,ballx,bally,trail): + workingpuzzle = copy.deepcopy(puzzle) + probex = ballx + probey = bally + numcolumns = len(workingpuzzle[probex]) + while (probey < numcolumns - 1): + probey += 1 + if workingpuzzle[probex][probey] == 1: + if probey - 1 == bally: + return # if ball is adjacent, can't hit it + + trailadd = "(" + str(ballx) + "," + str(bally) + ") RIGHT" + workingtrail = copy.deepcopy(trail) + workingtrail.append(trailadd) + + workingpuzzle[ballx][bally] = 0 # remove original ball + while probey < numcolumns: + if workingpuzzle[ballx][probey] == 1: + workingpuzzle[ballx][probey - 1] = 1 + workingpuzzle[ballx][probey] = 0 + probey += 1 + nextwizard = wizard(workingpuzzle,workingtrail) + + def tryleft(this,puzzle,ballx,bally,trail): + workingpuzzle = copy.deepcopy(puzzle) + probex = copy.deepcopy(ballx) + probey = copy.deepcopy(bally) + numcolumns = len(workingpuzzle[probex]) + while (probey > 0): + probey -= 1 + if workingpuzzle[probex][probey] == 1: + if probey + 1 == bally: # if ball is adjacent, can't hit it + return + + trailadd = "(" + str(ballx) + "," + str(bally) + ") LEFT" + workingtrail = copy.deepcopy(trail) + workingtrail.append(trailadd) + + workingpuzzle[ballx][bally] = 0 # remove original ball + while probey >= 0: + if workingpuzzle[ballx][probey] == 1: + workingpuzzle[ballx][probey + 1] = 1 + workingpuzzle[ballx][probey] = 0 + probey -= 1 + nextwizard = wizard(workingpuzzle,workingtrail) + + def trydown(this,puzzle,ballx,bally,trail): + workingpuzzle = copy.deepcopy(puzzle) + probex = ballx + probey = bally + numrows = len(workingpuzzle) + while (probex < numrows - 1): + probex += 1 + if workingpuzzle[probex][probey] == 1: + if probex - 1 == ballx: + return # if ball is adjacent, can't hit it + + trailadd = "(" + str(ballx) + "," + str(bally) + ") DOWN" + workingtrail = copy.deepcopy(trail) + workingtrail.append(trailadd) + + workingpuzzle[ballx][bally] = 0 # remove original ball + while probex < numrows: + if workingpuzzle[probex][bally] == 1: + workingpuzzle[probex -1][bally] = 1 + workingpuzzle[probex][bally] = 0 + probex += 1 + nextwizard = wizard(workingpuzzle,workingtrail) + + def tryup(this,puzzle,ballx,bally,trail): + workingpuzzle = copy.deepcopy(puzzle) + probex = copy.deepcopy(ballx) + probey = copy.deepcopy(bally) + numrows = len(workingpuzzle) + while (probex > 0): + probex -= 1 + if workingpuzzle[probex][probey] == 1: + if probex + 1 == ballx: # if ball is adjacent, can't hit it + return + + trailadd = "(" + str(ballx) + "," + str(bally) + ") UP" + workingtrail = copy.deepcopy(trail) + workingtrail.append(trailadd) + + workingpuzzle[ballx][bally] = 0 # remove original ball + while probex >= 0: + if workingpuzzle[probex][bally] == 1: + workingpuzzle[probex + 1][bally] = 1 + workingpuzzle[probex][bally] = 0 + probex -= 1 + nextwizard = wizard(workingpuzzle,workingtrail) + + + +puzzle = [ [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] , + [0,0,0,0,0,0,0] ] + +firstwizard = wizard(puzzle,["Solution:"]) + +#print "firstwizard died" diff --git a/bashrc.txt b/bashrc.txt new file mode 100644 index 0000000..c383586 --- /dev/null +++ b/bashrc.txt @@ -0,0 +1,5 @@ +alias engage1='ssh -D 10000 -L 3389:10.133.23.220:3389 -p 2222 its@203.215.132.7' +alias engage2='xfreerdp /kbd:0x00000411 /clipboard /size:1440x1000 /u:sburdick@servcorp.prd /p:RichMalt2020 /v:10.133.23.223 /cert-ignore' +alias ll='ls -lh' +alias vim=vim.tiny +alias puke='dd if=/dev/urandom bs=1M count=1 2>/dev/null |base64 |tail -2|head -1' diff --git a/bmsh_parse-cli/parse_app.py b/bmsh_parse-cli/parse_app.py new file mode 100644 index 0000000..60c43a4 --- /dev/null +++ b/bmsh_parse-cli/parse_app.py @@ -0,0 +1,119 @@ +#!/usr/bin/python2.7 + +from PIL import Image +from urllib import urlopen +import sys +import StringIO + +def gen_sig(x_start, y_start): # returns black pixels + sig_0 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [6, 5], [7, 5], [0, 6], [1, 6], [6, 6], [7, 6], [0, 7], [1, 7], [6, 7], [7, 7], [0, 8], [1, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_1 = [[3, 0], [4, 0], [1, 1], [2, 1], [3, 1], [4, 1], [1, 2], [2, 2], [3, 2], [4, 2], [3, 3], [4, 3], [3, 4], [4, 4], [3, 5], [4, 5], [3, 6], [4, 6], [3, 7], [4, 7], [3, 8], [4, 8], [3, 9], [4, 9], [3, 10], [4, 10], [3, 11], [4, 11], [3, 12], [4, 12], [3, 13], [4, 13], [3, 14], [4, 14]] + sig_2 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [5, 5], [6, 5], [7, 5], [4, 6], [5, 6], [6, 6], [4, 7], [5, 7], [3, 8], [4, 8], [5, 8], [2, 9], [3, 9], [4, 9], [2, 10], [3, 10], [1, 11], [2, 11], [3, 11], [0, 12], [1, 12], [2, 12], [0, 13], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [7, 13], [0, 14], [1, 14], [2, 14], [3, 14], [4, 14], [5, 14], [6, 14], [7, 14]] + sig_4 = [[5, 0], [6, 0], [5, 1], [6, 1], [4, 2], [5, 2], [6, 2], [4, 3], [5, 3], [6, 3], [3, 4], [4, 4], [5, 4], [6, 4], [3, 5], [4, 5], [5, 5], [6, 5], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [2, 7], [3, 7], [5, 7], [6, 7], [1, 8], [2, 8], [3, 8], [5, 8], [6, 8], [1, 9], [2, 9], [5, 9], [6, 9], [0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [0, 11], [1, 11], [2, 11], [3, 11], [4, 11], [5, 11], [6, 11], [7, 11], [5, 12], [6, 12], [5, 13], [6, 13], [5, 14], [6, 14]] + sig_6 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [0, 6], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [0, 7], [1, 7], [2, 7], [5, 7], [6, 7], [7, 7], [0, 8], [1, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_8 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [2, 5], [5, 5], [6, 5], [7, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [0, 8], [1, 8], [2, 8], [5, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + char_width = 8 + char_height = 15 + space = 2 + english_sig = "" + + for digit_num in range(1,4): + this_sig = [] + for check_y in range(y_start, y_start + char_height): + for check_x in range(x_start, x_start + char_width): + (curr_r, curr_g, curr_b) = pix[check_x,check_y] + if (curr_r, curr_g, curr_b) == (0,0,0): # if pixel is black + this_sig.append([check_x - x_start,check_y - y_start]) + + for ref_sig in (["0",sig_0], ["1",sig_1], ["2",sig_2], ["4",sig_4], ["6",sig_6], ["8",sig_8]): # array of known sigs added to arrays with element [0] being the English name of the number + if this_sig == ref_sig[1]: + english_sig += ref_sig[0] + + x_start += char_width + space + return int(english_sig) + +def detect_y_axis_labels(): # Detect the y_axis labels + x_offset = 38 # 38 is x coordinate of 1st character of y-axis labels + y_axis_labels = [] + for y in (29, 75, 122, 168, 214, 260, 306): # y coordinates of y-axis kWh labels + # print "Captain, our sensors detected the number: " + gen_sig(38,y) + y_axis_labels.append([gen_sig(38,y), y + 7]) # adding 7 to mark y-coord of cooresponding black line (always 7 pixels lower than start of text label) + return y_axis_labels + +def detect_monthly_totals(): # Read the green bars and push to array + # static variables + image_dimy = 350 # height of image + (green_r, green_g, green_b) = (130,185,6) # RGB values of the deepest green value, used to detect bar heights + column_offset = 119 # starting x coord of 1st graph in bar graph + column_increment = 55 # spare between bars + + month = 1 + monthly_totals = [] + check_x = column_offset + for check_x in range(column_offset, column_offset + (12 * column_increment), column_increment): # LOOP to check a year + for check_y in range(36,image_dimy): # LOOP to check a month + (curr_r, curr_g, curr_b) = pix[check_x,check_y] + if (curr_r, curr_g, curr_b) == (green_r, green_g, green_b): + # print "Month " + str(month) + " total: y=" + str(check_y) + monthly_totals.append([month,check_y]) + break + month += 1 + return monthly_totals + +def calculate_kWh_per_month(monthly_totals, y_axis_labels): + monthly_kWh = [] + for [month_num, month_y] in monthly_totals: # loop for each month + for x in range(0, len(y_axis_labels)): # x = [int kWh, int y-axis]: + if (y_axis_labels[x][1] > month_y and y_axis_labels[x-1][1] < month_y): + kWh_label_increment = y_axis_labels[x-1][0] - y_axis_labels[x][0] + y_label_increment = y_axis_labels[x][1] - y_axis_labels[x-1][1] + kWh_per_pixel = float(kWh_label_increment) / float(y_label_increment) + kWh_bonus = kWh_per_pixel * (y_axis_labels[x][1] - month_y) + kWh_this_month = kWh_bonus + float(y_axis_labels[x][0]) + monthly_kWh.append([month_num, round(kWh_this_month,2)]) + return monthly_kWh + +def fetch_bmp_url(year): + url_base = "http://192.168.0.11/pc/" + + filename_header = "graph_pc.bmp?" + filename_header_len = len(filename_header) + + html = urlopen(url_base + "?befor_hs_y_pc.html+"+year).read() + html = html.split("\r") + for line in html: + pos_of_graphic = line.find(filename_header) + if pos_of_graphic == -1: + continue + bmp_filename = line[pos_of_graphic:pos_of_graphic+filename_header_len+14] # extract substring contai$ + return url_base + bmp_filename + + + +if len(sys.argv) == 2: + year = sys.argv[1] +else: + sys.exit("Please feed me a 4-digit year as an argument.") + +bmp_url = fetch_bmp_url(year) +bmp = StringIO.StringIO(urlopen(bmp_url).read()) + +try: + im = Image.open(bmp) +except IOError as errno: + sys.exit("Error opening image:\n" + str(errno)) + +pix = im.load() # pix is array containing pixel data + +monthly_totals = detect_monthly_totals() +#print "Monthly totals [month #, kWh]:" +#print monthly_totals + +y_axis_labels = detect_y_axis_labels() +#print "y-axis label heights:" +#print y_axis_labels + +monthly_kWh = calculate_kWh_per_month(monthly_totals, y_axis_labels) + +for [month_num, month_kWh] in monthly_kWh: + print "Month " + str(month_num) + ": " + str(month_kWh) + " kWh" diff --git a/bmsh_parse-wxpython/parse_app.py b/bmsh_parse-wxpython/parse_app.py new file mode 100644 index 0000000..11ee3d0 --- /dev/null +++ b/bmsh_parse-wxpython/parse_app.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from PIL import Image +from urllib import urlopen +import datetime +import StringIO +import sys +import wx +import wx.grid + +class SharpNinja: + def return_monthly_kWh_cuz_python_is_a_bitch(self): + return self.monthly_kWh + + def __init__(self, year): + + bmp_url = self.fetch_bmp_url(year) + bmp = StringIO.StringIO(urlopen(bmp_url).read()) + + try: + im = Image.open(bmp) + except IOError as errno: + sys.exit("Error opening image:\n" + str(errno)) + + pix = im.load() # pix is array containing pixel data + + monthly_totals = self.detect_monthly_totals(pix) + #print "Monthly totals [month #, kWh]:" + + y_axis_labels = self.detect_y_axis_labels(pix) + #print "y-axis label heights:" + #print y_axis_labels + + self.monthly_kWh = self.calculate_kWh_per_month(monthly_totals, y_axis_labels) + + output = '' + for [month_num, month_kWh] in self.monthly_kWh: + print "Month " + str(month_num) + ": " + str(month_kWh) + " kWh" + output += "Month " + str(month_num) + ": " + str(month_kWh) + " kWh\n" + + def gen_sig(self, x_start, y_start, pix): # returns black pixels + sig_0 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [6, 5], [7, 5], [0, 6], [1, 6], [6, 6], [7, 6], [0, 7], [1, 7], [6, 7], [7, 7], [0, 8], [1, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_1 = [[3, 0], [4, 0], [1, 1], [2, 1], [3, 1], [4, 1], [1, 2], [2, 2], [3, 2], [4, 2], [3, 3], [4, 3], [3, 4], [4, 4], [3, 5], [4, 5], [3, 6], [4, 6], [3, 7], [4, 7], [3, 8], [4, 8], [3, 9], [4, 9], [3, 10], [4, 10], [3, 11], [4, 11], [3, 12], [4, 12], [3, 13], [4, 13], [3, 14], [4, 14]] + sig_2 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [5, 5], [6, 5], [7, 5], [4, 6], [5, 6], [6, 6], [4, 7], [5, 7], [3, 8], [4, 8], [5, 8], [2, 9], [3, 9], [4, 9], [2, 10], [3, 10], [1, 11], [2, 11], [3, 11], [0, 12], [1, 12], [2, 12], [0, 13], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [7, 13], [0, 14], [1, 14], [2, 14], [3, 14], [4, 14], [5, 14], [6, 14], [7, 14]] + sig_3 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [5, 5], [6, 5], [7, 5], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [5, 8], [6, 8], [7, 8], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_4 = [[5, 0], [6, 0], [5, 1], [6, 1], [4, 2], [5, 2], [6, 2], [4, 3], [5, 3], [6, 3], [3, 4], [4, 4], [5, 4], [6, 4], [3, 5], [4, 5], [5, 5], [6, 5], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [2, 7], [3, 7], [5, 7], [6, 7], [1, 8], [2, 8], [3, 8], [5, 8], [6, 8], [1, 9], [2, 9], [5, 9], [6, 9], [0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [0, 11], [1, 11], [2, 11], [3, 11], [4, 11], [5, 11], [6, 11], [7, 11], [5, 12], [6, 12], [5, 13], [6, 13], [5, 14], [6, 14]] + sig_5 = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [0, 3], [1, 3], [0, 4], [1, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [0, 6], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [0, 7], [1, 7], [2, 7], [5, 7], [6, 7], [7, 7], [0, 8], [1, 8], [6, 8], [7, 8], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_6 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [0, 6], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [0, 7], [1, 7], [2, 7], [5, 7], [6, 7], [7, 7], [0, 8], [1, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + sig_8 = [[2, 0], [3, 0], [4, 0], [5, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [0, 2], [1, 2], [2, 2], [5, 2], [6, 2], [7, 2], [0, 3], [1, 3], [6, 3], [7, 3], [0, 4], [1, 4], [6, 4], [7, 4], [0, 5], [1, 5], [2, 5], [5, 5], [6, 5], [7, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [0, 8], [1, 8], [2, 8], [5, 8], [6, 8], [7, 8], [0, 9], [1, 9], [6, 9], [7, 9], [0, 10], [1, 10], [6, 10], [7, 10], [0, 11], [1, 11], [6, 11], [7, 11], [0, 12], [1, 12], [2, 12], [5, 12], [6, 12], [7, 12], [1, 13], [2, 13], [3, 13], [4, 13], [5, 13], [6, 13], [2, 14], [3, 14], [4, 14], [5, 14]] + char_width = 8 + char_height = 15 + space = 2 + english_sig = "" + + for digit_num in range(1,4): + this_sig = [] + for check_y in range(y_start, y_start + char_height): + for check_x in range(x_start, x_start + char_width): + (curr_r, curr_g, curr_b) = pix[check_x,check_y] + if (curr_r, curr_g, curr_b) == (0,0,0): # if pixel is black + this_sig.append([check_x - x_start,check_y - y_start]) + + for ref_sig in (["0",sig_0], ["1",sig_1], ["2",sig_2], ["3",sig_3], ["4",sig_4], ["5",sig_5], ["6",sig_6], ["8",sig_8]): # array of known sigs added to arrays with element [0] being the English name of the number + if this_sig == ref_sig[1]: + english_sig += ref_sig[0] + + x_start += char_width + space + return int(english_sig) + + def detect_y_axis_labels(self, pix): # Detect the y_axis labels + x_offset = 38 # 38 is x coordinate of 1st character of y-axis labels + y_axis_labels = [] + for y in (29, 75, 122, 168, 214, 260, 306): # y coordinates of y-axis kWh labels + # print "Captain, our sensors detected the number: " + gen_sig(38,y) + y_axis_labels.append([self.gen_sig(38,y,pix), y + 7]) # adding 7 to mark y-coord of cooresponding black line (always 7 pixels lower than start of text label) + return y_axis_labels + + def detect_monthly_totals(self, pix): # Read the green bars and push to array + # static variables + image_dimy = 350 # height of image + (green_r, green_g, green_b) = (130,185,6) # RGB values of the deepest green value, used to detect bar heights + column_offset = 119 # starting x coord of 1st graph in bar graph + column_increment = 55 # spare between bars + + month = 1 + monthly_totals = [] + check_x = column_offset + for check_x in range(column_offset, column_offset + (12 * column_increment), column_increment): # LOOP to check a year + for check_y in range(36,image_dimy): # LOOP to check a month + (curr_r, curr_g, curr_b) = pix[check_x,check_y] + if (curr_r, curr_g, curr_b) == (green_r, green_g, green_b): + # print "Month " + str(month) + " total: y=" + str(check_y) + monthly_totals.append([month,check_y]) + break + if check_y == image_dimy - 1: # if a green bar was not discovered, insert 0 for the monthly total + monthly_totals.append([month,0]) + month += 1 + return monthly_totals + + def calculate_kWh_per_month(self, monthly_totals, y_axis_labels): + monthly_kWh = [] + for [month_num, month_y] in monthly_totals: # loop for each month + if month_y == 0: + monthly_kWh.append([month_num, 0]) + continue + for x in range(0, len(y_axis_labels)): # x = [int kWh, int y-axis]: + if (y_axis_labels[x][1] > month_y and y_axis_labels[x-1][1] < month_y): + kWh_label_increment = y_axis_labels[x-1][0] - y_axis_labels[x][0] + y_label_increment = y_axis_labels[x][1] - y_axis_labels[x-1][1] + kWh_per_pixel = float(kWh_label_increment) / float(y_label_increment) + kWh_bonus = kWh_per_pixel * (y_axis_labels[x][1] - month_y) + kWh_this_month = kWh_bonus + float(y_axis_labels[x][0]) + monthly_kWh.append([month_num, round(kWh_this_month,2)]) + return monthly_kWh + + def fetch_bmp_url(self, year): + url_base = "http://192.168.0.11/pc/" + + filename_header = "graph_pc.bmp?" + filename_header_len = len(filename_header) + + html = urlopen(url_base + "?befor_hs_y_pc.html+"+year).read() + html = html.split("\r") + for line in html: + pos_of_graphic = line.find(filename_header) + if pos_of_graphic == -1: + continue + bmp_filename = line[pos_of_graphic:pos_of_graphic+filename_header_len+14] # extract substring contai$ + return url_base + bmp_filename + + + +class MyFrame(wx.Frame): + def EvtComboBox(self, event): + year = event.GetString() + cached_record = self.output_cache.get(year) + if cached_record: + output = cached_record + else: + MySharpNinja = SharpNinja(year) + output = MySharpNinja.return_monthly_kWh_cuz_python_is_a_bitch() + for [month,kWh] in output: + self.grid.SetCellValue(month - 1, 0, str(kWh)) + self.grid.SetReadOnly(month -1 , 0, True) + self.grid.SetCellAlignment(month - 1, 0, wx.ALIGN_RIGHT, wx.ALIGN_CENTER) + self.output_cache[year] = output + + def __init__(self, parent, id, title): + wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, 600)) + first_year = 2011 + self.output_cache = {} + + # Container + vbox = wx.BoxSizer(wx.VERTICAL) + + # Label + label = wx.StaticText(self, label="年度を選んでください") + vbox.Add(label, 0, wx.ALIGN_CENTER | wx.ALL, 30) + + # Dropdown + now = datetime.datetime.now() + cb_choices = [] + for x in range(now.year, now.year - 7, -1): # display last 7 years + if x >= first_year: + cb_choices.append(str(x)) + cb = wx.ComboBox(self, 1, choices=cb_choices) + wx.EVT_COMBOBOX(self, 1, self.EvtComboBox) + vbox.Add(cb, 0, wx.ALIGN_CENTER | wx.ALL, 10) + + # Grid + self.grid = wx.grid.Grid(self) + self.grid.CreateGrid(12, 1) + self.grid.SetColLabelValue(0, "kWh") + self.grid.SetColMinimalAcceptableWidth(80) + for x in range(1,13): + self.grid.SetRowLabelValue(x - 1,str(x) + "月") + self.grid.Fit() + vbox.Add(self.grid, 0, wx.ALIGN_CENTER | wx.ALL, 10) + + # Open the curtain + self.SetSizer(vbox) + +class MyApp(wx.App): + def OnInit(self): + frame = MyFrame(None, -1, 'BM: 年間発電計算ツール') + frame.Show(True) + return True + +app = MyApp(0) +app.MainLoop() diff --git a/draw_circle-cli/.DS_Store b/draw_circle-cli/.DS_Store new file mode 100644 index 0000000..bcdcacf Binary files /dev/null and b/draw_circle-cli/.DS_Store differ diff --git a/draw_circle-cli/draw_circle-cli.py b/draw_circle-cli/draw_circle-cli.py new file mode 100644 index 0000000..fcbb951 --- /dev/null +++ b/draw_circle-cli/draw_circle-cli.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from math import sin,cos,radians + +radius = 17 +steps = 90 +angle_increment = 90/steps +grid = [] + +for n in range(0,(90/angle_increment) + 1): + angle = n * angle_increment + x = int(sin(radians(angle)) * radius) + y = int(cos(radians(angle)) * radius) + if (x,y) not in grid: + grid.append((x,y)) + +rows = [] +for row in range(radius,-1,-1): + thisrow = "" + # top half + for col in range(0,radius+1): + if(col,row) in grid: + thisrow += "O" + else: + thisrow += "." + # mirror thisrow and prefix it to thisrow (add top left quadrant) + thisrow = thisrow[1:radius+1][::-1] + thisrow + rows.append(thisrow) + +#print top hemisphere +for row in rows: + print row + +#print bottom hemisphere (reverse it -> chop first element off) +for row in rows[::-1][1:radius+1]: + print row + diff --git a/ibm_laptop/mysqldump.gz b/ibm_laptop/mysqldump.gz new file mode 100644 index 0000000..11c9012 Binary files /dev/null and b/ibm_laptop/mysqldump.gz differ diff --git a/ibm_laptop/www_root.tar.gz b/ibm_laptop/www_root.tar.gz new file mode 100644 index 0000000..462be05 Binary files /dev/null and b/ibm_laptop/www_root.tar.gz differ diff --git a/id3_renamer.pl b/id3_renamer.pl new file mode 100644 index 0000000..46bed7f --- /dev/null +++ b/id3_renamer.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use v5.18; +use Data::Dumper; + +opendir my $dh, '.'; +my @files = readdir $dh; +closedir $dh; + +for my $file (@files){ + my %bag; + next unless $file =~ m/\.mp3$/i; + my $id3out = `id3 "$file"`; + for (split "\n", $id3out){ + if(m/Track\: (\d+)/){ + $bag{'track'} = $1; + $bag{'track'} =~ s/^(\d)$/0\1/; + }; + if(m/Title\: (.+)/){$bag{'title'} = $1; + $bag{'title'} =~ s/\s*$//; + $bag{'title'} =~ tr/ /_/; + $bag{'title'} =~ tr/(/-/; + $bag{'title'} =~ tr/)//; + $bag{'title'} =~ s/\//_a.k.a._/g; + }; + } + next unless defined $bag{'track'} && defined $bag{'title'}; + my $newfile = sprintf "%s-%s.mp3", + $bag{'track'}, + $bag{'title'} + ; + printf "mv \"%s\" \"%s\"\n", $file, $newfile; +} diff --git a/id3_renamer.pl.20190820 b/id3_renamer.pl.20190820 new file mode 100644 index 0000000..46bed7f --- /dev/null +++ b/id3_renamer.pl.20190820 @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use v5.18; +use Data::Dumper; + +opendir my $dh, '.'; +my @files = readdir $dh; +closedir $dh; + +for my $file (@files){ + my %bag; + next unless $file =~ m/\.mp3$/i; + my $id3out = `id3 "$file"`; + for (split "\n", $id3out){ + if(m/Track\: (\d+)/){ + $bag{'track'} = $1; + $bag{'track'} =~ s/^(\d)$/0\1/; + }; + if(m/Title\: (.+)/){$bag{'title'} = $1; + $bag{'title'} =~ s/\s*$//; + $bag{'title'} =~ tr/ /_/; + $bag{'title'} =~ tr/(/-/; + $bag{'title'} =~ tr/)//; + $bag{'title'} =~ s/\//_a.k.a._/g; + }; + } + next unless defined $bag{'track'} && defined $bag{'title'}; + my $newfile = sprintf "%s-%s.mp3", + $bag{'track'}, + $bag{'title'} + ; + printf "mv \"%s\" \"%s\"\n", $file, $newfile; +} diff --git a/id3_renamer.pl.v1 b/id3_renamer.pl.v1 new file mode 100644 index 0000000..46bed7f --- /dev/null +++ b/id3_renamer.pl.v1 @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use v5.18; +use Data::Dumper; + +opendir my $dh, '.'; +my @files = readdir $dh; +closedir $dh; + +for my $file (@files){ + my %bag; + next unless $file =~ m/\.mp3$/i; + my $id3out = `id3 "$file"`; + for (split "\n", $id3out){ + if(m/Track\: (\d+)/){ + $bag{'track'} = $1; + $bag{'track'} =~ s/^(\d)$/0\1/; + }; + if(m/Title\: (.+)/){$bag{'title'} = $1; + $bag{'title'} =~ s/\s*$//; + $bag{'title'} =~ tr/ /_/; + $bag{'title'} =~ tr/(/-/; + $bag{'title'} =~ tr/)//; + $bag{'title'} =~ s/\//_a.k.a._/g; + }; + } + next unless defined $bag{'track'} && defined $bag{'title'}; + my $newfile = sprintf "%s-%s.mp3", + $bag{'track'}, + $bag{'title'} + ; + printf "mv \"%s\" \"%s\"\n", $file, $newfile; +} diff --git a/java-move_test/CounterThread.java b/java-move_test/CounterThread.java new file mode 100644 index 0000000..5612958 --- /dev/null +++ b/java-move_test/CounterThread.java @@ -0,0 +1,45 @@ +import java.applet.*; +import java.awt.*; + +public class CounterThread extends Applet implements Runnable +{ + Thread t; + int Count; + + public void init() + { + Count=0; + t=new Thread(this); + t.start(); + } + + public boolean mouseDown(Event e,int x, int y) + { + t.stop(); + return true; + } + + public void run() + { + while(true) + { + Count++; + repaint(); + try { + t.sleep(10); + } catch (InterruptedException e) {} + } + } + + public void paint(Graphics g) + { + g.drawString(Integer.toString(Count),10,10); + System.out.println("Count= "+Count); + } + + public void stop() + { + t.stop(); + } +} + diff --git a/java-move_test/baddy.gif b/java-move_test/baddy.gif new file mode 100644 index 0000000..e9fd224 Binary files /dev/null and b/java-move_test/baddy.gif differ diff --git a/java-move_test/ball.gif b/java-move_test/ball.gif new file mode 100644 index 0000000..7212eed Binary files /dev/null and b/java-move_test/ball.gif differ diff --git a/java-move_test/ball.java b/java-move_test/ball.java new file mode 100644 index 0000000..d25bd98 --- /dev/null +++ b/java-move_test/ball.java @@ -0,0 +1,122 @@ +import java.applet.*; +import java.awt.*; +/* I know a ball isn't a Rectangle, +* but Rectangle provides alot of useful methods/properties :) */ +class Ball extends Rectangle { + public int xdir,ydir; + public Color color; + public Ball(int size) { + xdir = 0; + ydir = 0; + this.width = size; + this.height = size; + color = Color.black; + } + public void collide(Ball b) { + this.xdir*=-1; + this.ydir*=-1; + b.xdir*=-1; + b.ydir*=-1; + } + public void check(Dimension d) { + Rectangle r = new Rectangle(d.width,d.height); + if (!r.contains(this)) { + if (this.x < 0) this.x = 0; + else if (this.x > r.width-this.width) this.x = r.width-this.width; + if (this.y < 0) this.y = 0; + else if (this.y > r.height-this.height) this.y = r.height-this.height; + if (this.x == 0 || this.x == r.width-this.width) xdir*=-1; + if (this.y == 0 || this.y == r.height-this.height) ydir*=-1; + } + } + public void move() { + this.translate(xdir,ydir); + } + public void paint(Graphics g) { + g.setColor(color); + g.fillOval(this.x,this.y,this.width,this.height); + } +} +public class Bouncy extends Applet implements Runnable { + Ball b[]; // ball for.. bouncing + Dimension d; + int w,h,collide; + Image buffer; + public void init() { + d = getSize(); + w = d.width; + h = d.height; + collide = 0; + buffer = createImage(w,h); + // now we have to make the balls with random properties + Color c[] = new Color[] {Color.red,Color.green,Color.blue,Color.cyan,Color.magenta, + Color.black,Color.pink,Color.yellow}; + b = new Ball[rand(9)+1]; // at MOST 10 balls + for (int j = 0;j < b.length;j++) { + b[j] = new Ball(rand(20)+10); // diameter is at MOST 30 + b[j].x = rand(w-b[j].width); // random x + b[j].y = rand(h-b[j].height); // random y + b[j].xdir = rand(3)+2; // random x direction + b[j].ydir = rand(3)+2; // random y direction + b[j].color = c[rand(c.length-1)]; // random color + } + new Thread(this).start(); + } + protected int rand(int r) { + return (int)Math.round(Math.random()*r); + } + public void run() { + // if you don't know about threads, + // this will confuse the snot out of you. + // so read up on threads!! + while (true) { + int j,n; + // now we update each ball position + for (j = 0;j < b.length;j++) { + // make sure the ball is in the applet + b[j].check(d); + // move the ball + b[j].move(); + // check for collisions... + for (n = 0;n < b.length;n++) { + if (n != j) { // no need to check current ball + if (b[j].intersects(b[n])) { + collide++; + b[j].collide(b[n]); // adjust x/y directions + // move both balls + b[j].move(); + b[n].move(); + } + } + } + } + Graphics g = getGraphics(); + if (g != null) paint(g); // attempt active rendering + else repaint(); // passive will work if active doesn't + try { + Thread.sleep(10); + } + catch (InterruptedException e) { + break; + } + } + } + public void paint(Graphics g) { + Graphics gfx = buffer.getGraphics(); + gfx.setColor(Color.white); + gfx.fillRect(0,0,w,h); + for (int j = 0;j < b.length;j++) { + b[j].paint(gfx); + } + gfx.setColor(Color.black); + FontMetrics f = gfx.getFontMetrics(); + gfx.drawString("Balls: "+b.length,10,h-f.getAscent()); + String s = "Collisions: "+collide; + gfx.drawString(s,w-(f.stringWidth(s)+10),h-f.getAscent()); + gfx.drawRect(0,0,w-1,h-1); + g.drawImage(buffer,0,0,null); + } + public void update(Graphics g) { + paint(g); + } +} \ No newline at end of file diff --git a/java-move_test/chicken.gif b/java-move_test/chicken.gif new file mode 100644 index 0000000..aed960d Binary files /dev/null and b/java-move_test/chicken.gif differ diff --git a/java-move_test/dirt.jpg b/java-move_test/dirt.jpg new file mode 100644 index 0000000..f1f136d Binary files /dev/null and b/java-move_test/dirt.jpg differ diff --git a/java-move_test/hello.class b/java-move_test/hello.class new file mode 100644 index 0000000..b4e4cec Binary files /dev/null and b/java-move_test/hello.class differ diff --git a/java-move_test/hello.htm b/java-move_test/hello.htm new file mode 100644 index 0000000..a5fd4bd --- /dev/null +++ b/java-move_test/hello.htm @@ -0,0 +1,19 @@ + + +My First Applet + + +This is the world's simplest applet. +

+ + + + + +

+
+ + + + + \ No newline at end of file diff --git a/java-move_test/hello.java b/java-move_test/hello.java new file mode 100644 index 0000000..fffd6af --- /dev/null +++ b/java-move_test/hello.java @@ -0,0 +1,153 @@ +import java.applet.*; // Don't forget these import statements! +import java.awt.*; +import java.awt.Rectangle; +import java.lang.*; +import java.util.Random; + + +public class hello extends Applet implements Runnable { + + Thread t; + Random generator = new Random(); + + + Image Buffer; + Graphics gBuffer; + + // for Baddies + int baddies_number = 30; + int baddies_teams_number = 2; + int baddies_angle[][] = new int[baddies_number][3]; + int baddies_size = 10; + Rectangle[] baddies = new Rectangle[baddies_number]; + + Image dirt = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dirt.jpg")); + + public void init() { + Buffer=createImage(size().width,size().height); + gBuffer=Buffer.getGraphics(); + + for (int i = 0; i < baddies_number; i++){ + baddies[i] = new Rectangle(generator.nextInt(size().width - baddies_size), generator.nextInt(size().height - baddies_size), baddies_size, baddies_size); + if (collisiontest(i) == -1){ + baddies_angle[i][0] = generator.nextInt(31) - 16; + baddies_angle[i][1] = generator.nextInt(31) - 16; + if (i <= baddies_number/2 - 1) baddies_angle[i][2] = 0; + else baddies_angle[i][2] = 1; + } + else i--; + } + t=new Thread(this); + t.start(); + + + } + + + public int collisiontest(int currentball_number){ + + for(int i = 0; i < currentball_number; i++){ + if (i != currentball_number && baddies[currentball_number].intersects(baddies[i]) == true) return i; + } + return -1; + } + + + public void battle(int ball1, int ball2) { + if (ball1 == -1) return; + // balls are same colour + if (baddies_angle[ball1][2] == baddies_angle[ball2][2]){ + if (baddies[ball1].width > baddies[ball2].width) {baddies[ball2].width = 0; baddies[ball1].height += 5; baddies[ball1].width += 5;} + if (baddies[ball1].width < baddies[ball2].width) {baddies[ball1].width = 0; baddies[ball2].height += 5; baddies[ball2].width += 5;} + if (baddies[ball1].width == baddies[ball2].width) {baddies_angle[ball1][0] *= -1; baddies_angle[ball1][1] *= -1; baddies_angle[ball2][0] *= -1; baddies_angle[ball2][1] *= -1;} + } + // balls are different colours + else { + if(baddies[ball1].width > baddies[ball2].width) {baddies[ball1].width += 5; baddies[ball1].height += 5; baddies[ball2].width = 0;} + if(baddies[ball2].width > baddies[ball1].width) {baddies[ball2].width += 5; baddies[ball2].height += 5; baddies[ball1].width = 0;} } + if(baddies[ball1].width == baddies[ball2].width) {baddies_angle[ball1][0] *= -1; baddies_angle[ball1][1] *= -1; baddies_angle[ball2][0] *= -1; baddies_angle[ball2][1] *= -1;} + + } + + + public void drawstuff() { + gBuffer.drawImage(dirt, 0, 0, this); + for (int i = 0; i < baddies_number; i++){ + if (baddies[i].width != 0){ + if (baddies_angle[i][2] == 0) gBuffer.setColor(Color.red); + if (baddies_angle[i][2] == 1) gBuffer.setColor(Color.blue); + gBuffer.fillRect(baddies[i].x,baddies[i].y,baddies[i].width,baddies[i].height); + } + } + } + + + public void paint(Graphics g) { + drawstuff(); + g.drawImage(Buffer,0,0,this); + } + + public void update(Graphics g) { + paint(g); + } + + + public void run(){ + while(true) + { + + for(int i = 0; i < baddies_number; i++){ + + if(baddies[i].width != 0){ + + + if(baddies_angle[i][0] > 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x >= size().width - baddies[i].width){ + baddies[i].x = size().width - baddies[i].width; + baddies_angle[i][0] *= -1; + } + battle(collisiontest(i), i); + } + if(baddies_angle[i][0] < 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x < 0){ + baddies[i].x = 0; + baddies_angle[i][0] *= -1; + } + battle(collisiontest(i), i); + + } + + + if(baddies_angle[i][1] > 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y >= size().height - baddies[i].height){ + baddies[i].y = size().height - baddies[i].height; + baddies_angle[i][1] *= -1; + } + battle(collisiontest(i), i); + } + if(baddies_angle[i][1] < 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y < 0){ + baddies[i].y = 0; + baddies_angle[i][1] *= -1; + } + battle(collisiontest(i), i); + + } + + } + } + + repaint(); +// for(int i = 0; i < baddies_number; i++) +// {if (baddies[i].intersects(chickenpos) == true) return; +// } + try { + t.sleep(300); + } + catch (InterruptedException e) {} + } + } + + + +} \ No newline at end of file diff --git a/java-move_test/old.hello.java b/java-move_test/old.hello.java new file mode 100644 index 0000000..08b7591 --- /dev/null +++ b/java-move_test/old.hello.java @@ -0,0 +1,180 @@ +import java.applet.*; // Don't forget these import statements! +import java.awt.*; +import java.awt.Rectangle; +import java.lang.*; +import java.util.Random; + + +public class hello extends Applet implements Runnable { + + Thread t; + Random generator = new Random(); + + + Image Buffer; + Graphics gBuffer; + boolean pressedLeft, pressedRight, pressedUp, pressedDown; + + // for Chicken + Rectangle chickenpos = new Rectangle(5,5,25,25); + int boxsize = 25; + + // for Baddies + int baddies_number = 5; + int baddies_angle[][] = new int[baddies_number][2]; + int baddies_size = 35; + Rectangle[] baddies = new Rectangle[10]; + + // for Walls + int walls_number = 3; + int walls_size = 75; + Rectangle[] walls = new Rectangle[walls_number]; + + Rectangle goal = new Rectangle(0,0,40,40); + + Image dirt = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dirt.jpg")); + Image chicken = Toolkit.getDefaultToolkit().getImage(getClass().getResource("chicken.gif")); + Image baddyimg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("ball.gif")); + + public void init() { + Buffer=createImage(size().width,size().height); + gBuffer=Buffer.getGraphics(); + + goal.x = generator.nextInt(size().width - 70) + 30; + goal.y = generator.nextInt(size().height - 70) + 30; + + for (int i = 0; i < baddies_number; i++){ + baddies[i] = new Rectangle(generator.nextInt(size().width - 30 - baddies_size) + 30, generator.nextInt(size().height - 30 - baddies_size) + 30, 35, 35); + baddies_angle[i][0] = generator.nextInt(31) - 16; + baddies_angle[i][1] = generator.nextInt(31) - 16; + } + + for (int i = 0; i < walls_number; i++){ + walls[i] = new Rectangle(generator.nextInt(size().width), generator.nextInt(size().height), walls_size, walls_size); + if (walls[i].intersects(chickenpos) == true || walls[i].intersects(goal) == true) i--; + } + + // for (int i= 0; i < walls_number; i++){ + // if (int(generator.nextInt(2)) == 0) walls[i] = new Rectangle(generator.nextInt); + // } + + t=new Thread(this); + t.start(); + + + } + + +public boolean collisiontest(int x, int y){ + + for(int i = 0; i < walls_number; i++){ + if (new Rectangle(x,y,boxsize,boxsize).intersects(walls[i]) == true) return true; + } + return false; + } + +public boolean keyDown(Event e, int key) { + if(key==Event.LEFT && chickenpos.x - 5 >= 0 && collisiontest(chickenpos.x - 5, chickenpos.y) != true) + // pressedLeft=true; + chickenpos.x = chickenpos.x - 5; + if(key==Event.RIGHT && chickenpos.x + boxsize + 5 <= size().width && collisiontest(chickenpos.x + 5, chickenpos.y) != true) + // pressedRight=true; + chickenpos.x = chickenpos.x + 5; + if(key==Event.UP && chickenpos.y - 5 >= 0 && collisiontest(chickenpos.x, chickenpos.y - 5) != true) + // pressedUp=true; + chickenpos.y = chickenpos.y - 5; + if(key==Event.DOWN && chickenpos.y + boxsize + 5 <= size().height && collisiontest(chickenpos.x, chickenpos.y + 5) != true) + // pressedDown=true; + chickenpos.y = chickenpos.y + 5; + repaint(); + return true; + } + +public boolean keyUp(Event e, int key) + { + pressedLeft=pressedRight=pressedUp=pressedDown=false; + + repaint(); + + return true; + } + + public void drawstuff() { + gBuffer.drawImage(dirt, 0, 0, this); + + gBuffer.setColor(Color.black); + gBuffer.fillRect(goal.x, goal.y, goal.width, goal.height); + gBuffer.setColor(Color.green); + for (int i = 0; i < walls_number; i++){ + gBuffer.fillRect(walls[i].x, walls[i].y, walls[i].width, walls[i].height); + } + + gBuffer.drawImage(chicken, chickenpos.x, chickenpos.y, this); + for (int i = 0; i < baddies_number; i++){ + gBuffer.drawImage(baddyimg, baddies[i].x, baddies[i].y, this); + } + } + + + public void paint(Graphics g) { + drawstuff(); + g.drawImage(Buffer,0,0,this); + } + + public void update(Graphics g) { + paint(g); + } + + + public void run(){ + while(true) + { + if (goal.contains(new Rectangle(chickenpos.x,chickenpos.y,chickenpos.width,chickenpos.height))) return; + + for(int i = 0; i < baddies_number; i++){ + + if(baddies_angle[i][0] > 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x >= size().width - baddies_size){ + baddies[i].x = size().width - baddies_size; + baddies_angle[i][0] *= -1; + } + } + if(baddies_angle[i][0] < 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x < 0){ + baddies[i].x = 0; + baddies_angle[i][0] *= -1; + } + + } + + + if(baddies_angle[i][1] > 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y >= size().height - baddies_size){ + baddies[i].y = size().height - baddies_size; + baddies_angle[i][1] *= -1; + } + } + if(baddies_angle[i][1] < 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y < 0){ + baddies[i].y = 0; + baddies_angle[i][1] *= -1; + } + + } + + } + + repaint(); + for(int i = 0; i < baddies_number; i++) + {if (baddies[i].intersects(chickenpos) == true) return; + } + try { + t.sleep(300); + } + catch (InterruptedException e) {} + } + } + + + +} \ No newline at end of file diff --git a/java/CounterThread.java b/java/CounterThread.java new file mode 100644 index 0000000..5612958 --- /dev/null +++ b/java/CounterThread.java @@ -0,0 +1,45 @@ +import java.applet.*; +import java.awt.*; + +public class CounterThread extends Applet implements Runnable +{ + Thread t; + int Count; + + public void init() + { + Count=0; + t=new Thread(this); + t.start(); + } + + public boolean mouseDown(Event e,int x, int y) + { + t.stop(); + return true; + } + + public void run() + { + while(true) + { + Count++; + repaint(); + try { + t.sleep(10); + } catch (InterruptedException e) {} + } + } + + public void paint(Graphics g) + { + g.drawString(Integer.toString(Count),10,10); + System.out.println("Count= "+Count); + } + + public void stop() + { + t.stop(); + } +} + diff --git a/java/baddy.gif b/java/baddy.gif new file mode 100644 index 0000000..e9fd224 Binary files /dev/null and b/java/baddy.gif differ diff --git a/java/ball.gif b/java/ball.gif new file mode 100644 index 0000000..7212eed Binary files /dev/null and b/java/ball.gif differ diff --git a/java/ball.java b/java/ball.java new file mode 100644 index 0000000..d25bd98 --- /dev/null +++ b/java/ball.java @@ -0,0 +1,122 @@ +import java.applet.*; +import java.awt.*; +/* I know a ball isn't a Rectangle, +* but Rectangle provides alot of useful methods/properties :) */ +class Ball extends Rectangle { + public int xdir,ydir; + public Color color; + public Ball(int size) { + xdir = 0; + ydir = 0; + this.width = size; + this.height = size; + color = Color.black; + } + public void collide(Ball b) { + this.xdir*=-1; + this.ydir*=-1; + b.xdir*=-1; + b.ydir*=-1; + } + public void check(Dimension d) { + Rectangle r = new Rectangle(d.width,d.height); + if (!r.contains(this)) { + if (this.x < 0) this.x = 0; + else if (this.x > r.width-this.width) this.x = r.width-this.width; + if (this.y < 0) this.y = 0; + else if (this.y > r.height-this.height) this.y = r.height-this.height; + if (this.x == 0 || this.x == r.width-this.width) xdir*=-1; + if (this.y == 0 || this.y == r.height-this.height) ydir*=-1; + } + } + public void move() { + this.translate(xdir,ydir); + } + public void paint(Graphics g) { + g.setColor(color); + g.fillOval(this.x,this.y,this.width,this.height); + } +} +public class Bouncy extends Applet implements Runnable { + Ball b[]; // ball for.. bouncing + Dimension d; + int w,h,collide; + Image buffer; + public void init() { + d = getSize(); + w = d.width; + h = d.height; + collide = 0; + buffer = createImage(w,h); + // now we have to make the balls with random properties + Color c[] = new Color[] {Color.red,Color.green,Color.blue,Color.cyan,Color.magenta, + Color.black,Color.pink,Color.yellow}; + b = new Ball[rand(9)+1]; // at MOST 10 balls + for (int j = 0;j < b.length;j++) { + b[j] = new Ball(rand(20)+10); // diameter is at MOST 30 + b[j].x = rand(w-b[j].width); // random x + b[j].y = rand(h-b[j].height); // random y + b[j].xdir = rand(3)+2; // random x direction + b[j].ydir = rand(3)+2; // random y direction + b[j].color = c[rand(c.length-1)]; // random color + } + new Thread(this).start(); + } + protected int rand(int r) { + return (int)Math.round(Math.random()*r); + } + public void run() { + // if you don't know about threads, + // this will confuse the snot out of you. + // so read up on threads!! + while (true) { + int j,n; + // now we update each ball position + for (j = 0;j < b.length;j++) { + // make sure the ball is in the applet + b[j].check(d); + // move the ball + b[j].move(); + // check for collisions... + for (n = 0;n < b.length;n++) { + if (n != j) { // no need to check current ball + if (b[j].intersects(b[n])) { + collide++; + b[j].collide(b[n]); // adjust x/y directions + // move both balls + b[j].move(); + b[n].move(); + } + } + } + } + Graphics g = getGraphics(); + if (g != null) paint(g); // attempt active rendering + else repaint(); // passive will work if active doesn't + try { + Thread.sleep(10); + } + catch (InterruptedException e) { + break; + } + } + } + public void paint(Graphics g) { + Graphics gfx = buffer.getGraphics(); + gfx.setColor(Color.white); + gfx.fillRect(0,0,w,h); + for (int j = 0;j < b.length;j++) { + b[j].paint(gfx); + } + gfx.setColor(Color.black); + FontMetrics f = gfx.getFontMetrics(); + gfx.drawString("Balls: "+b.length,10,h-f.getAscent()); + String s = "Collisions: "+collide; + gfx.drawString(s,w-(f.stringWidth(s)+10),h-f.getAscent()); + gfx.drawRect(0,0,w-1,h-1); + g.drawImage(buffer,0,0,null); + } + public void update(Graphics g) { + paint(g); + } +} \ No newline at end of file diff --git a/java/chicken.gif b/java/chicken.gif new file mode 100644 index 0000000..aed960d Binary files /dev/null and b/java/chicken.gif differ diff --git a/java/dirt.jpg b/java/dirt.jpg new file mode 100644 index 0000000..f1f136d Binary files /dev/null and b/java/dirt.jpg differ diff --git a/java/hello.class b/java/hello.class new file mode 100644 index 0000000..b4e4cec Binary files /dev/null and b/java/hello.class differ diff --git a/java/hello.htm b/java/hello.htm new file mode 100644 index 0000000..a5fd4bd --- /dev/null +++ b/java/hello.htm @@ -0,0 +1,19 @@ + + +My First Applet + + +This is the world's simplest applet. +

+ + + + + +

+
+ + + + + \ No newline at end of file diff --git a/java/hello.java b/java/hello.java new file mode 100644 index 0000000..fffd6af --- /dev/null +++ b/java/hello.java @@ -0,0 +1,153 @@ +import java.applet.*; // Don't forget these import statements! +import java.awt.*; +import java.awt.Rectangle; +import java.lang.*; +import java.util.Random; + + +public class hello extends Applet implements Runnable { + + Thread t; + Random generator = new Random(); + + + Image Buffer; + Graphics gBuffer; + + // for Baddies + int baddies_number = 30; + int baddies_teams_number = 2; + int baddies_angle[][] = new int[baddies_number][3]; + int baddies_size = 10; + Rectangle[] baddies = new Rectangle[baddies_number]; + + Image dirt = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dirt.jpg")); + + public void init() { + Buffer=createImage(size().width,size().height); + gBuffer=Buffer.getGraphics(); + + for (int i = 0; i < baddies_number; i++){ + baddies[i] = new Rectangle(generator.nextInt(size().width - baddies_size), generator.nextInt(size().height - baddies_size), baddies_size, baddies_size); + if (collisiontest(i) == -1){ + baddies_angle[i][0] = generator.nextInt(31) - 16; + baddies_angle[i][1] = generator.nextInt(31) - 16; + if (i <= baddies_number/2 - 1) baddies_angle[i][2] = 0; + else baddies_angle[i][2] = 1; + } + else i--; + } + t=new Thread(this); + t.start(); + + + } + + + public int collisiontest(int currentball_number){ + + for(int i = 0; i < currentball_number; i++){ + if (i != currentball_number && baddies[currentball_number].intersects(baddies[i]) == true) return i; + } + return -1; + } + + + public void battle(int ball1, int ball2) { + if (ball1 == -1) return; + // balls are same colour + if (baddies_angle[ball1][2] == baddies_angle[ball2][2]){ + if (baddies[ball1].width > baddies[ball2].width) {baddies[ball2].width = 0; baddies[ball1].height += 5; baddies[ball1].width += 5;} + if (baddies[ball1].width < baddies[ball2].width) {baddies[ball1].width = 0; baddies[ball2].height += 5; baddies[ball2].width += 5;} + if (baddies[ball1].width == baddies[ball2].width) {baddies_angle[ball1][0] *= -1; baddies_angle[ball1][1] *= -1; baddies_angle[ball2][0] *= -1; baddies_angle[ball2][1] *= -1;} + } + // balls are different colours + else { + if(baddies[ball1].width > baddies[ball2].width) {baddies[ball1].width += 5; baddies[ball1].height += 5; baddies[ball2].width = 0;} + if(baddies[ball2].width > baddies[ball1].width) {baddies[ball2].width += 5; baddies[ball2].height += 5; baddies[ball1].width = 0;} } + if(baddies[ball1].width == baddies[ball2].width) {baddies_angle[ball1][0] *= -1; baddies_angle[ball1][1] *= -1; baddies_angle[ball2][0] *= -1; baddies_angle[ball2][1] *= -1;} + + } + + + public void drawstuff() { + gBuffer.drawImage(dirt, 0, 0, this); + for (int i = 0; i < baddies_number; i++){ + if (baddies[i].width != 0){ + if (baddies_angle[i][2] == 0) gBuffer.setColor(Color.red); + if (baddies_angle[i][2] == 1) gBuffer.setColor(Color.blue); + gBuffer.fillRect(baddies[i].x,baddies[i].y,baddies[i].width,baddies[i].height); + } + } + } + + + public void paint(Graphics g) { + drawstuff(); + g.drawImage(Buffer,0,0,this); + } + + public void update(Graphics g) { + paint(g); + } + + + public void run(){ + while(true) + { + + for(int i = 0; i < baddies_number; i++){ + + if(baddies[i].width != 0){ + + + if(baddies_angle[i][0] > 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x >= size().width - baddies[i].width){ + baddies[i].x = size().width - baddies[i].width; + baddies_angle[i][0] *= -1; + } + battle(collisiontest(i), i); + } + if(baddies_angle[i][0] < 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x < 0){ + baddies[i].x = 0; + baddies_angle[i][0] *= -1; + } + battle(collisiontest(i), i); + + } + + + if(baddies_angle[i][1] > 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y >= size().height - baddies[i].height){ + baddies[i].y = size().height - baddies[i].height; + baddies_angle[i][1] *= -1; + } + battle(collisiontest(i), i); + } + if(baddies_angle[i][1] < 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y < 0){ + baddies[i].y = 0; + baddies_angle[i][1] *= -1; + } + battle(collisiontest(i), i); + + } + + } + } + + repaint(); +// for(int i = 0; i < baddies_number; i++) +// {if (baddies[i].intersects(chickenpos) == true) return; +// } + try { + t.sleep(300); + } + catch (InterruptedException e) {} + } + } + + + +} \ No newline at end of file diff --git a/java/old.hello.java b/java/old.hello.java new file mode 100644 index 0000000..08b7591 --- /dev/null +++ b/java/old.hello.java @@ -0,0 +1,180 @@ +import java.applet.*; // Don't forget these import statements! +import java.awt.*; +import java.awt.Rectangle; +import java.lang.*; +import java.util.Random; + + +public class hello extends Applet implements Runnable { + + Thread t; + Random generator = new Random(); + + + Image Buffer; + Graphics gBuffer; + boolean pressedLeft, pressedRight, pressedUp, pressedDown; + + // for Chicken + Rectangle chickenpos = new Rectangle(5,5,25,25); + int boxsize = 25; + + // for Baddies + int baddies_number = 5; + int baddies_angle[][] = new int[baddies_number][2]; + int baddies_size = 35; + Rectangle[] baddies = new Rectangle[10]; + + // for Walls + int walls_number = 3; + int walls_size = 75; + Rectangle[] walls = new Rectangle[walls_number]; + + Rectangle goal = new Rectangle(0,0,40,40); + + Image dirt = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dirt.jpg")); + Image chicken = Toolkit.getDefaultToolkit().getImage(getClass().getResource("chicken.gif")); + Image baddyimg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("ball.gif")); + + public void init() { + Buffer=createImage(size().width,size().height); + gBuffer=Buffer.getGraphics(); + + goal.x = generator.nextInt(size().width - 70) + 30; + goal.y = generator.nextInt(size().height - 70) + 30; + + for (int i = 0; i < baddies_number; i++){ + baddies[i] = new Rectangle(generator.nextInt(size().width - 30 - baddies_size) + 30, generator.nextInt(size().height - 30 - baddies_size) + 30, 35, 35); + baddies_angle[i][0] = generator.nextInt(31) - 16; + baddies_angle[i][1] = generator.nextInt(31) - 16; + } + + for (int i = 0; i < walls_number; i++){ + walls[i] = new Rectangle(generator.nextInt(size().width), generator.nextInt(size().height), walls_size, walls_size); + if (walls[i].intersects(chickenpos) == true || walls[i].intersects(goal) == true) i--; + } + + // for (int i= 0; i < walls_number; i++){ + // if (int(generator.nextInt(2)) == 0) walls[i] = new Rectangle(generator.nextInt); + // } + + t=new Thread(this); + t.start(); + + + } + + +public boolean collisiontest(int x, int y){ + + for(int i = 0; i < walls_number; i++){ + if (new Rectangle(x,y,boxsize,boxsize).intersects(walls[i]) == true) return true; + } + return false; + } + +public boolean keyDown(Event e, int key) { + if(key==Event.LEFT && chickenpos.x - 5 >= 0 && collisiontest(chickenpos.x - 5, chickenpos.y) != true) + // pressedLeft=true; + chickenpos.x = chickenpos.x - 5; + if(key==Event.RIGHT && chickenpos.x + boxsize + 5 <= size().width && collisiontest(chickenpos.x + 5, chickenpos.y) != true) + // pressedRight=true; + chickenpos.x = chickenpos.x + 5; + if(key==Event.UP && chickenpos.y - 5 >= 0 && collisiontest(chickenpos.x, chickenpos.y - 5) != true) + // pressedUp=true; + chickenpos.y = chickenpos.y - 5; + if(key==Event.DOWN && chickenpos.y + boxsize + 5 <= size().height && collisiontest(chickenpos.x, chickenpos.y + 5) != true) + // pressedDown=true; + chickenpos.y = chickenpos.y + 5; + repaint(); + return true; + } + +public boolean keyUp(Event e, int key) + { + pressedLeft=pressedRight=pressedUp=pressedDown=false; + + repaint(); + + return true; + } + + public void drawstuff() { + gBuffer.drawImage(dirt, 0, 0, this); + + gBuffer.setColor(Color.black); + gBuffer.fillRect(goal.x, goal.y, goal.width, goal.height); + gBuffer.setColor(Color.green); + for (int i = 0; i < walls_number; i++){ + gBuffer.fillRect(walls[i].x, walls[i].y, walls[i].width, walls[i].height); + } + + gBuffer.drawImage(chicken, chickenpos.x, chickenpos.y, this); + for (int i = 0; i < baddies_number; i++){ + gBuffer.drawImage(baddyimg, baddies[i].x, baddies[i].y, this); + } + } + + + public void paint(Graphics g) { + drawstuff(); + g.drawImage(Buffer,0,0,this); + } + + public void update(Graphics g) { + paint(g); + } + + + public void run(){ + while(true) + { + if (goal.contains(new Rectangle(chickenpos.x,chickenpos.y,chickenpos.width,chickenpos.height))) return; + + for(int i = 0; i < baddies_number; i++){ + + if(baddies_angle[i][0] > 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x >= size().width - baddies_size){ + baddies[i].x = size().width - baddies_size; + baddies_angle[i][0] *= -1; + } + } + if(baddies_angle[i][0] < 0) {baddies[i].x += baddies_angle[i][0]; + if (baddies[i].x < 0){ + baddies[i].x = 0; + baddies_angle[i][0] *= -1; + } + + } + + + if(baddies_angle[i][1] > 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y >= size().height - baddies_size){ + baddies[i].y = size().height - baddies_size; + baddies_angle[i][1] *= -1; + } + } + if(baddies_angle[i][1] < 0) {baddies[i].y += baddies_angle[i][1]; + if (baddies[i].y < 0){ + baddies[i].y = 0; + baddies_angle[i][1] *= -1; + } + + } + + } + + repaint(); + for(int i = 0; i < baddies_number; i++) + {if (baddies[i].intersects(chickenpos) == true) return; + } + try { + t.sleep(300); + } + catch (InterruptedException e) {} + } + } + + + +} \ No newline at end of file diff --git a/js/nabi-kitaakabane.html b/js/nabi-kitaakabane.html new file mode 100644 index 0000000..dcbaff6 --- /dev/null +++ b/js/nabi-kitaakabane.html @@ -0,0 +1,106 @@ + + + + + + +

 

+

北赤羽駅出発ナビ \(^o^)/

+ +
+ + diff --git a/local_rsync.sh b/local_rsync.sh new file mode 100644 index 0000000..f3b88a4 --- /dev/null +++ b/local_rsync.sh @@ -0,0 +1,7 @@ +#!/bin/bash +SRCROOT=/home/kairu0 +DSTROOT=/myPL/Backups +RSYNC=/usr/bin/rsync + +${RSYNC} -rl ${SRCROOT} ${DSTROOT} +# ${RSYNC} -rl --ignore-existing ${SRCROOT} ${DSTROOT} diff --git a/mpg123.sh b/mpg123.sh new file mode 100644 index 0000000..f41f567 --- /dev/null +++ b/mpg123.sh @@ -0,0 +1,18 @@ +#!/bin/bash +mpg123 -C \ +http://ice.somafm.com/secretagent \ +http://ice.somafm.com/illstreet \ +http://ice.somafm.com/groovesalad \ +http://ice.somafm.com/lush \ +http://ice.somafm.com/indiepop \ +http://ice.somafm.com/bootliquor \ +http://ice.somafm.com/suburbsofgoa \ +http://ice.somafm.com/digitalis \ +http://ice.somafm.com/covers \ +http://ice.somafm.com/tags \ +http://ice.somafm.com/poptron \ +http://ice.somafm.com/beatblender \ +http://ice.somafm.com/sonicuniverse \ +http://ice.somafm.com/dronezone \ +http://ice.somafm.com/cliqhop \ +http://ice.somafm.com/spacestation diff --git a/parse-images.cgi b/parse-images.cgi new file mode 100644 index 0000000..db02bfd --- /dev/null +++ b/parse-images.cgi @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use LWP::Simple; +use LWP::UserAgent; +use HTTP::Request; +use HTTP::Response; +use HTML::LinkExtor; # allows you to extract the links off of an HTML page. + +$URL = $ARGV[0]; + +$browser = LWP::UserAgent->new(); +$browser->timeout(10); + +my $request = HTTP::Request->new(GET => $URL); +my $response = $browser->request($request); +if ($response->is_error()) {printf "%s\n", $response->status_line;} + +$contents = $response->content(); + +my ($page_parser) = HTML::LinkExtor->new(undef, $URL); +$page_parser->parse($contents)->eof; +@links = $page_parser->links; + +foreach $link (@links) { + if($$link[2] =~ /jpg$/){ + print '

'."\n"; + } + } diff --git a/parse_images_from_html/parse_images.cgi b/parse_images_from_html/parse_images.cgi new file mode 100644 index 0000000..db02bfd --- /dev/null +++ b/parse_images_from_html/parse_images.cgi @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use LWP::Simple; +use LWP::UserAgent; +use HTTP::Request; +use HTTP::Response; +use HTML::LinkExtor; # allows you to extract the links off of an HTML page. + +$URL = $ARGV[0]; + +$browser = LWP::UserAgent->new(); +$browser->timeout(10); + +my $request = HTTP::Request->new(GET => $URL); +my $response = $browser->request($request); +if ($response->is_error()) {printf "%s\n", $response->status_line;} + +$contents = $response->content(); + +my ($page_parser) = HTML::LinkExtor->new(undef, $URL); +$page_parser->parse($contents)->eof; +@links = $page_parser->links; + +foreach $link (@links) { + if($$link[2] =~ /jpg$/){ + print '

'."\n"; + } + } diff --git a/photosort.pl b/photosort.pl new file mode 100644 index 0000000..fcc3a9e --- /dev/null +++ b/photosort.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.14; +my $binidentify = '/usr/bin/identify'; + +for my $file (<*.jpg>){ + my $cmd = sprintf "%s -format '%[exif:DateTime]' %s", $binidentify, $file; + my $outty = `$cmd`; + next if ($? != 0); + next if ($outty !~ m/^(\d{4})\:(\d{2})\:(\d{2})/); + my ($year, $month, $day) = ($1, $2, $3); + my $cmd = sprintf "mkdir -p %s/%s", $year, $month; + `$cmd`; + my $cmd = sprintf "mv %s %s/%s/", $file, $year, $month; + `$cmd`; +} diff --git a/rotate-video.sh b/rotate-video.sh new file mode 100644 index 0000000..703b9f7 --- /dev/null +++ b/rotate-video.sh @@ -0,0 +1,4 @@ +#!/bin/sh +AVCONVBIN=/usr/bin/avconv + +${AVCONVBIN} -vf "transpose=1" -vf "scale=480:-1" -i $1 $2 diff --git a/ssc_mount.sh b/ssc_mount.sh new file mode 100644 index 0000000..a308ba4 --- /dev/null +++ b/ssc_mount.sh @@ -0,0 +1,27 @@ +#!/usr/bin/expect -f + set timeout -1 + set dest_ip "203.215.131.224" + set dest_user "sburdick" + set tc_exe "/cygdrive/c/Program\\ Files/TrueCrypt/TrueCrypt.exe" + set tc_vol "c:\\Users\\sburdick\\personal_backup.tc" + set tc_vol_pass "jRqH4YsZpqwxTKULiYWqtoNz" + set dest_drv_ltr "Q" + + set action [lindex $argv 0] + if { $action=="mount" || $action=="unmount" } { + spawn ssh $dest_user@$dest_ip + expect "$ " + # try to unmount the TC volume just in case (with /s to silently die if not actually mounted) + send "$tc_exe /d Q /q /s\r" + expect "$ " + if { $action=="mount" } { + # mount the TC volume + send "$tc_exe /v \"$tc_vol\" /q /p $tc_vol_pass /l Q\r" + expect "$ " + } + } +exit + +#REFERENCE: +# /cygdrive/c/Program\ Files/TrueCrypt/TrueCrypt.exe /v "c:\Users\sburdick\personal_backup.tc" /q /p jRqH4YsZpqwxTKULiYWqtoNz /l Q +# /cygdrive/c/Program\ Files/TrueCrypt/TrueCrypt.exe /d Q /q diff --git a/ssc_rsync.sh b/ssc_rsync.sh new file mode 100644 index 0000000..e43725e --- /dev/null +++ b/ssc_rsync.sh @@ -0,0 +1,9 @@ +#!/bin/bash +DIRS=( '/home/kairu0/Documents' '/home/kairu0/Pictures' '/home/kairu0/kairu0.tc' ) +ELEMENTS=${#DIRS[@]} +for (( i=0;i<$ELEMENTS;i++)); do + rsync -r ${DIRS[${i}]} sburdick@203.215.131.224:/cygdrive/q +done + +#Reference: +# rsync -r /home/kairu0/Pictures sburdick@203.215.131.224:/cygdrive/q diff --git a/sync-to-knowing.sh b/sync-to-knowing.sh new file mode 100644 index 0000000..12e57bf --- /dev/null +++ b/sync-to-knowing.sh @@ -0,0 +1,2 @@ +#!/bin/sh +rsync -avz --group=media --chmod=ug+rw,o-rwx /home/kairu0/Pictures/album/ knowing:/home/media/Pictures/album diff --git a/systemd/sshesame.service b/systemd/sshesame.service new file mode 100644 index 0000000..a4bb7e9 --- /dev/null +++ b/systemd/sshesame.service @@ -0,0 +1,14 @@ +[Unit] +Description=SSH Honeypot +After=network.target + +[Service] +Type=simple +#ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' /home/honeypot/go/bin/sshesame +ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' /home/honeypot/go/bin/sshesame +ExecStart=/bin/su - honeypot -c "/home/honeypot/go/bin/sshesame -listen_address 192.168.0.131 -port 22 -host_key /home/honeypot/poopsalot" +#User=honeypot +#Group=honeypot + +[Install] +WantedBy=multi-user.target diff --git a/wallpaper_changer.py b/wallpaper_changer.py new file mode 100644 index 0000000..2b7ba14 --- /dev/null +++ b/wallpaper_changer.py @@ -0,0 +1,14 @@ +#!/usr/bin/python +import os, os.path, random, gconf +startdir="/home/kairu/Pictures/wtf" +gkey="/desktop/gnome/background/picture_filename" + +imgs=[] +for root, dirs, files in os.walk(startdir): + for file in files: + base, ext = os.path.splitext(file) + if ext.lower() in [".jpg", ".png", ".svg"]: + imgs.append(os.path.join(root, file)) +img = random.choice(imgs) + +gconf.client_get_default().set_string(gkey, img)