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
.force-height(@height: 100%) { | |
height: @height; | |
min-height: @height; | |
} | |
.apply(@selector: ~'', @contents){ | |
@{selector}{ | |
@contents(); | |
} | |
} |
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 django.template import Node | |
class PrettyPrintNode(Node): | |
def __init__(self, nodelist): | |
self.nodelist = nodelist | |
def render(self, context): | |
from bs4 import BeautifulSoup | |
html = BeautifulSoup(self.nodelist.render(context)) |
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
/** | |
* This utility allows us to ignore using Sahi's <browser> </browser> tags for defining functions that should be run on the browser. | |
* Instead we can simply call these utilities to pass functions back and forth between the two, which is super useful. | |
*/ | |
var $Browser = (function ($Browser) { | |
/** | |
* Adds a function to the window object on the browser side of things. | |
* | |
* @param $key - The name that should be assigned to the function on the browser. |
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 django.utils.module_loading import autodiscover_modules | |
# creating a decorator that effectively sets the 'Plug' class | |
# as the meta class and passes along the key and module | |
def Plugin(key, module): | |
class Plug(type): | |
# here because we need to allow kwargs but not pass them to the type constructor | |
def __new__(cls, name, bases, namespace, **kwargs): |
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
public final class ObjectUtils { | |
private ObjectUtils() { | |
} | |
/** | |
* Instantiate a class for the provided constructor arguments. | |
* | |
* @param clazz The class to instantiate | |
* |
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
trait Functor[F[_]] { | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Applicative[F[_]] extends Functor[F] { | |
def unit[A](a: => A): F[A] | |
def map2[A,B,C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C] | |
def map[A,B](fa: F[A])(f: A => B): F[B] = |
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
(defmacro make-model | |
[name args & body] | |
(let [defaults (if (map? (first body)) (first body) {}) | |
constructor-name (str/lower-case (str "make-" name))] | |
`(do (defrecord ~name ~args ~@(if (map? (first body)) (rest body) body)) | |
(defn ~(symbol constructor-name) | |
([] (~(symbol constructor-name) {})) | |
([values#] (~(symbol (str "map->" name)) (merge ~defaults values#))))))) |
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
(defmacro map-symbols [& symbols] | |
"Converts variadic provided symbols into a map of symbol-turned-keyword -> symbol-value" | |
(into {} (map #(hash-map (keyword (name %)) (var-get (resolve %))) symbols))) |
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
(defn aliasing [& keys-and-values] | |
"Creates a map from pairs of vector/value entries. Each entry in the vector is used as a key for the corresponding value." | |
(loop [result {} entries (into [] (partition 2 keys-and-values))] | |
(let [entry (first entries) keys (first entry) value (second entry)] | |
(if (empty? entries) | |
result | |
(recur (merge result (zipmap keys (repeatedly #(identity value)))) (rest entries)))))) |
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
(defn subtrees [tree] | |
(if (or (nil? tree) (empty? tree)) | |
'() | |
(let [parent (first tree) children (take-while list? (rest tree))] | |
(if (not-empty children) | |
(concat | |
(map #(list parent %) children) | |
(mapcat subtrees children) | |
(subtrees (drop (inc (count children)) tree))) | |
(subtrees (next tree)))))) |
OlderNewer