Skip to content

Instantly share code, notes, and snippets.

@pstephens
pstephens / arc_str.rs
Last active February 15, 2023 17:16 — forked from rust-play/playground.rs
Code shared from the Rust Playground
//! Proof of concept for a reference counted [str]
//! Primary innovation over a plain Rc<str> is that is one less level of
//! indirection and heap allocation
#![feature(const_alloc_layout)]
use core::ptr::NonNull;
use std::alloc::Layout;
use std::alloc::{GlobalAlloc, System};
@pstephens
pstephens / README.md
Last active August 8, 2018 19:31 — forked from magnetikonline/README.md
Bash array usage cheatsheet.
@pstephens
pstephens / lambda_test.c
Created June 28, 2018 03:31
What would transducers look like in C?
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
typedef struct thing thing_t;
struct thing {
long num;
int cnt;
@pstephens
pstephens / calc.py
Created December 26, 2017 18:11
A simple expression evaluator in Python.
"""Implements a simple expression evaluator.
Supported syntax:
1. Balanced parenthesis for grouping.
2. Numbers. Can include a decimal point.
3. Negation ('-' as a prefix unary operator)
4. Binary operators for '*', '/', '+', and '-'.
Order of operations follow typical rules:
1. Grouping. (1+2)
@pstephens
pstephens / RiderNonRepro.fs
Created August 27, 2017 20:07
RiderNonRepro
namespace Collections
module RiderReproTests =
open FsCheck.Xunit
open Xunit
[<Property>]
let repro_test_pass (_:int) = true
@pstephens
pstephens / theanswer.asm
Created December 11, 2016 05:18
My first assembler program on Linux :-)
section .text
global _start
_start:
mov rdi, 42
mov rax, 60 ; sys_exit
syscall
; assemble the elf64 object file with nasm:
@pstephens
pstephens / Program.scala
Last active May 17, 2017 09:13
A Spark doodle
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.io.{LongWritable, Text}
import org.apache.hadoop.mapreduce.lib.input.{FileSplit, TextInputFormat}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.NewHadoopRDD
object Program {
def main(args: Array[String]): Unit = {
val srcFile = "hdfs://sandbox/Numbers.txt"
val conf = new SparkConf().setAppName("spark-numbers")
@pstephens
pstephens / serve.cljs
Created November 15, 2015 04:25
Simple node.js style 'hello world' web server in ClojureScript
(ns biblecli.commands.serve
(:require
[cljs.nodejs :as nodejs]
[clojure.string :as string]
[goog.object]))
(def node-http (nodejs/require "http"))
(defn process-request [req res]
(goog.object/set res "statusCode" 200)
@pstephens
pstephens / bootstrap.ps1
Last active August 29, 2015 14:26
Proposed bootstrap script for ClojureScript (rough draft)
$ErrorActionPreference = "Stop"
$root = Resolve-Path "$PSScriptRoot\.."
$shell = New-Object -com shell.application
# Read white listed dependency version info from the /bin/sh script and store in variables
Get-Content $root\script\bootstrap |
Where-Object { $_ -match '^\s*(\w+)\s*=\s*\"([^\"]*)\"\s*$' } |
Where-Object { $matches[1] -in "CLOJURE_RELEASE", "CLOSURE_RELEASE",
"DJSON_RELEASE", "GCLOSURE_LIB_RELEASE", "RHINO_RELEASE", "TREADER_RELEASE" } |
Foreach-Object { New-Variable $matches[1] $matches[2] -Scope private }
@pstephens
pstephens / coder.clj
Last active August 29, 2015 14:19
Alphabet Cipher solution
;; Solution to https://github.com/gigasquid/wonderland-clojure-katas/tree/master/alphabet-cipher
(ns alphabet-cipher.coder)
(defn crypt [op keyword message]
(letfn [
(tochar [idx] (char (+ idx (int \a))))
(toidx [ch] (- (int ch) (int \a)))
(encode [keychar msgchar] (tochar (mod (op (toidx msgchar) (toidx keychar)) 26)))]
(->> message
(map encode (cycle keyword))