Skip to content

Instantly share code, notes, and snippets.

@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.
@mislav
mislav / html.rb
Created May 12, 2010 08:31
Pretty up HTML with Nokogiri and XSLT
require 'nokogiri'
ugly = Nokogiri::HTML ARGF
tidy = Nokogiri::XSLT File.open('tidy.xsl')
nice = tidy.transform(ugly).to_html
puts nice
@Ameeda
Ameeda / NokogiriXPathNamespaces
Created May 5, 2011 14:48
Selecting elements in some namespace using Nokogiri with XPath
2 ways to extract elements from within XML namespaces using Nokogiri
When trying to select elemenets in the default namespace, e.g. "xmlns= http://www.w3.org/2005/Atom", try the following two ways. Note the xmlns=" attribute on entry element:
Original xml:
Nokogiri::XML(@xml_string).xpath("//author/name").each do |node|
puts node
end
1. Define a namespace context for your XPath expression and point your XPath steps to match elements in that namespace. Define a namespace-to-prefix mapping and use this prefix (a) in the XPath expression.
@yoavram
yoavram / client.py
Created December 21, 2012 08:41
Example of uploading binary files programmatically in python, including both client and server code. Client implemented with the requests library and the server is implemented with the flask library.
import requests
#http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
url = "http://localhost:5000/"
fin = open('simple_table.pdf', 'rb')
files = {'file': fin}
try:
r = requests.post(url, files=files)
print r.text
@jeppeburchardt
jeppeburchardt / msbuild node gyp
Created July 17, 2013 12:54
node gyp msbuild misssing registry warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64
Sample project for the "Getting started with JavaFX in Clojure" ( https://coderwall.com/p/4yjy1a ) ProTip.
@friemen
friemen / profiles.clj
Last active July 11, 2024 07:53
My Leiningen profiles.clj
;; put this into profiles.clj in ~/.lein folder
{:user {:jvm-opts ^:replace ["-Xmx6G"
"-XX:-OmitStackTraceInFastThrow"]
:repl-options {:timeout 180000}
:plugins [[cider/cider-nrepl "0.49.0"]
[refactor-nrepl "3.10.0"]
[jonase/eastwood "0.3.14"]
[lein-ancient "1.0.0-RC3"]
[lein-try "0.4.3"]
[lein-cloverage "1.0.13"]
@staltz
staltz / introrx.md
Last active July 25, 2024 16:52
The introduction to Reactive Programming you've been missing
@john2x
john2x / 00_destructuring.md
Last active July 9, 2024 01:38
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@wrobstory
wrobstory / gist:06471b5cd9046a6e50e0
Last active December 13, 2019 20:11
Fastest Clojure Sum
;; Gaussian sum!
user=> (crit/with-progress-reporting (crit/quick-bench (/ (* (+ 1 99999) 99999) 2)))
Warming up for JIT optimisations 5000000000 ...
compilation occured before 333366 iterations
Estimating execution count ...
Sampling ...
Final GC...
Checking GC...
WARNING: Final GC required 8.548926352381509 % of runtime
Finding outliers ...