Skip to content

Instantly share code, notes, and snippets.

View jvranish's full-sized avatar

Job Vranish jvranish

  • Grand Rapids, MI
View GitHub Profile
@jvranish
jvranish / c_option_type.c
Last active May 2, 2022 19:17
Simple option type in C
//usr/bin/make -s "${0%.*}" CFLAGS="-O2 -Wall -Werror" && ./"${0%.*}" "$@"; s=$?; rm ./"${0%.*}"; exit $s
#include <stdio.h>
#include <stdbool.h>
enum option_tag { OPTION_SOME, OPTION_NONE };
#define option_type(T) { enum option_tag tag; T some; }
#define SOME(S) { .tag = OPTION_SOME, .some = S }
#define NONE() { .tag = OPTION_NONE }
@jvranish
jvranish / LICENSE
Created September 13, 2016 21:23
Simple makefiles for C/C++ projest with automatic determination of header dependencies, source files, and include paths
ISC License
Copyright (c) 2016, Job Vranish
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@jvranish
jvranish / thumbv7em-none-eabi
Created May 16, 2016 13:47
Rust Cortex-M4 target spec
{
"arch": "arm",
"cpu": "cortex-m4",
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"disable-redzone": true,
"executables": true,
"llvm-target": "thumbv7em-none-eabi",
"morestack": false,
"os": "none",
"relocation-model": "static",
@jvranish
jvranish / read_with_timeout.rb
Created June 8, 2015 18:48
ruby read with timeout
def read_with_timeout(io_like, read_len, timeout)
timeout_time = Time.now + timeout
data = ""
loop do
begin
result = io_like.read_nonblock(read_len - data.length)
puts data
data += result
if block_given?
@jvranish
jvranish / adcpi18.py
Created May 20, 2015 23:51
python script to continuously sample ADC connected to raspberry pi via I2C
#!/usr/bin/env python
# read abelectronics ADC Pi V2 board inputs with repeating reading from each channel.
# # Requries Python 2.7
# Requires SMBus
# I2C API depends on I2C support in the kernel
# Version 1.0 - 06/02/2013
# Version History:
# 1.0 - Initial Release
@jvranish
jvranish / broken.rs
Created May 17, 2015 17:57
Example that crashes rustc
/* automatically generated by rust-bindgen */
#![crate_type="staticlib"]
#[derive(Copy)]
pub struct StructUnnamed9 {
pub _bindgen_bitfield_1_: u32,
pub _bindgen_bitfield_2_: u32,
pub _bindgen_bitfield_3_: u32,
pub _bindgen_bitfield_4_: u32,
@jvranish
jvranish / dt-blob-dpi.dts
Created April 9, 2015 15:08
Raspberry PI B+ DeviceTree for 24-bit DPI LCD interface over GPIOs
/dts-v1/;
/ {
videocore {
clock_routing {
vco@PLLD { freq = <2000000000>; };
chan@DPER { div = <8>; }; // APER will be 500MHz
}; // clock routing
pins_bplus {
pin_config {
@jvranish
jvranish / queue_with_timeout.rb
Created May 20, 2014 15:14
Ruby pop with timeout implementation
class QueueWithTimeout
def initialize
@mutex = Mutex.new
@queue = []
@recieved = ConditionVariable.new
end
def <<(x)
@mutex.synchronize do
@queue << x
@jvranish
jvranish / adt.rb
Created October 17, 2013 14:20
Simple algebraic datatypes for ruby
require 'stringio'
class ADT < Struct
def self.members() @members end
def self.add_member(c)
@members ||= []
@members << c
@members.length - 1
end
def self.data(*args)
@jvranish
jvranish / logict_vs_fbacktrack.hs
Created March 9, 2013 15:30
A comparison of LogicT and Stream (from Olegs FBackTrack.hs) Stream has better termination criteria!
{-
To install dependencies:
cabal install logict
cabal install stream-monad
-}
import Control.Monad.Logic