Skip to content

Instantly share code, notes, and snippets.

View obmarg's full-sized avatar

Graeme Coupar obmarg

  • London
  • 00:27 (UTC +01:00)
View GitHub Profile
@enisdenjo
enisdenjo / graphiql-over-sse.html
Last active August 30, 2023 12:07
GraphiQL ❤️ graphql-sse
<!--
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* This code is licensed under the MIT license.
* Use it however you wish.
-->
<!DOCTYPE html>
<html>
<head>
@ruiramos
ruiramos / pattern-matching2.js
Last active January 19, 2022 14:58
Simple Javascript pattern matching
let a = [null, {status: 'OK'}];
switch_(
(err, _) => console.log('error', err),
(_, resp) => console.log('response', resp)
)(a);
// logs 'response' { "status": "OK" }
let b = [{err: 401}, null];
@coreyhaines
coreyhaines / Editable.elm
Last active August 25, 2022 05:11
type Editable
module Editable exposing (..)
type Editable ofType
= NotEditing { value : ofType }
| Editing { originalValue : ofType, buffer : ofType }
value : Editable ofType -> ofType
value editable =
@josevalim
josevalim / watcher.sh
Last active May 22, 2024 10:06
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | mix test --stale --listen-on-stdin
@Xion
Xion / lambdacode.py
Last active November 23, 2023 03:59
Retrieve source code of a (short) lambda -- http://xion.io/post/code/python-get-lambda-code.html
import ast
import inspect
import os
def get_short_lambda_source(lambda_func):
"""Return the source of a (short) lambda function.
If it's impossible to obtain, returns None.
"""
try:
@kcurtin
kcurtin / ex_unite_case_template.ex
Last active February 26, 2016 16:39
Using case templates to setup your database for integration tests with elixir and ecto.
defmodule DBTransactions do
use ExUnit.CaseTemplate
setup_all do
Ecto.Adapters.SQL.begin_test_transaction(Repo)
on_exit fn ->
Ecto.Adapters.SQL.rollback_test_transaction(Repo)
end
end
@henrik
henrik / say_when_real_guards.exs
Created December 31, 2015 16:43
Example of using real guard clauses in your own code with Elixir macros. Inspired by `plug :foo when action in [:create, :update]`. Also see https://gist.github.com/henrik/d21251bcf5d569e16ca9 for "fake" guard clauses that allow any condition/function to be used.
defmodule Lab do
defmacro say({:when, _, [message, condition]}) do
{result, _} = Code.eval_quoted(quote do
case true do
true when unquote(condition) -> true
true -> false
end
end)
if result do
@henrik
henrik / say_when.exs
Last active September 7, 2016 09:03
Example of using "guard clauses" in your own code with Elixir macros. Inspired by `plug :foo when action in [:create, :update]`. This implementation accepts any types of conditions, not just the subset allowed in actual guard clauses. But also see https://gist.github.com/henrik/68f136f9916165e0defb for an implementation with real guard clauses.
defmodule Lab do
defmacro say({:when, _, [message, condition]}) do
{result, _} = Code.eval_quoted(condition)
if result do
quote do
IO.puts unquote(message)
end
end
end
@mbbx6spp
mbbx6spp / ALTERNATIVES.adoc
Last active April 25, 2024 15:14
Super quick list of alternatives to Jira and/or Confluence, Stash, Crucible, etc.
@BinaryMuse
BinaryMuse / README.md
Last active April 20, 2022 21:45
Elixir Map/HashDict Performance on Erlang OTP R17 vs R18