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
(ns days360.core | |
(:require [clj-time.core :as t] | |
[clj-time.format :as f] | |
[clj-time.predicates :as p] | |
[clj-time.periodic :as per])) | |
;; It works! Now to prettify it... | |
(defn days360 | |
"Calculates the number of days between a start-date and end-date according to | |
a 360-day year." |
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
;; We can go further and use automatic gensyms provided | |
;; by Clojure when use a hashtag after the symbol we | |
;; want gensymed | |
(defmacro nif | |
[expr pos zero neg] | |
`(let [e# ~expr] | |
(cond | |
(pos? e#) ~pos | |
(zero? e#) ~zero |
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
;; WIP... | |
(defn quote-units | |
[units] | |
(let [syms (filter symbol? units) | |
vals (filter number? units)] | |
(interleave (map (fn [u] `'~u) syms) vals))) | |
(defmacro defunits | |
[quantity base-unit & units] |
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
(set-env! | |
:source-paths #{"javasrc"} | |
:resource-paths #{"src/pnmacmodel" "src/movr2"} | |
:repositories [["releases" {:url "http://es-ubu-archiva-d-2.pnmac.com:8080/repository/internal" | |
:creds :gpg}] | |
["snapshots" {:url "http://es-ubu-archiva-d-2.pnmac.com:8080/repository/snapshots" | |
:creds :gpg}] | |
["clojars" {:url "https://clojars.org"}]] | |
:dependencies '[[org.clojure/clojure "1.7.0"] | |
[com.taoensso/nippy "2.5.2"] |
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
def chop(int, array_of_int) | |
return -1 if array_of_int.empty? | |
@max ||= array_of_int.size - 1 | |
@min ||= 0 | |
@mid ||= @max / 2 + @min | |
return @mid if int == array_of_int[@mid] | |
return -1 if @mid == @max |
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 is-even? [n] | |
(if (= n 0) | |
(not false) | |
(recur (is-even? (dec n))))) | |
(meditations | |
"Recursion ends with a base case" | |
(= true (is-even? 0)) | |
"And starts by moving toward that base case" |
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
;; Earlier attempt | |
(defn factorial [n] | |
(loop [n n | |
result n] | |
(if (<= n 1) | |
1 | |
result) | |
(recur (dec n) (* result (dec n))))) | |
;; Working so far |
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
# | |
# PURPOSE: | |
# The purpose of this script is to generate a list of commands to delete unused access rules from a | |
# Cisco PIX or ASA firewall. This script is appropriate if you use the RedSeal application: | |
# http://www.redsealnetworks.com. Currently the results are printed to the screen only. | |
# | |
# INSTRUCTIONS: | |
# When you want to clean up unused rules on a firewall. Use the RedSeal application to run a cleanup: | |
# Tools > Manage Device Cleanup (Alt+T, C). When finished, export the results as a CSV file. Don't | |
# forget to include the .CSV extension. Run this script and type the name of the file with the |
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
module ApplicationHelper | |
def highlight_tag_if(condition, tag, &block) | |
if condition | |
content_tag tag, :class => 'hilite', &block | |
else | |
content_tag tag, &block | |
end | |
end | |
end |
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
class Movie < ActiveRecord::Base | |
def self.all_ratings | |
# debugger | |
find_by_sql("SELECT DISTINCT rating FROM movies").map(&:rating) | |
end | |
end |
OlderNewer