Thursday, August 28, 2014

I keep losing bits of code that do this. I like to make my brain work while it reads. I get bored with the act of reading quickly sometimes. This puts a complete halt to the boredom/lack of challenge.


$filename = "C:\Users\Ogre\Documents\Calibre Library\Catch-22\Joseph Heller (30)\Joseph Heller - Catch-22.txt"
$text = [System.IO.File]::ReadAllText($filename);
$output = ""
for($i = 0; $i -lt $text.Length; $i++){
 $currentAsciiValue = [int]$text[$i];
 
 if($currentAsciiValue -gt 64 -and $currentAsciiValue -lt 91) {
  $output += [char]($currentAsciiValue + 1)
 } elseif($currentAsciiValue -gt 96 -and $currentAsciiValue -lt 123) {
  $output += [char]($currentAsciiValue + 1)
 } else {
  $output += [char]($currentAsciiValue)
 }
}
$output >> Catch22Ciphered.txt

Saturday, May 17, 2014

Sketchup Plugin #1


Here's the ruby that I wrote for a plugin for Sketchup.


require 'sketchup' def do_curve(x) a1 = 0 a2 = 0 a3 = 4.7173806e-006 a4 = -1.13578e-007 a5 = 8.4145793e-010 r = -1.111234 c = 1.0/r k = -3.739907 return (c * x * x) / (1 + (1 - (1 + k) * c * c * x * x) ** 0.5) end def draw_curve model = Sketchup.active_model entities = model.entities model.start_operation "DrawCurve" last_num = 0 last_y = 0 for i in -1000 .. 1000 floati = i.to_f / 100 y = do_curve(floati) if i != -1000 Sketchup.active_model.entities.add_line [floati, y, 0], [last_num, last_y, 0] end last_num = floati last_y = y end model.commit_operation end UI.menu("PlugIns").add_item("Draw Curve") { draw_curve } #draw_curve
I used this to draw a curve in sketchup, which I turned into a 3d shape to print out on my 3d printer.

This represents some interesting skills that I've acquired.
1) The ability to program in Ruby, or rather the skill to write a short program in an unknown language in about an hour.
2) The ability to programmatically control a 3d modelling program, in this case sketchup.
3) The ability to turn that 3d model into a physical object, using a 3d printer.


Tuesday, March 25, 2014

Dilbert Me in F#

This is the Dilbert download tool in F#, just because I like playing with F# and making up reasons to do so.

I switched to WebClient here instead of WebRequest. It makes things a little easier and I clearly should have been using it all along.

I wrote it in Visual Studio 2013 as a F# script file. I selected all then hit 'alt+enter' to run it.

FsLight was what I was led to when googling F# code formatters. It was easy to use and seems to have done a good job.

1
2
3
4
5
6
7
8
let webClient = new System.Net.WebClient()
let url = "http://www.dilbert.com"
let dilbert = webClient.DownloadString(url)
let innerUrl = "http://www.dilbert.com/" + System.Text.RegularExpressions.Regex.Match(dilbert, "src=.*strip.gif").Value.Substring(5)
innerUrl
let innerTempFile = System.IO.Path.GetTempFileName() + ".gif"
webClient.DownloadFile(innerUrl, innerTempFile)
System.Diagnostics.Process.Start(innerTempFile)
Created with FsLight

Monday, March 17, 2014

Dilbert Me 2

The previous powershell script for dilbert broke. It seems the cartoons aren't sequential. This is try #2. 

$url = "http://www.dilbert.com" 
$httpRequest = [Net.WebRequest]::create($url)

$response = $httpRequest.GetResponse()
$stream = $response.GetResponseStream()
$buffer = @()
$binaryReader = New-Object System.IO.BinaryReader($stream)

$tempBuffer = $binaryReader.ReadBytes(1024)
while($tempBuffer.Length -eq 1024) { 
    $buffer += $tempBuffer
    $tempBuffer = $binaryReader.ReadBytes(1024)
}

$dilbert = [System.Text.ASCIIEncoding]::UTF8.GetString($buffer)

$url = "http://www.dilbert.com/" + [System.Text.RegularExpressions.Regex]::Match($dilbert, "src=.*strip.gif").Value.Substring(5)

$url 

$httpRequest = [Net.WebRequest]::create($url)

$response = $httpRequest.GetResponse()
$stream = $response.GetResponseStream()
$buffer = @()
$binaryReader = New-Object System.IO.BinaryReader($stream)

$tempBuffer = $binaryReader.ReadBytes(1024)
while($tempBuffer.Length -eq 1024) { 
    $buffer += $tempBuffer
    $tempBuffer = $binaryReader.ReadBytes(1024)
}

$buffer += $tempBuffer
$tempFile = [System.IO.Path]::GetTempFileName() + ".gif"
[System.IO.File]::WriteAllBytes($tempFile, $buffer)
.$tempFile

Tuesday, March 11, 2014

Dilbert Me!

My RSS reader (feedly) doesn't handle Dilbert well. Probably because they want me to view all the advertising surrounding the daily Dilbert cartoon. So it opens up an external browser and forwards me to Dilbert.com from the RSS reader. This is annoying. This powershell script opens up today's Dilbert and shows just the strip. I should wrap this in it's own RSS feed... eventually

$startDate = New-Object DateTime(1425, 9, 14)
$days = [DateTime]::Now.Subtract($startDate).Days
$hundredThousands = [Math]::Floor( $days / 100000)
$tenThousands = [Math]::Floor( ($days % 100000)/10000)
$thousands = [Math]::Floor( ($days % 10000)/1000)
$hundreds = [Math]::Floor( ($days %1000) /100)
$remainder = [Math]::Floor( ($days %100))
#http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/200000/10000/4000/900/214940/214940.strip.gif
$url = "http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/" + $hundredThousands + "00000/" + $tenThousands + "0000/" + $thousands + "000/" + $hundreds + "00/" + $days + "/" + $days + ".strip.gif"

$httpRequest = [Net.WebRequest]::create($url)

$response = $httpRequest.GetResponse()
$stream = $response.GetResponseStream()
$buffer = @()
$binaryReader = New-Object System.IO.BinaryReader($stream)

$tempBuffer = $binaryReader.ReadBytes(1024)
while($tempBuffer.Length -eq 1024) { 
 $buffer += $tempBuffer
 $tempBuffer = $binaryReader.ReadBytes(1024)
}

$buffer += $tempBuffer
$tempFile = [System.IO.Path]::GetTempFileName() + ".gif"
[System.IO.File]::WriteAllBytes($tempFile, $buffer)
.$tempFile

Wednesday, March 5, 2014

Drawing in a canvas.

I created an html 5 canvas object.
Mouse down to draw in it.

Sadly, this only works if it is the only post viewed.
JSFiddle was very useful in debugging this and getting it to work. I did the development on a PC, and tested the results immediately in a browser on a tablet and on my phone.