Skip to content

Instantly share code, notes, and snippets.

View frankhale's full-sized avatar
🎮
writing games

Frank Hale frankhale

🎮
writing games
View GitHub Profile
@frankhale
frankhale / dir-walk.clj
Last active December 28, 2015 09:19
(learning Clojure) So I need a function that walks a set of directories and recursively gets the files paths contained in them. Here is my attempt.
;
; Still learning Clojure...
;
; Walk a directory or a series of directories and return a map of their files paths
;
; I initially started with the directory walk example here:
;
; http://rosettacode.org/wiki/Walk_a_directory/Recursively#Clojure
;
(defn walk [dirpaths pattern]
@frankhale
frankhale / get-filenames.clj
Last active December 28, 2015 10:59
(still learning!) Returns a map of filenames for a series of file paths past in.
;;
;; Part of some learning exercises I'm doing. This returns a map of filenames for a series of file paths passed in
;;
(defn get-filenames-from-paths [& paths]
(map #(-> %
(.getFileName)
(.toString))
(map #(java.nio.file.Paths/get (.toURI (java.io.File. %))) paths)))
@frankhale
frankhale / node-webkit-menu-clojurescript.cljs
Last active December 29, 2015 03:29
Trying to learn Clojurescript by creating a menubar with a menu in Node-Webkit. I know this can be done better and more succinctly, this is really rough but it works.
(def gui (js/require "nw.gui"))
(def window (.get (.-Window gui)))
(def m (.-Menu gui))
(def mi (.-MenuItem gui))
(defn create [obj opts]
(obj. (clj->js opts)))
(def menubar (create m {:type "menubar"}))
(def menu1 (create m {:type "contextmenu"}))
(defn actions [array-of-funcs]
(doseq [func array-of-funcs] (func)))
@frankhale
frankhale / map-test.clj
Last active December 29, 2015 23:49
Playing with maps in Clojure
; Playing here, trying to figure out how to work with vectors of maps, my brain synapses are connecting but
; this code doesn't totally reflect the connections made. This will be rectified within 24 hours! HAHA!
;(def buffers (atom []))
;(swap! buffers conj {:file-name "one.txt" :file-text "first file"}
; {:file-name "two.txt" :file-text "second file"}
; {:file-name "three.txt" :file-text "third file"}
; {:file-name "four.txt" :file-text "fourth file"})
@frankhale
frankhale / implement-interface.clj
Last active December 30, 2015 19:29
Can't figure out how to implement an interface in Clojure CLR
; This does not work, boo! Don't know how to tell Clojure that IsReusable is a property
(System.Reflection.Assembly/LoadWithPartialName "System.Web")
(defn foo-handler []
(reify System.Web.IHttpHandler
(IsReusable [] false)
(ProcessRequest [context] ())))
@frankhale
frankhale / map-fun.clj
Last active December 30, 2015 23:59
More map fun!
(def data (atom []))
;(def data1 [{:abc "123"}{:bcd "234"}])
;swap! data conj {:foo "bar"})
;(swap! data into data1)
(def more-data ["foo" "bar" "hello" "world"])
(swap! data into (map #(conj {} {:name %}) more-data))
(swap! data conj {:hello "1234"})
@frankhale
frankhale / project.clj
Created January 13, 2014 17:42
Barebones project.clj for Clojurescript
(defproject your-project "0.0.1-SNAPSHOT"
:description "Describe your app here"
:url "http://somewhere.com"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2138"]]
:plugins [[lein-cljsbuild "1.0.1"]]
:cljsbuild
{:builds
@frankhale
frankhale / main.cljs
Last active August 29, 2015 14:01
My first attempt to port the main.js of the Hello, World atom-shell application to Clojurescript. This does not currently work because atom-shell thinks my application is invalid.
(ns main.core)
(def app (js/require "app"))
(def browser-window (js/require "browser-window"))
(def crash-reporter (js/require "crash-reporter"))
(def main-window (atom nil))
(defn init-browser []
(reset! main-window (browser-window. (clj->js {:width 800 :height 600})))
@frankhale
frankhale / helloworld.fs
Created October 7, 2015 02:28
An F# IHttpHandler hello,world
type HelloWorldHandler() =
interface IHttpHandler with
member this.IsReusable
with get() = false
member this.ProcessRequest(context:HttpContext) =
context.Response.ContentType <- "text/html"
context.Response.Write("<b>I love F# OMG!</b>")