TinyMCE — Absolute URL Images

Add the option ‘relative_urls’: ‘false’ to disable the auto absolute-to-relative link changing behavior.

This wiki lists all types of URL converting here… but I’m still having issues. I’ve tried all of them.

I’ve heard of issues with IE auto formatting links, but I’m using Chrome. I’m trying to write an img address for a newsletter, which will obviously fail if i use a relative link.

http://wiki.moxiecode.com/index.php/TinyMCE:FAQ#Paths.2FURLs_are_incorrect.2C_I_want_absolute.2Frelative_URLs.3F

WWaaait a minute.. Why doesn’t this link fail? >_>

/blah/ is reaching my server from refreshing gmail.. does it automatically determine the domain from email headers or something??

Python on Windows — Running Python.exe From Command Prompt

If you’re wondering how to run python.exe by typing python (like in a linux box), set up an environment variable called python that targets python.exe.

The following post details how to set an environment variable.
https://yuji.wordpress.com/2009/08/31/django-on-windows-setting-path-environment-variable/

Follow the instructions, except instead of appending to the Path variable, add a new one:

  • Variable: python
  • Value: C:\Python[version]\python.exe

Start up your command prompt and type ‘python’, or ‘python _whatever_’ and the commands should work as expected.

Python — Split String in Half

Here is an easy way to split a string in two. I just have a rudimentary form collecting a full name, yet my model stores first/last names.

I’m just going to use the partition string method.

‘Yuji Tomita’.partition(‘ ‘)
returns (‘Yuji’, ‘ ‘, ‘Tomita)

‘Yuji Middlename Tomita’.partition(‘ ‘)
returns (‘Yuji’, ‘ ‘, ‘Middlename Tomita’)

Which is plenty good for me.

Python / Cryptography / Blowfish — Using Blowfish and b64decode to store encrypted data

I used this just the other day, with reference from its use in Satchmo payment processing to build a unique encrypted link for our affiliate clients.

I wanted them to have an easy, one click link that they can use to visit their information instead of having to remember a password (FAILS, unless service is important enough).

I used Blowfish in the Python Cryptography Toolkit.

import bas64from Crypto.Ciphers import Blowfish

encryption_object = Blowfish.new("my-key-of-some-kind") # keep this key.. I used the django settings.SECRET_KEY
encryption_object.encrypt() 

# requires multiple of 8 character input, so we must check if our string to encrypt is a multiple of 8 and add extra characters when it's short 
padding = ''
if (len(STRING_TO_ENCRYPT) % 8  ) <> 0    :  
    padding = 'X' * (8-(len(STRING_TO_ENCRYPT) % 8))  
    # len(STRING_TO_ENCRYPT) % 8 returns the remainder of division
    # subtracting this from 8 gives you the number needed to reach the multiple of 8.

encrypted_string = base64.b64encode(encryption_object.encrypt(STIRNG_TO_ENCRYPT+padding))
# b64encode to create a "more" url-safe string.


encryption_object.decode(base64.b64decode(encrypted_string)).rstrip('X') 


Now I can encrypt something like a slug and use it as a unique link that is only available to the person who I send the link to.

Another way I’ve done that is to use a 1 way hash: store a hash on the model of the slug and look up the DB object by hash.

I just didn’t want to add a new field and deal with updating DBs to add this feature.

Python — CSV Reader. Basic / Bare Minimum Usage

This is a quick post about the standard library ‘csv’ in python. Absolute bare minimum usage to parse some CSV.

I’ve been using this or my own version of csv to process email lists, inventory histories, etc. Any time a spreadsheet is used, you can easily save it as a csv and load it up in python.

I do a lot of number crunching / processing that’s just too complicated to do easily in a spreadsheet, but data often comes in spreadsheets.

Example of usage in the python shell:

import csv
f = open('path/to/my/file', 'r') # open the file
reader = csv.reader(f)
reader.next() # prints the next ROW, as a list.
for row in reader:
         name = row[0]
         email = row[1]
         if email_validation(email): 
               #  do some logic to check against an ignore list, or what have you.
               save_email_or_smth(email, name)
f.close() # close the file.

Python / SQL — Remove all non ASCII characters from unicode string

Here’s a brute force method to force a unicode string to ASCII by removing all non ascii characters from a unicode string for those pesky Ordinal Not In Range errors or DB errors.

Though I found comprehensive solutions that replace the non ASCII characters and such with approximate values, I just wanted to get rid of them, ASAP, Yesterday.

''.join([x for x in 'YOUR_STRING' if ord(x) < 128])

Ending of Genshiken Explanation

The ending of Genshiken, my favorite manga explained.

Note: Chapter 56 is out there! Email me if you need it.

The ending:

I wondered what it meant at first, and I even looked it up online hoping for an answer. At the very last page of chapter 55, Ogiue is observing “I don’t think Kasukabe senpai realizes just how sensitive she is to conversations like this…”

I just came up with an interpretation that ends the whole series on a great note, summing up the whole message all along: that despite their differences these guys have mutually accepted (and respect) each other.


The very last page:

The top frame starts after Kousaka tells Kasukabe that she has no “moe”. She’s shocked (a “gaan..” reaction, not real shock) and responds with a smiling “hmph”.  The expression shows she’s not pissed.

The little sister is having fun watching this chaos (just like this interaction has happened before) but, this time it’s a little different: Ohno responds that it’s not fair not all that seriously, but I think the point here is to show she has respect for Kasukabe. The usual would be to do a “tsukkomi” and pitch into the mayhem for kicks.

Ogiue then pitches in, saying “you know.. I’ve always noticed..”  (getting ready for the last line in the damn series!)

The next frame has no text and no eyes to emphasize the group atmosphere. Kasukabe is yelling something (smiling) at the 3 on the right, who are all smiling.

The last frame is Kasukabe who looks back at the reader, still smiling, saying “huh?”

I wondered what this meant. They built up to the Kasukabe point so I wondered and wondered. This time, I get it.


The point?

The girls are commenting on how Kasukabe is actually sensitive to “conversations like these” — those being the otaku ish conversations. The series starts with Kasukabe being hostile to the otakus, wanting nothing to do with them (only trying to drag her boyfriend out of otakudom), being embarrassed about associating with them, etc.

The series ends with her actually being a part of the group. It’s mutual friendship / respect.  The moe comment was about that: she wouldn’t have cared at all about a comment like that at the beginning of the series. She might have even punched one of the characters for it : ).

I think that’s why she’s with the 3 characters she least converses with/ have the most Otaku specific personalities for the final scene. For example Kanji is purposely left out because I think as the main character, he would take away from the power of this scene if he was in the last page, since his presence kinda justifies any conversation.

“sensitive to conversations like these…” : you can’t be sensitive to conversations like the moe comment if you don’t give a crap about moe, or the people who you’re talking to.

The most important frame is the 2nd to last frame (there’s a lot to interpret in it): the 3 girls have the “drop” implying they are observing something very obvious. The 5 in the back are in their own world. Kasukabe is all heated up about the “usual” conversation. She totally gets along.

That is the meaning behind Ogiue’s comment about her being sensitive to “conversations like these”, followed by a full width shot of Kasukabe smiling.

The first time I read this, I thought the author was going for a “life goes on” kinda ending with no resolution on purpose. Turns out there is indeed a resolution, and a great one at that! The message of the whole series is finalized here.

I wish it wasn’t over : ( I am clearly trying to pretend its not. I do have chapter 56 left to read, and I’m stashing it next to my crack. I will re-read the first 55 to get to 56 :3

To quote a memorable comment:

“I have to say, I’m taking the end of Genshiken surprisingly badly. I feel like a heroin addict who’s just been told that I’ve taken the last hit on the planet.”

BAH!

Django — MediaDefiningClass object is not iterable

For me, the cause of this error was sending arguments to the register function in the wrong order.

Check the order of registering a ModelAdmin: it’s the model class first, then the ModelAdmin class.

Example: admin.site.register(Model, ModelAdmin)

I suppose naturally the second one has to be the ModelAdmin since register(MyModel) works as well. That’s one good way to think about it.

Mastercam Gotcha: Two Same Contour Toolpaths / Different Bit Sizes Ruins Verify

If you have two contour toolpaths using the exact same drive chain and the verify is showing a ledge when it shouldn’t, it’s because the tolerances in the verify settings and not an actual deviation in the real toolpath.

0.01 tolerance on a .1 bit will render a slightly different verify than 0.01 tolerance on a 1.0 bit resulting in a ledge if you only have the smaller bit cutting deeper.

This can be reproduced: create 1 line anywhere.

Run a contour toolpath with your larger bit with any settings to any depth.

Right click-drag to copy the toolpath, and only change the tool to a new bit .1 SMALLER than the previous operation, and change the depth to go DEEPER.

Example:
.5 bit, -.25 depth for Contour1
.4 bit, -.5 depth for Contour2

Verify will show a ledge, when the real machine path will have none, as you might expect.

Tightening the tolerances will make the ledge smaller and smaller, but it’s still there.

I feel like relying on verify like it represents reality exactly has caused me the most trouble.