Skip to content

Instantly share code, notes, and snippets.

@mrjoelkemp
mrjoelkemp / Outline.shader
Last active August 18, 2023 04:24
Unity 3D Outline Shader - adds a configurable outline around the associated object
// Graciously adapted from https://www.youtube.com/watch?v=SlTkBe4YNbo&lc=UgwdZi_heg9VslLssQp4AaABAg
Shader "Unlit/Outline"
{
Properties{
_Color("Main Color", Color) = (0,0,0,1)
_OutlineColor("Outline color", color) = (0,0,0,1)
_OutlineWidth("Outline width", Range(1.0,5.0)) = 1.01
}
SubShader{
defmodule Game do
require Board
defstruct board: %Board{}
def is_complete?(%Game{ board: board } = game) do
Board.has_winner?(board) or Board.is_draw?(board)
end
end
defmodule MyViewTest do
use MyAppWeb.ConnCase
import Phoenix.LiveViewTest
import Mock
require MyView
require MyDataFetcher
test "it renders the fetched data", %{conn: conn} do
defmodule MyView do
use MyAppWeb, :live_view
def mount(_params, _session, socket) do
send(self(), {:load_data})
{:ok,
assign(socket,
data: ""
)}
@mrjoelkemp
mrjoelkemp / go-defer.js
Last active December 22, 2017 09:48
Go-style defer without dependency injection
var deferrable = function (cb) {
function getFunctionBody(code) {
var functionDef = code.match(/\{(.|[\r\n])+\}/);
// Strip body of all useless chars
return functionDef[0].replace(/\{|\}/g, '')
}
var
// Grab the entire defer() block
@mrjoelkemp
mrjoelkemp / parseFunctionArguments.js
Created September 11, 2013 14:54
For every function on a given object, set up the function to auto-parse stringified arguments. Use case: In Flash to Javascript communication, this avoids the need to manually parse for every JS api endpoint.
function parseFunctionArguments (obj) {
for (var method in obj) {
if (obj.hasOwnProperty(method) && typeof obj[method] === 'function') {
(function (method) {
var func = obj[method];
obj[method] = function () {
// Try to convert each string arg into an object literal
var converted = [].map.call(arguments, function (v) {
if (typeof v === 'string') {