Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki

Christoph Grabo asaaki

🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki
View GitHub Profile
@asaaki
asaaki / Gemfile
Last active February 25, 2020 13:28
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'puma'
gem 'sinatra'
gem 'sinatra-contrib'
@asaaki
asaaki / ___boolean_env_vars.md
Last active November 7, 2019 19:42
Env Vars as Booleans

Boolean Environment Variables

Don't overcomplicate things.

I've seen a lot of parse the env var and match it against some known values like:

env_var = ENV['FEATURE_ONE']
case env_var.to_s.downcase
when 'true', 't', 'yes', 'y', 'on', '1' then true
@asaaki
asaaki / ruby-sigils.rb
Created May 28, 2019 16:51
ruby-sigils.rb
[*('A'..'Z'), *('a'..'z')].map do |c|
puts [c, eval("%#{c}(ls)")].inspect
rescue Exception
puts "#{c} not allowed"
end; 0
@asaaki
asaaki / experiments.rb
Created May 16, 2019 09:23
Some Ruby stdlib experiments
### Experiments
# https://ruby-doc.org/core-2.5.0/SizedQueue.html
log = SizedQueue.new(100)
# https://ruby-doc.org/core-2.5.0/Queue.html
queue = Queue.new
# https://ruby-doc.org/core-2.5.0/ThreadGroup.html
group = ThreadGroup.new # pool
5.times do |i|
# https://ruby-doc.org/core-2.5.0/Thread.html
@asaaki
asaaki / flurlicht.ino
Created January 30, 2019 09:30
motion sensor / interrupt triggered neopixel light controller
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#define STRIP_PIN 6
#define TRIGGER_PIN 2
#define CONTROL_LED 13
// Note: this duration should be also longer than the HIGH time of the PIR
@asaaki
asaaki / rustup-targets.sh
Created October 22, 2018 14:44
(rustup) add or remove list of targets for a list of toolchains
#!/bin/sh
targets=(armv7-unknown-linux-musleabihf thumbv7em-none-eabi armv7-unknown-linux-musleabihf)
toolchains=(stable beta nightly)
for toolchain in $toolchains; do
for target in $targets; do
echo "--> toolchain $toolchain and target $target"
rustup target install $target --toolchain $toolchain
# rustup target remove $target --toolchain $toolchain
@asaaki
asaaki / callables_spec.rb
Created March 2, 2018 09:44
callables in specs
require 'spec_helper'
module CallableSubject
def callable_subject(&_block)
subject { -> { yield } }
end
end
RSpec.configure do |c|
c.extend(CallableSubject)
@asaaki
asaaki / playground.rs
Created January 26, 2018 08:42 — forked from anonymous/playground.rs
Rust code shared from the playground
use std::ops::Deref;
struct StateFn(fn(&mut Machine) -> StateFn);
impl Deref for StateFn {
type Target = fn(&mut Machine) -> StateFn;
fn deref(&self) -> &Self::Target {
&self.0
}
@asaaki
asaaki / 0___rust_serde_json_wasm_parcel___0.md
Last active January 28, 2023 14:14
Rust-to-JS JSON string exchange (parcel.js, wasm)

Rust, serde-json, wasm, parcel.js

With this combination it is fairly easy to get things done in Rust and utilize it in JavaScript. Yay!

@asaaki
asaaki / hello.rs
Last active January 26, 2018 01:57
parcel.js/Rust: return a string
/*
gist is: return a ref to c_char and the length of it (via 2 functions)
C example: https://wasdk.github.io/WasmFiddle//?w590f
*/
use std::ffi::CString;
use std::os::raw::c_char;
static HELLO: &'static str = "hello from rust";