Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
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
| # Example model | |
| class User(Base): | |
| __tablename__ = 'user' | |
| @classmethod | |
| def _base_filters(self, obj): | |
| # Add this method to your model if you want base filtering, otherwise leave it out | |
| # import and_ from sqlalchemy package | |
| # this is a base filter for ALL queries | |
| return and_( |
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 requests | |
| import eventlet | |
| eventlet.monkey_patch() | |
| with eventlet.Timeout(10): | |
| requests.get("http://ipv4.download.thinkbroadband.com/1GB.zip", verify=False) | |
| ##### r = requests.get("get("http://ipv4.download.thinkbroadband.c", verify=False, timeout=10) | |
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
| ## install Catalyst proprietary | |
| sudo ntfsfix /dev/sda2 | |
| sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.BAK | |
| sudo apt-get remove --purge fglrx* | |
| sudo apt-get install linux-headers-generic | |
| sudo apt-get install fglrx xvba-va-driver libva-glx1 libva-egl1 vainfo | |
| sudo amdconfig --initial | |
| ## install build essentials | |
| sudo apt-get install cmake |
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
| ;; Code for blog article at | |
| ;; http://www.lexicallyscoped.com/2015/01/05/parsing-flat-files-in-clojure.html | |
| (ns flatfile.core | |
| (:use [clojure.java.io]) | |
| (:import [java.io PushbackReader])) | |
| (defn load-rulebook [file] | |
| (with-open [r (reader file)] | |
| (read (PushbackReader. r)))) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
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
| /* | |
| TITLE: DECODER FOR HT6P20B ENCODER | |
| CREATED BY: AFONSO CELSO TURCATO | |
| DATE: 18/JUN/2014 | |
| E-MAIL: acturcato (at) gmail.com | |
| LICENSE: GPL | |
| REV.: 04 | |
| DESCRIPTION: | |
| http://acturcato.wordpress.com/2014/01/04/decoder-for-ht6p20b-encoder-on-arduino-board-english/ |
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 sample | |
| (:require [clojure-leap.core :as leap] | |
| [clojure-leap.hand :as l-hand] | |
| [clojure-leap.pointable :as l-pointable :refer [tip-position]])) | |
| (defn process-frame [frame] | |
| (let [_ (println "Frame id:" (.id frame) "timestamp:" (.timestamp frame) | |
| "hands:" (leap/hands frame) "fingers:" (leap/fingers frame) "tools:" (leap/tools frame))] | |
| (when-let [hand (and (leap/hands? frame) (leap/hand frame 0))] | |
| (let [fingers (leap/fingers hand) |
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
| -- show running queries (pre 9.2) | |
| SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
| FROM pg_stat_activity | |
| WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
| ORDER BY query_start desc; | |
| -- show running queries (9.2) | |
| SELECT pid, age(clock_timestamp(), query_start), usename, query | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
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
| require 'rubygems' | |
| require 'yaml' | |
| # A demonstration of YAML anchors, references and handling of nested values | |
| # For more info, see: | |
| # http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/ | |
| stooges = YAML::load( File.read('stooges.yml') ) | |
| # => { | |
| # "default" => { |