This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base import * | |
DEBUG = True | |
TEMPLATE_DEBUG = DEBUG | |
PROJECT_DIR = "/path/to/project/directory/" | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simpler pivot table for non-python people. | |
Pythonisms present: | |
1. You can iterate over a list of tuples using `for ... in` and map each tuple to a variable. | |
2. Dicts exist and are great. | |
3. Iterating over a dict returns the key. | |
4. Attempting to access a variable that doesn't exist in a dict raises a KeyError. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def take_screenshot(): | |
""" | |
Use GTK to get a screengrab of the current screen. | |
Returns an (x, y, 3) full-color pixel array | |
""" | |
w = gtk.gdk.get_default_root_window() | |
sz = w.get_size() | |
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotDiamondDashException(Exception): | |
pass | |
def crop_dd_screenshot(pixarray): | |
""" | |
If there is no stored index, load the reference .png, | |
find it in the current screen, and get the coordinates. | |
If the reference is not found, raise a | |
NotDiamondDashException so we know we're not looking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Color of each block at 10, 10 | |
COLORS = ( | |
(158, 221, 255), # Diamond | |
(247, 183, 0), #Yellow | |
(1, 185, 1), # Green | |
(186, 115, 255), # Purple | |
(242, 0, 16), # Red | |
(6, 104, 253)) # Blue | |
def downsample_pixarray(pixarray, factor=40.): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_largest_contiguous_region(countsarray): | |
""" | |
Find the contiguous regions in countsarray using the modified | |
flood count algorithm described in get_flood_count | |
""" | |
Q = countsarray.copy() | |
points_checked = [] | |
rows, cols = Q.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test-app.core) | |
(defn fact [x] (reduce * (range 1 (inc x)))) | |
(fact 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns find-m-files | |
(:import java.io.File)) | |
; Wrap java.io.file methods | |
(defn is-file? [f] (.isFile f)) | |
(defn is-dir? [f] (.isDirectory f)) | |
(defn get-name [f] (.getName f)) | |
(defn get-path [f] (.getPath f)) | |
(defn get-m-files [d] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Short answer: use import to import a given class | |
; In java: | |
; import java.io.File; | |
(import java.io.File) | |
; Preferred: put it in your ns | |
(ns my-namespace | |
(:import java.io.File)) | |
; Instantiate an object with an argument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pegdown-test | |
(:import org.pegdown.PegDownProcessor)) | |
(defn markdown-to-html [md] | |
(let [pd (PegDownProcessor.)] | |
(.markdownToHtml pd md))) |
OlderNewer