Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
@jeremygilly
jeremygilly / thread_test.py
Created March 28, 2020 12:57
Raspberry Pi test code for James
''' Jeremy's test script - 28 Mar 2020.
It creates two threads and waits for both to finish before presenting the results.
Each thread generates random data, but data that is similar to what is expected from the sensor devices.
The results are added to the queue, removed, then presented to the user.
Not completed: writing to '''
import queue, threading, time, random, math, numpy, sys

React Native + macOS + Clojurescript

image

Project Catalyst

Since the recent release of Catalina, macOS has shipped with the ability to allow iOS/iPAD apps to run on macOS without any modification via a featureset known as Project Catalyst.

This is exciting, as writing React Native + Clojurescript apps as a target for the desktop is much more compelling than a pure Electron app (imo).

@ReeseWang
ReeseWang / [email protected]
Created October 13, 2019 10:49
Systemd service file for starting a DHCP server on a specific interface with a separate lease file, modified from the dhcp package from Arch Linux.
[Unit]
Description=IPv4 DHCP server on %i
After=network.target network-online.target
Wants=network-online.target
[Service]
Type=forking
ExecStartPre=/usr/bin/touch /var/lib/dhcp/dhcpd@%i.leases
ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/dhcpd.conf.d/%i.conf -pf /run/dhcpd4/dhcpd@%i.pid -lf /var/lib/dhcp/dhcpd@%i.leases %i
RuntimeDirectory=dhcpd4
@schmee
schmee / assembly.log
Created August 6, 2019 18:53
Vector API in Clojure!
vector_clj/core$i256_add.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [0x000000011f8acdc0, 0x000000011f8ad058] 664 bytes
[Entry Point]
[Constants]
# {method} {0x000000013253d3b8} 'invoke' '(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;' in 'vector_clj/core$i256_add'
# this: rsi:rsi = 'vector_clj/core$i256_add'
# parm0: rdx:rdx = 'java/lang/Object'
# parm1: rcx:rcx = 'java/lang/Object'
# [sp+0x30] (sp of caller)
.....
0x000000011f8acec3: prefetchw BYTE PTR [r10+0x180]
@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization

Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs, and so that is what I favor. In paricular, shadow-cljs lets you install npm modules using npm or yarn and uses the resulting package.json to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.

Packaging and Delivering Code

@thegeez
thegeez / spec_parsing.clj
Last active December 30, 2023 18:17
Parsing with clojure.spec for the Advent of Code challenge
(ns net.thegeez.advent.spec-parsing
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.test.check.generators :as tgen]))
;; Dependencies:
;; [org.clojure/clojure "1.9.0-alpha14"]
;; [org.clojure/test.check "0.9.0"]
;; Advent of Code is a series of code challenges in the form of an advent
@BurkeB
BurkeB / microphone.clj
Created October 7, 2016 19:49
Microphone Clojure test
(def audioformat (new javax.sound.sampled.AudioFormat 44100 16 2 true true))
(def info (new javax.sound.sampled.DataLine$Info javax.sound.sampled.TargetDataLine audioformat))
(if (not= (javax.sound.sampled.AudioSystem/isLineSupported info))(print "dataline not supported")(print "ok lets start\n"))
(def line (javax.sound.sampled.AudioSystem/getTargetDataLine audioformat))
(.open line audioformat)
(.start line)
(let [size (/ (.getBufferSize line) 5)
buf (byte-array size)]
@aputs
aputs / jwt.cljs
Created September 21, 2016 02:01
clojurescript JWT encode/decode (SHA version only)
(ns cljsjs.jwt
(:require
[clojure.spec :as s]
[clojure.string :as str]
[goog.json :as json]
[goog.crypt.base64 :refer [encodeString decodeString]]))
;; https://github.com/Caligatio/jsSHA
;; goog.crypt.hmac produces different signature than nodejs version
(def jssha (js/require "jssha"))
@vkz
vkz / bleval.clj
Created December 15, 2015 12:39
Clojure's `eval` and namespaces
;; Clojure's eval is dynamic with respect to current namespace.
;; If you ever find yourself in need of eval but want to avoid **wat**
;; moments here's hopefully an illuminating sequence:
user> (in-ns 'bla)
#namespace[bla]
bla> (refer-clojure)
nil
bla> (def x "bla")
#'bla/x
bla> (defn bleval [s]
@s-fujimoto
s-fujimoto / s3-to-es-lamba.py
Created November 14, 2015 15:57
Import Elasticsearch from ELB access log for AWS Lambda Function
##################################################
### Elasticsearch host name
ES_HOST = "search-******************.ap-northeast-1.es.amazonaws.com"
### Elasticsearch prefix for index name
INDEX_PREFIX = "awslogs"
#################################################
### ELB access log format keys
ELB_KEYS = ["timestamp", "elb", "client_ip", "client_port", "backend_ip", "backend_port", "request_processing_time", "backend_processing_time", "response_processing_time", "elb_status_code", "backend_status_code", "received_bytes", "sent_bytes", "request_method", "request_url", "request_version", "user_agent"]