Skip to content

Instantly share code, notes, and snippets.

View kyptin's full-sized avatar

Jeff Terrell kyptin

View GitHub Profile
@ghoseb
ghoseb / ns-cheatsheet.clj
Last active May 20, 2024 13:01 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
@nikolaplejic
nikolaplejic / core.clj
Created September 2, 2010 17:54
File upload example in Compojure
(ns fileupload.core
(:use [net.cgrand.enlive-html
:only [deftemplate defsnippet content clone-for
nth-of-type first-child do-> set-attr sniptest at emit*]]
[compojure.core]
[ring.adapter.jetty])
(:require (compojure [route :as route])
(ring.util [response :as response])
(ring.middleware [multipart-params :as mp])
(clojure.contrib [duck-streams :as ds]))
@mikelikesbikes
mikelikesbikes / gist:2297685
Created April 4, 2012 04:21
Base62 encoding
(def alphabet "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
(defn encode [i, alphabet]
(reduce #(str (nth alphabet (last %2)) %) ""
(take-while
#(not= [0 0] %)
(rest
; this is the magic (creates a lazy sequence of tuples, consisting of quot and mod)
(iterate
(fn [[i _]]
@gbarrancos
gbarrancos / gist:3277138
Created August 6, 2012 17:57
7 Tips for Successful Self Learning

7 Tips for Successful Self Learning - by Bradford Cross

No matter what, you're going to have to learn most everything on your own anyway. Self-learning is hard. Regardless of where, when or how you learn - being a good self-learner will maximize your potential.

In this post, Hamilton Ulmer (an almost-done Stanford stats masters student) and I, will explore seven ways to become a great self-learner.

The longest path is the shortest and the shortest path is the longest

@semperos
semperos / clojure-deftype-scaffolding.clj
Created October 4, 2012 18:16
Clojure Scaffolding for deftype (Christophe Grand) - Show which methods a class implements and for which interfaces
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
@edw
edw / delete-recursively.clj
Last active November 12, 2021 20:31
To delete a directory recursively in Clojure.
(defn delete-recursively [fname]
(let [func (fn [func f]
(when (.isDirectory f)
(doseq [f2 (.listFiles f)]
(func func f2)))
(clojure.java.io/delete-file f))]
(func func (clojure.java.io/file fname))))
@demisx
demisx / active_record_objects_autosave.md
Last active July 4, 2024 14:20
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
@Integralist
Integralist / Ruby Lambdas.md
Last active August 8, 2023 05:10
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@jgrimes
jgrimes / gist:c0e048c8a0b8bc9efd7b
Last active August 29, 2015 14:16
reducing multiple functions
lambda.match> (time (sidelong-count-and-sum (range 100000000)))
"Elapsed time: 89361.517429 msecs"
[100000000 4999999950000000]
lambda.match> (time (reduce #((juxt
(partial (fn [x y] (+ x 1)) (first %)) ; count
(partial + (second %))) ; sum
%2)
[1 0]
(range 1 100000000)))
@booch
booch / HTML_Templating_Patterns.md
Last active January 8, 2023 03:29
HTML Templating Patterns

HTML Templating Patterns

I've decided to try documenting the different patterns used in HTML templates. By HTML templates, I mean taking some HTML(ish) text, and inserting dynamically-generated content. This templating can take place on the web server or in the browser; the patterns don't usually differ between the two.

Delimited HTML