Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
@jimsynz
jimsynz / rgb_spectrum.c
Created January 5, 2011 20:59
Arduino sketch to cycle an RGB LED through the colour spectrum.
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
void setup() {
// Start off with the LED off.
setColourRgb(0,0,0);
}
void loop() {
@jimsynz
jimsynz / ash_recursive_cte_wip.md
Last active July 9, 2023 21:42
A half-finished blog post about using recursive CTEs with Ash.

Relationships to recursive common table expressions

Let me lead by saying that this is a probably a bad idea and if you're starting from scratch you should instead look at using a Postgres extension like ltree instead.

Recently I was working on a client's application and they have a Location resource which represents a physical location. Locations are a tree - ie they have a belongs_to :parent_location, Location relationship that if loaded essentially performs a self-join on the locations table. Likewise it has a

Keybase proof

I hereby claim:

  • I am jimsynz on github.
  • I am jimsy (https://keybase.io/jimsy) on keybase.
  • I have a public key whose fingerprint is 35C0 3A00 BB0B F539 3A62 7A31 BC0D 2595 FE40 0374

To claim this, I am signing this object:

@jimsynz
jimsynz / weighted_reference_counting.md
Last active May 9, 2019 15:25
Weighted Reference Counting Example

Weighted Reference Couting

Weighted reference counting is more efficient than traditional reference counting because you don't have to update the reference counted object every time a reference is taken (potentially meaning updating the object on the heap and blowing the processor cache). Weighted reference counting only updates the referenced object when a reference is dropped or when weight is exhausted. Weight Reference Counting is also really good for concurrent systems because the number of synchronisations needed is much lower than normal reference counting.

Algorithm overview:

Allocate a new reference counted object with a default weight (a tunable power of two - usually around 1 << 16 for a real implementation). An initial reference is allocated which points to the object and the weight value is copied into it. Every time the reference is cloned, the weight is split in two (shifting one bit to the right is the same as dividing by two) and one half allocated to the existing reference and one

@jimsynz
jimsynz / initializer.js
Created January 14, 2019 01:59
How I add GA to my Ember apps.
# app/instance-initializers/google-analytics.js
import ENV from "./config/environment";
export function initialize(application) {
let fastboot = application.lookup('service:fastboot');
window.dataLayer = window.dataLayer || [];
if (!fastboot.get('isFastBoot')) {
let body = document.getElementsByTagName('body').item(0);
@jimsynz
jimsynz / api_controller.rb
Last active December 27, 2018 07:29
API Session Token Example
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
respond_to :json
rescue_from UserAuthenticationService::NotAuthorized, with: :not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :not_found
before_filter :api_session_token_authenticate!
private
def signed_in?
@jimsynz
jimsynz / install_ex.sh
Last active November 4, 2018 22:24
I use this to install Elixir on Codeship.
#!/bin/sh
# I use this to install Elixir on our codeship instances for testing. YMMV.
# curl -O https://gist.githubusercontent.com/jamesotron/44f8962cddef781ab830/raw/e75599e95587cbca26e707505fd40dd0f26eb0f5/install_ex.sh
# . ~/install_ex.sh
# You can override your Elixir and Erlang versions from your shell when you call ./install_ex.sh.
export ERLANG_VERSION=${ERLANG_VERSION:-18.0.3}
export ELIXIR_VERSION=${ELIXIR_VERSION:-1.0.5}
@jimsynz
jimsynz / index.hbs
Created May 22, 2018 02:40
How to use Semantic UI's visibility module with Semantic UI Ember.
{{#ui-visibility class="ui segment masthead"
once=false
onBottomPassed=(action "mastheadOffScreen")
onBottomPassedReverse=(action "mastheadOnScreen") }}
<div class="ui container">
<h1>Hello, World!</h1>
</div>
{{/ui-visibility}}
/// Returns the line and column numbers for the beginning and the end of
/// this pair.
///
/// # Example
///
/// ```
/// # use std::rc::Rc;
/// # use pest;
/// # use pest::inputs::StringInput;
/// # #[allow(non_camel_case_types)]
pub trait Object { }