Data Visibility Abstraction
@stuartsierra
Data Visibility Abstraction @stuartsierra Being abstract is - - PowerPoint PPT Presentation
Data Visibility Abstraction @stuartsierra Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.
@stuartsierra
PERL(1) Perl Programmers Reference Guide PERL(1) NAME perl - Practical Extraction and Report Language SYNOPSIS Overview perl Perl overview (this section) perlintro Perl introduction for beginners perltoc Perl documentation table of contents Tutorials perlreftut Perl references short introduction perldsc Perl data structures intro perllol Perl data structures: arrays of arrays perlrequick Perl regular expressions quick start perlretut Perl regular expressions tutorial perlboot Perl OO tutorial for beginners perltoot Perl OO tutorial, part 1
Tie::File(3pm) Perl Programmers Reference Guide Tie::File(3pm) NAME Tie::File - Access the lines of a disk file via a Perl array SYNOPSIS # This file documents Tie::File version 0.97 use Tie::File; tie @array, 'Tie::File', filename or die ...; $array[13] = 'blah'; # line 13 of the file is now 'blah' print $array[42]; # display line 42 of the file $n_recs = @array; # how many records are in the file? $#array -= 2; # chop two records off the end for (@array) { s/PERL/Perl/g; # Replace PERL with Perl everywhere }
use XML::DOM; my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile ("file.xml"); # print all HREF attributes of all CODEBASE elements my $nodes = $doc->getElementsByTagName ("CODEBASE"); my $n = $nodes->getLength; for (my $i = 0; $i < $n; $i++) { my $node = $nodes->item ($i); my $href = $node->getAttributeNode ("HREF"); print $href->getValue . "\n"; }
<xsl:template match="/doc:article/doc:info"/> <xsl:template match="doc:link"> <xsl:element name="ulink" namespace="http://docbook.org/ns/docbook"> <xsl:attribute name="url" namespace="http://docbook.org/ns/docbook"> <xsl:value-of select="@xlink:href"/> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="doc:footnote"> <xsl:element name="footnote" namespace="http://docbook.org/ns/docbook"> <xsl:apply-templates select="*"/> </xsl:element> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
(defun breadth-first-search (start) (let ((open (list start)) ; the list of nodes to be examined (closed (list)) ; the list of nodes already examined (steps 0) ; number of iterations (expanded 0) ; total number of nodes expanded (stored 0)) ; max number of nodes stored at any one time (loop while open do (let ((x (pop open))) (when (finished? x) (return (format nil "Found ~a in ~a steps. Expanded ~a nodes, stored a maximum of ~a nodes." x steps expanded stored))) (incf steps) (pushnew x closed :test #'equal) (let ((successors (successors x))) (incf expanded (length successors)) (setq successors (delete-if (lambda (a) (or (find a open :test #'equal) (find a closed :test #'equal))) successors)) (setq open (append open successors)) (setq stored (max stored (length open))))))))
access Alexandria arnesi aromyxo bknr-utils ch-util cl-configuration cl-jpl-util cl-utilities CLLIB common-idioms de.setf.utility dso-util fare-utils Formlets fukacl hu.dwim.util incf-cl JARW kmrcl mccme-helpers metatilities metatilities-base monkeylib- utilities mop-utils my-util pergamum qtility rutils s-utils SCLF umpa-lumpa ytools
;; Association list (setq user '((name . "Stuart") (age . 24) (langs . ("XSLT" "Perl" "Lisp"))) ;; Hash table (setq user (make-hash-table)) (setf (gethash 'name user) "Stuart") (setf (gethash 'age user) 24) (setf (gethash 'langs user) '("XSLT" "Perl" "Lisp"))
(defcenum svtype :null ; undef :iv ; Scalar (integer) :nv ; Scalar (double) :rv ; Scalar (reference) :pv ; Scalar (string) :pviv ; pointer to an IV (used in hashes) :pvnv ; pointer to an NV (used in hashes) :pvmg ; blessed or magical scalar :pvbm ; ?? :pvlv ; ?? :pvav ; Array :pvhv ; Hash :pvcv ; Code reference :pvgv ; typeglob (possibly file handle) :pvfm ; ?? :pvio) ; an I/O handle?
(defun call-perl (function return-type methodp &rest args) (need-perl) (perl-scope (pushmark) (push-mortals-on-stack args) (get-stack-by-type return-type (funcall (if (stringp function) #'perl-call-function ;; either scalar string or code reference #'perl-call-scalar) function (calling-flags return-type methodp)))))
class Company < ActiveRecord::Base include Auditable belongs_to :group has_many :profiles, :dependent => :destroy has_many :users, :dependent => :destroy has_many :subscriptions, :dependent => :destroy, :order => :service_id has_many :services, :through => :subscriptions has_many :statistics, :dependent => :destroy accepts_nested_attributes_for :subscriptions, :allow_destroy => true, :reject_if => lambda{|attrs| attrs[:_create] == '0'} accepts_nested_attributes_for :users, :allow_destroy => true after_update :ensure_users_match validates_presence_of :name validates_uniqueness_of :name validate :presence_of_subscriptions default_scope :order => :name end
(map function set-of-maps) (map function (resultset-seq query)) (map function (line-seq file)) (map function (xml-seq xml-tree)) (map function (file-seq directory)) (map function list-of-vectors) (map function map-of-maps) (map function (range)) ; all integers (map function "characters in string")
(def primes (letfn [(next-prime [known-primes n] (lazy-seq (if (some #(zero? (rem n %)) known-primes) (next-prime known-primes (inc n)) (cons n (next-prime (conj known-primes n) (inc n))))))] (next-prime [] 2))) (map #(inc (* 2 %)) primes) ;;=> (5 7 11 15 23 27 35 39 47 59 ...)
user=> (def editor (d/entity db editor-id)) user=> editor ;;=> {:db/id 17592186045425} user=> (:user/firstName editor) ;;=> "Edward" user=> (:comment/_author editor) ;;=> [{:db/id 17592186045429} ...]
(defn complex-process [] (let [result (computation (get-input)] (if (condition? result) (launch-missile) (erase-hard-drive))))
(defn gather-information [state] (assoc state :analysis (computation (:input state))) (defn make-decision [state] (assoc state :response (if (condition? (:analysis state)) :launch-missile :erase-hard-drive)))
user=> (make-decision {:input "trustno1"}) ;;=> {:input "trustno1" ;; :analysis :security-breach ;; :response :erase-hard-drive}
(defn take-action [state] (case (:response state) :launch-missile (launch-missile) :erase-hard-drive (erase-hard-drive))) (defn complex-process [initial-state] (-> initial-state gather-information make-decision take-action))
(defn log [state] (logging/info state) state) (defn complex-process [initial-state] (-> initial-state gather-information make-decision log take-action))
Convert Data Convert Data Data
Interceptor T wo Interceptor Three Interceptor One
Enter Data
Response Request
Data Enter Data
Data Enter Data
Data
Interactive GUI Database Web Services Automated T ests
Interactive GUI Database Web Services Automated T ests
(hystrix/defcommand complex-command {:timeout 3000 :request-volume-threshold 10 :error-threshold-percentage 75 :sleep-window 60000} [input] ... code ... )
;; Rally the troops (defn init! [] (connect-to-database!) (create-thread-pools!) (start-background-processes!) (start-web-server!) ...)
;; System lifecycle (defrecord System [storage config web-service] Lifecycle (start [_] (start storage) (start web-service)) (stop [_] (stop web-service) (stop storage)))
;; System lifecycle (reduce (fn [system key] (update-in system [key] start)) system (dependency-sort (keys system)))