Skip to content

Instantly share code, notes, and snippets.

View narrowtux's full-sized avatar
:shipit:
Shipping it

Moritz Schmale narrowtux

:shipit:
Shipping it
View GitHub Profile
@narrowtux
narrowtux / repo_stream.ex
Created October 9, 2017 09:18
Module for Ecto and GenStage to work together when you want to use Repo.stream in conjunction with a GenStage subscriber or a Flow.
defmodule RepoStream do
defmodule Producer do
use GenStage
defstruct [:demand, :pid]
def start_link() do
GenStage.start_link(__MODULE__, self())
end
@narrowtux
narrowtux / countdown.html
Created September 17, 2023 06:00
Simple HTML page that shows a countdown in the center, with nudges when it's lower than 2 minutes.
<!doctype html>
<html>
<head>
<title>Test</title>
<style>
body {
color: white;
background: black;
font-family: "Helvetica", Arial, sans-serif;
}
@narrowtux
narrowtux / sevene1serial.h
Created March 30, 2015 15:37
Arduino SoftwareSerial 7E1 read support
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#ifndef SEVEN_E_1_SERIAL
#define SEVEN_E_1_SERIAL
#define _DEBUG 0
#define _DEBUG_PIN1 11
@narrowtux
narrowtux / model.ex
Last active February 16, 2023 08:39
Recursive models with ecto
defmodule Model do
schema "models" do
field :foo, :string
has_many :children, Model, foreign_key: :parent_id
belongs_to :parent, Model, foreign_key: :parent_id
end
@doc """
Recursively loads parents into the given struct until it hits nil
"""
@narrowtux
narrowtux / README.md
Created September 14, 2022 07:46
Distributed Erlang with WSL in the mix

Distributed Erlang with WSL

Checklist

  • Set the same erlang cookies (~/.erlang-cookie or :erlang.set_cookie :abc)
  • On the WSL machine, use ifconfig to find out the IP address of the WSL machine
  • Start nodes with FQDN using their IP address as hostname: iex --name main@[ip] -S mix [command]
  • On the WSL machine, run epmd -names to find the port of the erlang node that has just been started
  • On the WSL host, run these commands in powershell:
*smoothScroll.js*
*smooth*.js*
*nicescroll*js*
*jquery.mousewheel.js*
*plugins-scroll.js*
https://d33wubrfki0l68.cloudfront.net/bundles/85ee573a175fbccec4ed26bf47ede7fd06c1d248.js
@narrowtux
narrowtux / OS X Shortcuts.md
Last active November 5, 2021 16:26
OS X Shortcuts

OS X Shortcuts

This gist aims to be a fairly complete list of all known shortcuts all around OS X (and some OS X applications).

How to ergonomically press shortcuts

In this gist, there are sometimes multiple shortcuts for the same action. In that case, the shortcuts are ordered by how ergonomically you can press them, in descending order. That means that you should always learn the first shortcut in the list.

let child = require("child_process")
let source_map = require("source-map")
let SourceMapConsumer = source_map.SourceMapConsumer
let path = require("path")
var crypto = require('crypto');
module.exports = function(source, sourceMap) {
this.cacheable()
this.async()
var self = this
@narrowtux
narrowtux / SimpleRandom.java
Created May 8, 2015 10:47
Pseudorandom implementation that is deterministic across the platforms Java and Arduino(AVR)
import java.util.Random;
public class SimpleRandom extends Random {
long seed;
public SimpleRandom(long seed) {
setSeed(seed);
}
@Override
@narrowtux
narrowtux / polymorphic_embed.ex
Created February 25, 2020 15:56
Polymorphic Embeds
defmodule PolymorphicEmbed do
@moduledoc """
Allows you to embed with an unknown schema at compile time.
The schema is decided by a `type_field` which could be an elixir module,
but also an enum which can be converted into a module with an `embedded_schema`.
"""
use Ecto.Type