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 round_to_number(value, rounding_number): | |
| remainder = value % rounding_number | |
| rounded_down = value - remainder | |
| if remainder >= rounding_number / 2: | |
| return rounded_down + rounding_number | |
| return rounded_down | |
| assert round_to_number(1234, 500) == 1000 | |
| assert round_to_number(1250, 500) == 1500 |
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
| pwgen --ambiguous --capitalize --numerals --symbols 16 |
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
| import os | |
| import subprocess | |
| import tempfile | |
| def edit_text_with_editor(text=""): | |
| _, location_for_temp_file = tempfile.mkstemp() | |
| with open(location_for_temp_file, "r+") as temp_file: | |
| temp_file.write(text) | |
| temp_file.flush() |
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 if2 [expr cond1 cond2] | |
| `(get ~{true `'cond1 false `'cond2} ~expr)) | |
| (println (if2 (= 4 (+ 2 2)) | |
| (println "true") | |
| (println "false"))) |
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 pivot-and-rest [coll] | |
| (let [splitted (split-at (quot (count coll) 2) coll) | |
| second-part (second splitted)] | |
| [(first second-part) (concat (first splitted) (rest second-part))])) | |
| (defn quicksort [coll] | |
| (cond | |
| (empty? coll) [] | |
| (= (count coll) 1) coll | |
| :else (let [[p xs] (pivot-and-rest coll) |
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
| bat_widget = wibox.widget.textbox() | |
| function set_bat(bat_widget) | |
| local s = "" | |
| local output = io.popen("acpi"):read() | |
| if not output then | |
| s = "N/A" | |
| bat_widget:set_text(s) | |
| return | |
| end | |
| local percentage = string.match(output, ".-(%d+)%%") |
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 make_counter(n): | |
| def inner(): | |
| nonlocal n | |
| n = n + 1 | |
| return n | |
| return inner | |
| counter = make_counter(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
| / | |
| (?:(\w+)\:?\/\/)? # Protocol | |
| ([^\/?]+) # Optional subdomains, domain and TLD | |
| \/? # Traling slash | |
| ([^\?]*) # Path | |
| ([^\#]*) # Query | |
| (\#?.*) # Fragment | |
| /xu | |
| # http://regex101.com/r/oV5tN9 |
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
| @namespace url(http://www.w3.org/1999/xhtml); | |
| @-moz-document domain("news.ycombinator.com") { | |
| td[bgcolor="#ff6600"] { | |
| background-color: #efefef !important; | |
| border-radius: 4px; | |
| } | |
| a[href="news"] { |
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 counter.core | |
| (:require [om.core :as om :include-macros true] | |
| [om.dom :as dom :include-macros true])) | |
| (enable-console-print!) | |
| (def app-state (atom {:count 42})) | |
| (defn dec-button [counter owner] | |
| (reify |