Skip to content

Instantly share code, notes, and snippets.

@lilactown
lilactown / cljs-serverless.md
Last active January 27, 2020 05:06
CLJS in AWS Lambda Quick Start
@ordnungswidrig
ordnungswidrig / microweb.cljs
Created December 10, 2019 11:12
Webserver in clojurescript on espruino
(set! *warn-on-infer* true)
(def ^js wifi (js/require "Wifi"))
(def ^js http (js/require "http"))
(def n (atom 0))
(defn build-response []
(str
"<html>"
@gdamjan
gdamjan / record_to_list.hrl
Created October 8, 2011 19:45
An erlang macro that creates a function to convert a record to a key-value list
%%% This macro will create a function that converts a record to
%%% a {key, value} list (a proplist)
-define(record_to_list(Record),
fun(Val) ->
Fields = record_info(fields, Record),
[_Tag| Values] = tuple_to_list(Val),
lists:zip(Fields, Values)
end
).
@pofider
pofider / 01-ebs.config
Created September 10, 2015 15:14
Attach EBS volume to amazon elastic beanstalk
# .ebextensions/01-ebs.config
commands:
01clear-if-unmounted:
command: if ! mount | grep /media/ebs_volume > /dev/nul; then rm -rf /media/ebs_volume; fi
02attach-volume:
command: aws ec2 attach-volume --region eu-central-1 --volume-id vol-ddb08e34 --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh
ignoreErrors: true
03wait:
command: sleep 10
04trymount:
@utsengar
utsengar / EncodeBased64Binary.java
Created October 11, 2011 00:27
Encode a file to base64 binary in Java
import org.apache.commons.codec.binary.Base64;
private String encodeFileToBase64Binary(String fileName)
throws IOException {
File file = new File(fileName);
byte[] bytes = loadFile(file);
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
@joelittlejohn
joelittlejohn / test.clj
Last active July 3, 2023 21:08
Dynamically generate clojure.test deftests (and other tricks)
(ns dynamic.test
(:require [clojure.test :refer :all]))
;; This example shows how tests can be generated dynamically, by
;; creating new vars with the correct metadata.
(defn add-test
"Add a test to the given namespace. The body of the test is given as
the thunk test-fn. Useful for adding dynamically generated deftests."
[name ns test-fn & [metadata]]
@rsms
rsms / foo.service
Created October 3, 2020 00:18
Example go http server with systemd socket activation and zero-downtime restart
[Unit]
Description = Foo HTTP server
Requires = foo.socket
After = multi-user.target
[Service]
User = www-data
Group = www-data
WorkingDirectory = /var/foo
ExecStart = /var/foo/bin/foo-server
@joost-de-vries
joost-de-vries / akka-and-kotlin-coroutines.md
Last active February 27, 2024 07:00
Akka and kotlin coroutines

Akka and Kotlin coroutines: ♡

I've experimented with Kotlin and coroutines in programming Akka. And I must say, I really like the combination so far.
But before I go into it some brief preliminaries for those who don't know Akka and actors.

Actors and Akka

Actors are a programming model that fits cloud native architectures particularly well. Being highly available and scaling horizontally. All while embracing the realities of multiple servers collaborating, server instances coming and going and the network having hickups.

On the JVM Akka is the prominent actor framework. It's been around for a while now and as a result it's highly reliable, well thought out and offers a wide programming eco system. My own interest in Akka is because of its suitability for software systems that can only be built with business events as a key construct and thinking model. And then of course materialized views, CQRS and near real-time data streams play a big role in constructing those systems.

@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@MatthewJamesBoyle
MatthewJamesBoyle / DOCKERFILE
Last active March 11, 2024 15:57
production go dockerfile
FROM golang:1.21.0-bullseye as builder
COPY . /workdir
WORKDIR /workdir
ENV CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-all"
ENV GOFLAGS="-buildmode=pie"
RUN go build -ldflags "-s -w" -trimpath ./cmd/app