Skip to content

Instantly share code, notes, and snippets.

View gdeer81's full-sized avatar

Gary Deer gdeer81

View GitHub Profile
@gdeer81
gdeer81 / gist:6848b0a8cd5505804063
Created June 19, 2015 20:15
destructuring options
;;given a url of this structure <base>/Publish<type>?id=<id>&update=<1 or 0>
(def content-url "http://www.somesite.com/PublishContent?id=42&update=1")
(def article-url "http://www.somesite.com/PublishArticle?id=42&update=1")
(let [[_ type] (re-find #"Publish([Content Article]*)" content-url)
id (last (re-find #"(id=)([a-zA-Z0-9]*)" content-url))
update? (last (re-find #"(update=)(\d)" content-url))]
{:type type
:id id
:update? update?})
<!-- server passes in a collection of product maps -->
<!-- controller now sends a collection of collections of product maps, specifically (partition-all 4 products) -->
{% for product-partition in partitioned-products %}
{% for product in product-partition %}
<div class="col-sm-10 col-sm-offset-2">
<div class="row">
<div class="col-sm-3" style="height:250px;">
<p>{{product.name}}</p>
<p>Price ${{product.price}}</p>
@gdeer81
gdeer81 / euler1.clj
Created May 28, 2013 23:59
sum all numbers that are a multiple of 3 or 5 below 1000
(reduce + (flatten (conj (range 0 1000 5) (range 0 1000 3)))))
@gdeer81
gdeer81 / GroupSumKata.java
Last active December 17, 2015 20:29
Coding bat problem: codingbat.com/prob/p145416 Recursion groupSum given an array of ints, is it possible to choose a group of some of the ints so that the group sums to the given target the convention is to use a starting index so the form is fn(start int-array target) examples fn(0 [2 4 8] 10) -> true since 8+2 = 10 fn(0 [2 4 8] 9) -> false sin…
...
//omitted the ceremony code for declaring this a java class with a main method that creates a new object just to call one method
public boolean groupSum(int start, int[] nums, int target) {
// Base case: if there are no numbers left, then there is a
// solution only if target is 0.
if (start >= nums.length) return (target == 0);
// Key idea: nums[start] is chosen or it is not.
@gdeer81
gdeer81 / 2013.clj
Last active December 18, 2015 23:19
The Year as data
(ns 'gist.core
(:use [clj-time
[core]
[local]
[predicates]]))
;;create date objects for all 365 days of 2013
(def all-days
(for [month (range 1 13)
day (case month
@gdeer81
gdeer81 / quilgame.clj
Created December 9, 2013 03:19
some sample code from my experimentations with using quil for game development. very rough first cut. will evolve into something cleaner Note: This is a direct port from a Java tutorial for Processing by Jules Jacobs https://www.youtube.com/watch?v=hD8PGGly19w
(ns quilgame
(:use quil.core))
(defn setup []
(def ball-x (atom 200))
(def ball-y (atom 100))
(def speed-x (atom 10))
(def speed-y (atom 2))
(def hit (atom 0))
(def miss (atom 0)))
@gdeer81
gdeer81 / romannumeralkata.clj
Last active January 4, 2016 01:59
roman numeral kata in Clojure
;; in this kata we want to be able to convert a string to its roman numeral value
;;Roman numerals are written in descending order so we should be able to parse
;;the string and add up the values
;;the only issue is the subtraction rule
;; iv = 4
;; we'll have to split the string into a vector of characters
;; convert each of those characters into a value
;; reduce the all those values into one final value
@gdeer81
gdeer81 / bounceyball.clj
Last active December 10, 2016 07:25
bouncey ball problem with 2 different solutions
;;compare the two approaches to solving the same problem
;;A child plays with a ball on the nth floor of a big building the height of which is known
;;(float parameter "h" in meters, h > 0) .
;;He lets out the ball. The ball rebounds for example to two-thirds
;;(float parameter "bounce", 0 < bounce < 1)
;;of its height.
;;His mother looks out of a window that is 1.5 meters from the ground
;;(float parameters window < h).
;;How many times will the mother see the ball either falling or bouncing in front of the window
@gdeer81
gdeer81 / 4char_forms.txt
Created December 12, 2016 17:24
every form in clojure.core that has four characters
*in*
*ns*
aget
amap
as->
aset
atom
bean
byte
case
@gdeer81
gdeer81 / spec-coercion.clj
Last active January 23, 2017 12:49 — forked from Deraen/spec-coercion.clj
Clojure.spec coercion test
(ns spec-test.core
(:require [clojure.spec :as s]))
(defn x-integer? [x]
(if (integer? x)
x
(if (string? x)
(try
(Integer/parseInt x)
(catch Exception e