This file contains hidden or 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
# -*- mode: python; coding: utf-8; -*- | |
# (def nbr-deltas [[-1 -1][-1 0][-1 1][0 -1][0 1][1 -1][1 0][1 1]]) | |
# (defn nbr-cells [[x y]] (map (fn [[a b]] [(+ x a)(+ y b)]) nbr-deltas)) | |
# (defn cell-table [cell] (apply conj {cell 10} (map #(vec [% 1]) (nbr-cells cell)))) | |
# (defn all-table [cells] (apply merge-with + (map cell-table cells))) | |
# (defn next-gen [cells] (keys (filter #(#{3 12 13} (second %)) (all-table cells)))) | |
# (defn n-next-gen [n cells] (if (== n 0) cells (recur (- n 1) (next-gen cells)))) | |
# (def r-pentomino [[0 1][1 1][2 1][1 2][2 0]]) |
This file contains hidden or 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
address_dispatch_table = {} | |
class MetaDownloadAgent(type): | |
def __new__(cls, name, bases, attributes): | |
return super(MetaDownloadAgent, cls).__new__(cls, name, bases, attributes) | |
def __init__(self, name, bases, attributes): | |
super(MetaDownloadAgent, self).__init__(name, bases, attributes) | |
if 'address_pattern' in attributes: | |
address_dispatch_table[attributes['address_pattern']] = self |
This file contains hidden or 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 wins(grid): | |
rows = [[grid[i+j] for j in 0, 1, 2] for i in 0, 3, 6] | |
cols = [[grid[i+j] for j in 0, 3, 6] for i in 0, 1, 2] | |
digs = [[grid[i] for i in 0, 4, 8], [grid[i] for i in 2, 4, 6]] | |
return any(all(cell is 'x' for cell in row) or | |
all(cell is 'o' for cell in row) | |
for row in rows + cols + digs) | |
def full(grid): | |
return all(cell is 'x' or cell is 'o' for cell in grid) |
This file contains hidden or 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
(defmacro defhook [name qualifier target args & body] | |
(let [key# (keyword name)] | |
`(add-hook ~qualifier ~target ~key# (fn ~args ~@body)))) | |
(defn run [{:as a :keys [strategy run-atom]}] | |
(when (run? a) (throw (Exception. "Cannot run agent while it is running."))) | |
(when (dead? a) (throw (Exception. "Cannot run dead agent."))) | |
(try (reset! run-atom true) | |
(let [action (strategy a)] |
This file contains hidden or 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
;;; -*- mode: clojure; coding: utf-8 -*- | |
;; Copyright (C) 2010 Roman Zaharov <[email protected]> | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
(ns log | |
(:use |
This file contains hidden or 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
(defmacro when-supplied [& clauses] | |
(if (not clauses) true | |
`(and (or (nil? ~(first clauses)) | |
(do ~(second clauses))) | |
(when-supplied ~@(next (next clauses)))))) | |
(defn make-download-agent | |
[line & {:as opts :keys [environment strategy precedence path name]}] | |
{:pre [(when-supplied strategy (instance? clojure.lang.IFn strategy) | |
precedence (number? precedence) |
This file contains hidden or 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
(defn as-file | |
[arg & {:as args :keys [exists create readable writeable directory]}] | |
(let [argtype (type arg)] | |
(cond (= argtype File) | |
(let [maybe-exists | |
(fn [f] (cond (= exists true) (when (.exists f) f) | |
(= exists false) (when-not (.exists f) f) | |
(not exists) f)) | |
maybe-directory | |
(fn [f] (cond (= directory true) (when (.isDirectory f) f) |
This file contains hidden or 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
action a > a | |
strategy a > action | |
schedule strategy > strategy | |
schedule strategy > strategy a > action a | |
(defn schedule-strategy [strategy] | |
(fn scheduled-strategy [a-stgy] | |
(fn scheduled-action [a-actn] | |
((strategy a-actn) a-actn)))) |
This file contains hidden or 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
#!/bin/bash | |
########################### | |
### Copyright Denis Popov 2010 ## | |
### Downloader files from ## | |
### The HTTP/FTP ## | |
########################### | |
get_information() | |
{ | |
dirdownload=$(zenity --entry --title "Quadregus Downloader" --text "Write folder for downloading file" --width 300) |
This file contains hidden or 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 gae-app.core | |
(:gen-class :extends javax.servlet.http.HttpServlet) | |
(:use [compojure.http.servlet :only (defservice)]) | |
(:use compojure.http.routes) | |
(:use [hiccup.core :only [h html]] | |
[hiccup.page-helpers :only [doctype include-css link-to xhtml-tag]] | |
[hiccup.form-helpers :only [form-to text-area text-field]]) | |
(:import (com.google.appengine.api.users UserServiceFactory |