Skip to content

Instantly share code, notes, and snippets.

rwat

Block or report user

Report or block rwat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vertigo_binary_search.clj
(ns bar.baz
(:require [vertigo.core :as vc]
[vertigo.structs :as vs]))
;;
;; based off of work by Michał Marczyk
;; http://stackoverflow.com/questions/8949837/binary-search-in-clojure-implementation-performance
;;
(set! *warn-on-reflection* true)
View nmanage.clj
(ns nmanage)
(def running (atom true))
(defn process
[]
(when @running
(prn "hi")
(Thread/sleep 1000))
(recur))
View gen-ips.clj
; Generate a list of random IPs to be fed into nmap so that nmap may scan
; aggressively but not swamp any given subnet within the 172.16.0.0/12 range.
;
; Licensed under the EPL. (fwiw ;)
(use '[clojure.contrib.seq-utils :only (shuffle)]
'[clojure.contrib.duck-streams :only (write-lines)])
(write-lines
"./ips.txt"
View udp_testing.clj
(import '(java.net InetAddress InetSocketAddress DatagramPacket DatagramSocket))
(def buf-len 1500)
; create a SocketAdress for the listener
(let [listener-port 29000
listener-ip "127.0.0.1"]
(def l-socket-address (InetSocketAddress. (InetAddress/getByName listener-ip) listener-port)))
View udp_proof_of_concept.clj
(import '(java.net InetAddress
InetSocketAddress
DatagramPacket
DatagramSocket))
; Create a SocketAddress object that holds the IP address and UDP port the
; socket will listen to.
(let [listener-ip "127.0.0.1"
listener-port 29000]
View udp_server.clj
(import '(java.net InetAddress
InetSocketAddress
DatagramPacket
DatagramSocket))
(defn create-udp-server [& {:keys [local-ip local-port remote-ip remote-port]}]
(let [s (InetSocketAddress. (InetAddress/getByName local-ip) local-port)
r (InetSocketAddress. (InetAddress/getByName remote-ip) remote-port)
d (DatagramSocket. s)
udp-server (ref d)]
View is-rfc1918.clj
(ns your-namespace
(:use [clojure.string :only [split]]))
; authored by ordnungswidrig
(defn is-rfc1918?
"Returns true if a string is a dotted quad in the IP ranges of 10.0.0.0/8,
192.168.0.0/16 or 172.16.0.0/22, else returns nil)"
[^String ip]
(when-let [[a b c d :as qs]
View leaks_memory.clj
(import '(java.net InetAddress
InetSocketAddress
DatagramPacket
DatagramSocket))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; networking
(defrecord UDPServer [dgram-socket connected closed])
@rwat
rwat / my-date-time.clj
Created Jan 24, 2011
exception handling example
View my-date-time.clj
(ns my-ns
(:use [clj-time.core :only [date-time]]))
(defn my-date-time
"same as clj-time.core date-time but returns nil on improper input"
[& args]
(try
(apply date-time (map #(Integer/parseInt %) args))
(catch RuntimeException e nil)))
@rwat
rwat / clojure_snippets.clj
Last active Jan 1, 2016
Sundry Clojure snippets
View clojure_snippets.clj
;; current time
(System/currentTimeMillis)
;; make a version 4 random UUID as per http://www.ietf.org/rfc/rfc4122.txt
(java.util.UUID/randomUUID)
;; start a new thread and run a function
(.start (Thread. (fn [] (loop []
(do
(update-mock-data!)
You can’t perform that action at this time.