Skip to content

Instantly share code, notes, and snippets.

View mfikes's full-sized avatar

Mike Fikes mfikes

View GitHub Profile
@mfikes
mfikes / shor.m
Created July 13, 2024 21:10
Simulate Shor's algorithm in a 4-qubit computer
% Number to factor
N = 15; % Example number
a = 7; % Randomly chosen integer coprime to N
% Number of qubits
n = 4;
dim = 2^n;
% Initialize the state vector to |0000>
state = zeros(dim, 1);
@mfikes
mfikes / shor.m
Last active July 13, 2024 21:03
Simulate Shor in a 3-qubit computer
% Number to factor
N = 6; % Example number
a = 5; % Randomly chosen integer coprime to N
% Number of qubits
n = 3;
dim = 2^n;
% Initialize the state vector to |000>
state = zeros(dim, 1);
@mfikes
mfikes / concurrency.clj
Last active June 7, 2024 18:33
Concurrency comparison Swift async/await and Clojure core.async
(require '[clojure.core.async :refer [go <!]])
(defn fetch-user-id [server]
(go
(if (= server "primary")
97
501)))
(defn fetch-username [server]
(go
@mfikes
mfikes / main.c
Last active May 14, 2023 16:52
Modified nrf/samples/bluetooth/peripheral_hids_keyboard/main.c
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
(require '[cljs-bean.core :refer [->clj ->js]])
(defn update-vals
"m f => {k (f v) ...}
Given a map m and a function f of 1-argument, returns a new map where the keys of m
are mapped to result of applying f to the corresponding values of m."
{:added "1.11"}
[m f]
(with-meta
(persistent!
@mfikes
mfikes / README.md
Last active April 5, 2021 02:17
Example of foreign library property namespace

Example using library property namespace with a foreign lib:

clj -M -m cljs.main -co co.edn -re node -r
ClojureScript 1.10.844
cljs.user=> (require '[yq$yowza :as yz :refer [getMessage]])
nil
cljs.user=> (getMessage)
"Hello, world!"
cljs.user=&gt; (yz/sayHello "hola")
@mfikes
mfikes / README.md
Last active February 2, 2021 18:23
Macro with side effect in ClojureScript
% clj -M -m cljs.main
ClojureScript 1.10.773
cljs.user=> (require 'foo.core)
nil
cljs.user=> (foo.core/m 1)
here
2
@mfikes
mfikes / keys-vals.md
Last active November 23, 2020 13:27

The following works in Clojure:

(keys (filter (comp odd? val) {:a 1 :b 2 :c 3}))

The docstrings for keys and vals don't indicate that you can do this. Is this accidential or intentional?

I vaguely recall Alex Miller indicating at some point that this capability was deemed useful and is intentionally allowed. Yes, this is an appeal to authority, but nevertheless, it makes a fairly convincing argument.

Self-hosted:

$ plk
ClojureScript 1.10.597
cljs.user=> (require '[foo.core :refer [defnmy]])
nil
cljs.user=> (defnmy FOO clojure.string/lower-case [x]
       #_=>   (inc x))
#'cljs.user/foo
/Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command; exit
Last login: Fri Apr 17 17:24:32 on ttys005
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Mikes-iMac:~ mfikes$ /Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command; exit
###### ######
### #### #### ###