Wednesday, March 12, 2014

How to remove parts of string in Python

Here's an example how to remove a substring from a string. It utilizes the replace function of the Python string.

str = 'something something <remove> something </removealso> yeah! <remove>'
str = str.replace('<remove>', '')
str = str.replace('</removealso>', '')

You can do it also like this:

str = 'something something <remove> something </removealso> yeah! <remove>'
str = str.replace('<remove>', '').replace('</removealso>', '')

Friday, December 13, 2013

AutoHotKey examples

AutoHotKey is a very useful scripting tool for creating macros. Here's some example code snippets for you!

Message box:

MsgBox Hello, world!

Message box with cancel. Pressing the Cancel button will stop the current script.

MsgBox, 1,, Do you really want to start this operation?
IfMsgBox, Cancel

Setting a variable. This will wait for 2 seconds.

DelayMilliseconds = 2000
Sleep DelayMilliseconds

Sending keypresses to the currently active window. Explanations as comments after the semicolon.

Send {Enter}
SendRaw Hello ;Sends the text "Hello"
Send {LAlt} ;Left alt
Send {Del}
Send ^a ;Ctrl+a
Send !a ;Alt+a
Send {Home}
Send {F10}

Searching for and activating windows that begin with a certain string:

SetTitleMatchMode 1 ;search windows beginning with the string
IfWinExist Internet Explorer
    WinActivate ;This will activate the window that was last searched for

    ;Add code here...

Checking if a window is NOT active:

If !WinActive("Internet Explorer")
       MsgBox Error, window not active

Responding to keypress F12:

MsgBox you pressed F12!

Responding to keypress Win+a:

MsgBox you pressed Win+a!

Thursday, April 11, 2013

haXe flixel installation tutorial

So you have installed Haxe NME and want to try the Haxe port of the great flixel game library?

Open up a command-line prompt and type

haxelib install flixel

It's really that simple!

Friday, April 5, 2013

python - random integer examples

Here's some helpful functions for generating random integers in python.

This has been tested on Python 2.7, but should work on newer Pythons also. Please comment if you run across any problems!

First, you have to import the random library.

import random

If you don't have it already in your library, download and place it in the same folder as your python script.

The nice documentation for the random library can be found here.

Now you can generate floating point (float) random numbers from 0.0 to 1.0 with the command


If you're looking for a way to generate random integers, here's a couple of ready functions for you!

# returns random integer from -variation to +variation
def rando(variation):
    return int(round((random.random()*2-1)*variation))

# random integer, from zero to maxval
def randzv(maxval):
    return int(round(random.random()*maxval))

# random integer, from minval to maxval
def randminmax(minval, maxval):
    return int(round(minval + random.random()*(maxval-minval)))

Hope this hels someone!

Wednesday, March 27, 2013

python - current date and time example

Here's a code example showing how to create date & time strings.

# first, we need to import the datetime module
# in order to use date & time functions.
import datetime

# create and print string example #1
timestring ="%Y-%m-%d-%H%M")

# create and print string example #2
timestring ="%Y-%m")

# append a text to the end of string example #2
timestring = timestring + "-logfile.txt"

Here's what the output will look like:


More info on how to format the datetime string can be found here.

Hope this helps you!