Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Terkwood's full-sized avatar
🦑

Terkwood Terkwood

🦑
  • Salesforce
  • Indiana, USA
  • 03:28 (UTC -04:00)
View GitHub Profile
# Controller option 1, implicit render selected based on format
defmodule MyApp.UserController do
use Phoenix.Controller
def show(conn, %{"id" => id}) do
render conn, :show, user: Repo.get(User, id)
end
end
# Controller option 2, explicit render with format pattern match
@Terkwood
Terkwood / install_elixir.md
Created July 12, 2021 19:44 — forked from rubencaro/install_elixir.md
Elixir installation guide

Elixir installation guide

Version numbers should be the ones you want. Here I do it with the last ones available at the moment of writing.

The simplest way to install elixir is using your package manager. Sadly, at the time of writing only Fedora shows the intention to keep its packages up to date. There you can simply sudo dnf install erlang elixir and you are good to go.

Anyway, if you intend to work with several versions of erlang or elixir at the same time, or you are tied to a specific version, you will need to compile it yourself. Then asdf is your best friend.

@Terkwood
Terkwood / Lambda.scala
Created March 8, 2021 19:33 — forked from RaasAhsan/Lambda.scala
Type-level, untyped lambda calculus in Scala 3
object Lambda extends App {
sealed trait Term
sealed trait Var[I <: Index] extends Term
sealed trait App[T1 <: Term, T2 <: Term] extends Term
sealed trait Abs[T1 <: Term] extends Term
sealed trait If[T1 <: Term, T2 <: Term, T3 <: Term] extends Term
sealed trait Bool[T1 <: Boolean] extends Term
sealed trait Index
@Terkwood
Terkwood / global-gitignore.md
Created March 6, 2021 15:57 — forked from subfuzion/global-gitignore.md
Global gitignore

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

git config --global core.excludesfile ~/.gitignore

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore

#Inject javascript into HTML pages from console

An easy way to inject Javascripts into the current loaded dom using the developer console in chrome.

jQuery

var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.7.2.min.js';
@Terkwood
Terkwood / gist:89348347bb11ed58d7b38c1d5217de67
Created January 17, 2021 14:02 — forked from danking/gist:1068185
A very simple example showing how to use Racket's lexing and parsing utilities
#lang racket
(require parser-tools/lex
(prefix-in re- parser-tools/lex-sre)
parser-tools/yacc)
(provide (all-defined-out))
(define-tokens a (NUM VAR))
(define-empty-tokens b (+ - EOF LET IN))
(define-lex-trans number
(syntax-rules ()
@Terkwood
Terkwood / writeup.md
Created November 30, 2020 17:14 — forked from edmundsmith/writeup.md
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

@Terkwood
Terkwood / brainfuck.hs
Created April 23, 2020 14:41
A brainfuck interpreter written in Haskell typeclasses
{-# LANGUAGE
TypeOperators, MultiParamTypeClasses, FunctionalDependencies,
FlexibleInstances, UndecidableInstances
#-}
module Brainfuck where
{- Usage:
Programs are encoded as cons-lists chained by (:-) and terminated by C0.
@Terkwood
Terkwood / README.md
Created March 20, 2020 22:21 — forked from tetkuz/README.md
GStreamer stream to HTML5

Description

[Server] GStreamer ---> HTML [Client]

Require

  • gstreamer-1.x
  • Browser which supports video tag of HTML5

debian

@Terkwood
Terkwood / build_VC4CL_rpi_3Bplus.sh
Last active March 1, 2020 16:17 — forked from aumouvantsillage/Building VC4CL
Building VC4C and VC4CL on a Raspberry Pi 3 with Raspbian Stretch
sudo apt install git cmake clang-3.9 opencl-headers ocl-icd-dev ocl-icd-opencl-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 100
git clone https://github.com/doe300/VC4C.git
git clone https://github.com/doe300/VC4CL.git
git clone https://github.com/doe300/VC4CLStdLib.git
cd VC4C
cmake -DBUILD_TESTING=OFF -DSPIRV_FRONTEND=OFF