Skip to content

Instantly share code, notes, and snippets.

View spacegangster's full-sized avatar
💭
Working on Lightpad.ai

Ivan Fedorov spacegangster

💭
Working on Lightpad.ai
View GitHub Profile
@Mikhail-Borisov
Mikhail-Borisov / named_regex.clj
Last active November 8, 2020 10:51
Clojure macro for regex that returns named capture groups as a map
(defmacro mk-named-regex-fn
"Given an expression that returns a string returns a function
that given a string returns nil if pattern did not match
and a map of named groups if pattern matches.
Usage: ((regex \"(?<name>[a-zA-Z]+)\") \"John\") => {\"name\" \"John\"}"
[regex-string-expression]
(let [regex-string (eval regex-string-expression)
re-group-regex #"(?<!\\)(?:\\\\)*\((?:\?<(\w+)>|[^?])"
pattern (re-pattern regex-string)
@voku
voku / global_js_error_handling.html
Last active November 25, 2021 10:16
global js error handling via "window.onerror"
<script type="text/javascript">
var one_error_reported_via_onerror = false;
var globalErrorReportHelper = function(msg, url, line, col, error) {
// fallback for e.g.: IE
if (
!error
&&
typeof Error === "function"
@arohner
arohner / google-api.clj
Created November 5, 2016 21:53
Clojure example of accessing google APIs directly
(ns example.api.google
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clj-jwt.core :as jwt]
[clj-jwt.key :as key]
[clj-time.core :as time]
[clj-http.client :as http]
[clojure.string :as str])
(:import java.io.StringReader))
@gavinhungry
gavinhungry / nginx-tls.conf
Last active March 11, 2024 14:51
Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Name: nginx-tls.conf
# Auth: Gavin Lloyd <gavinhungry@gmail.com>
# Desc: Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Enables HTTP/2, PFS, HSTS and OCSP stapling. Configuration options not related
# to SSL/TLS are not included here.
#
# Additional tips:
#
@noprompt
noprompt / slurp.clj
Created February 19, 2014 04:52
How to use slurp from ClojureScript
(ns foo.core
(:refer-clojure :exclude [slurp]))
(defmacro slurp [file]
(clojure.core/slurp file))
;; In CLJS
(ns bar.core
(:require [foo.core :include-macros true :refer [slurp]]))
@dr-dimitru
dr-dimitru / Social RESTful URLs snippet.md
Last active January 28, 2023 03:57
Social links, +1s and shares using only HTML (no JS)
@plentz
plentz / nginx.conf
Last active April 24, 2024 11:15
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@adamloving
adamloving / temporary-email-address-domains
Last active April 24, 2024 14:20
A list of domains for disposable and temporary email addresses. Useful for filtering your email list to increase open rates (sending email to these domains likely will not be opened).
0-mail.com
0815.ru
0clickemail.com
0wnd.net
0wnd.org
10minutemail.com
20minutemail.com
2prong.com
30minutemail.com
3d-painting.com
@jhickner
jhickner / 1.clj
Created April 14, 2012 07:00
hmac
(ns oauth.digest
(:import (javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)))
(defn hmac
"Calculate HMAC signature for given data."
[^String key ^String data]
(let [hmac-sha1 "HmacSHA1"
signing-key (SecretKeySpec. (.getBytes key) hmac-sha1)
mac (doto (Mac/getInstance hmac-sha1) (.init signing-key))]
@sids
sids / html_parser.clj
Created May 6, 2010 05:44
HTML Parsing in Clojure using HtmlCleaner.
(ns in.grok.history.html-parser
(:require [clojure.contrib.logging :as log])
(:import [org.htmlcleaner HtmlCleaner]
[org.apache.commons.lang StringEscapeUtils]))
(defn parse-page
"Given the HTML source of a web page, parses it and returns the :title
and the tag-stripped :content of the page. Does not do any encoding
detection, it is expected that this has already been done."
[page-src]