Skip to content

Instantly share code, notes, and snippets.

View quan-nh's full-sized avatar
🌗
.

Quân quan-nh

🌗
.
View GitHub Profile
@alandipert
alandipert / kahn.clj
Last active June 24, 2023 17:59
Kahn's topological sort in Clojure
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
@gorsuch
gorsuch / gist:1418850
Created December 1, 2011 18:37
clojure uuid
(defn uuid [] (str (java.util.UUID/randomUUID)))
@mattmcd
mattmcd / Hello.g4
Last active April 19, 2024 08:04
Simple ANTLR4 grammar example
// define a grammar called Hello
grammar Hello;
r : 'hello' ID;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
@Gonzih
Gonzih / try-macro.clj
Last active April 11, 2017 14:09
Clojure try* macro experiment. Part of small project that I'm working on right now (https://github.com/Gonzih/feeds2imap.clj).
(defmacro try*
"Macro to catch multiple exceptions with one catch body.
Usage:
(try*
(println :a)
(println :b)
(catch* [A B] e (println (class e)))
(catch C e (println :C))
(finally (println :finally-clause)))
@cgmartin
cgmartin / gist:5880732
Last active September 15, 2018 01:22
WebSocket subprotocol and origin validation with HTTP Kit
(ns my.server
(:use org.httpkit.server
[clojure.string :only [split trim lower-case]])
(:import [org.httpkit.server AsyncChannel]))
(defn origin-match? [origin-re req]
(if-let [req-origin (get-in req [:headers "origin"])]
(re-matches origin-re req-origin)))
@jkbrzt
jkbrzt / pyc
Last active June 6, 2023 14:59
Delete Python's compiled *.pyc files like a pro
#!/bin/sh
#
# Delete Python's compiled *.pyc and __pycache__ files like a pro
# https://gist.github.com/jakubroztocil/7892597
#
# Usage:
# Delele *.pyc and __pycache__ files recursively in the current directory:
# $ pyc
#
# The same, but under /path:
@salomvary
salomvary / datetime.java
Last active January 21, 2022 23:23
Java 8 Date and Time Parsing and Formatting Microtutorial
import java.time.format.DateTimeFormatter;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
Instant.now();
// java.time.Instant = 2015-08-13T09:28:27.141Z
DateTimeFormatter.ISO_INSTANT.format(Instant.now());
@mtth
mtth / Mail.avpr
Created February 26, 2016 15:45
Avro RPC
{
"protocol": "Mail",
"namespace": "example.proto",
"doc": "From https://github.com/phunt/avro-rpc-quickstart/blob/master/src/main/avro/mail.avpr",
"types": [
{
"name": "Message",
"type": "record",
"fields": [
{
@Dreyer
Dreyer / perlbrew_libgcc_s.txt
Created January 20, 2017 11:27
[perlbrew] ld: library not found for -lgcc_s.10.4
$ cd /usr/local/lib
$ sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib
$ sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.4.dylib
@LindaLawton
LindaLawton / GoogleAuthenticationCurl.sh
Last active June 9, 2024 10:41
Curl bash script for getting a Google Oauth2 Access token
# Tutorial https://www.daimto.com/how-to-get-a-google-access-token-with-curl/
# YouTube video https://youtu.be/hBC_tVJIx5w
# Client id from Google Developer console
# Client Secret from Google Developer console
# Scope this is a space seprated list of the scopes of access you are requesting.
# Authorization link. Place this in a browser and copy the code that is returned after you accept the scopes.
https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=http://127.0.0.1&scope=[Scopes]&response_type=code
# Exchange Authorization code for an access token and a refresh token.