Skip to content

Instantly share code, notes, and snippets.

View neenjaw's full-sized avatar
:shipit:
Shippin' code

Tim Austin neenjaw

:shipit:
Shippin' code
View GitHub Profile
@henrik
henrik / test_helper.exs
Last active June 10, 2020 20:16
Improved `assert_compile_time_raise` based on this comment by Andrea Leopardi: http://andrealeopardi.com/posts/compile-time-work-with-elixir-macros/#comment-2347206739
ExUnit.start()
defmodule CompileTimeAssertions do
defmacro assert_compile_time_raise(expected_exception, expected_message, fun) do
# At compile-time, the fun is in AST form and thus cannot raise.
# At run-time, we will evaluate this AST, and it may raise.
fun_quoted_at_runtime = Macro.escape(fun)
quote do
assert_raise unquote(expected_exception), unquote(expected_message), fn ->
@timruffles
timruffles / dyanmic_or_di_elixir.md
Last active June 11, 2020 04:23
Approaches to dependency-injection/dynamic dispatch in elixir

In many production systems you'll want to have one module capable of talking to many potential implementations of a collaborator module (e.g a in memory cache, a redis-based cache etc). While testing it's useful to control which module the module under test is talking to.

Here are the approaches I can see. The two points that seem to divide the approaches are their tool-ability (dialyzer) and their ability to handle stateful implementations (which need a pid).

Passing modules

Modules are first class, so you can pass them in. Used in EEx, where passed module must implement a behaviour.

@SleeplessByte
SleeplessByte / aoc-2020-d5.rb
Last active December 5, 2020 06:41
Advent of Code 2020: Day 5 - Binary Boarding
require 'benchmark'
class BoardingPass
def self.from_binary(binary_position)
rows = binary_position[0...7].tr("FB", "01")
columns = binary_position[7..].tr("LR", "01")
BoardingPass.new((rows + columns).to_i(2))
end
if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)) {
//is IE 11 or below
}
@Shmarkus
Shmarkus / elk-docker-compose.yml
Last active February 1, 2022 13:41
ELK stack (version 7.16.3) Docker compose bundle
version: "3"
services:
elasticsearch:
image: elasticsearch:7.16.3
container_name: elasticsearch
restart: unless-stopped
environment:
- node.name=elasticsearch
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=elasticsearch
@apal21
apal21 / ES5 class.js
Last active March 7, 2023 08:06
Example for blog to show the difference between ES5 and ES6 javascript classes using inheritance and prototypes use cases.
'use strict';
/**
* Person class.
*
* @constructor
* @param {String} name - name of a person.
* @param {Number} age - age of a person.
* @param {String} gender - gender of a person.
*/
@vaibhavmule
vaibhavmule / first-things.sh
Last active March 22, 2023 17:58
First Thing To Do After Installing Any Linux OS.
echo "Updating" &&
sudo apt-get update
echo "Upgrading" &&
sudo apt-get dist-upgrade
echo "Cleaning Up" &&
sudo apt-get -f install &&
sudo apt-get autoremove &&
sudo apt-get -y autoclean &&
@wesbos
wesbos / download-shows.ts
Created November 11, 2020 02:07
deno syntax episode downloader
// deno run --allow-net --allow-write download-shows.ts
import { download } from "https://deno.land/x/download/mod.ts";
const showList = 'https://syntax.fm/api/shows';
async function getShowList(): Promise<Show[]> {
const list = await (await fetch(showList)).json();
return list;
}
@Morse-Code
Morse-Code / stringReverse.c
Created April 4, 2013 12:36
Reverse a C string using bitwise XOR operator.
void stringReverse(char *str)
{
char *p1, *p2;
if (!str || !*str)
{
NSLog(@"No string passed into reverse function.");
}
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
@DarinM223
DarinM223 / Concepts.md
Last active February 9, 2024 16:02
Rust concept explanations

My explanation of the main concepts in Rust

There are three main concepts with Rust:

  1. Ownership (only one variable "owns" the data at one time, and the owner is in charge of deallocating)
  2. Borrowing (you can borrow a reference to an owned variable)
  3. Lifetimes (all data keeps track of when it will be destroyed)

These are fairly simple concepts, but they are often counter-intuitive to concepts in other languages, so I wanted to give a shot at