Skip to content

Instantly share code, notes, and snippets.

@import url('https://github.com/adobe-fonts/source-serif/blob/release/source-serif-display.css');
{
font-family: 'Source Serif', serif;
}
@BadBastion
BadBastion / elo.js
Last active August 21, 2020 06:21
Basic ELO sheets function
const STARTING_ELO = 100
const K = 2
function normalized_win_probability(player_elo, total_game_elo, player_count) {
const avg_opponent_elo = (total_game_elo - player_elo) / (player_count - 1)
// Standard ELO algorithm with opponent ELO avged because we have more than one opponent
const win_probability = 1 / (1 + Math.pow(10, (avg_opponent_elo - player_elo) / STARTING_ELO))
// Normally ELO is calculated for 1 vs 1 games. We need to normalize the probability with the number of players.
@BadBastion
BadBastion / VPOD_spawning_snipits.py
Last active February 8, 2019 19:31
VPOD spawning snipits
# VPOD spawning utils file sinipits
# Spawning new VPODs
# Also checks the JSON responce for errors and throws if VPODs api errored
def __check_json_for_errors(json):
error_name = f"Error {json.get('error')}: " if json.get('error') else ''
error_msg = f"\"{json.get('message')}\"" if json.get('message') else ''
error_full = f"Error: {json.get('errorMsg')}" if json.get('errorMsg') else ''
error = f'{error_name}{error_msg}{error_full}'
defmodule Sizzle.FlameFormaters.FlameEvent do
def unknown_event(unknown_log_line) do
# At a later date I should probably refactor this into something with more information
unknown_log_line
end
def frame_start(request_time, frame_type, frame_name, line_number, tags \\ %{}) do
%{
"event" => "Frame.start",
"time" => request_time,
@BadBastion
BadBastion / same.ex
Last active July 19, 2017 21:10
Both are basically the same
[1,2,3] |> map(fn number -> my_function(number) end)
[1,2,3] |> reduce([], fn number, acc -> acc ++ [ my_function(number) ] end)
@BadBastion
BadBastion / increment.ex
Last active July 19, 2017 18:34
Increment LL cursor
def increment(enums, head) do
# enums, and all of their heads (start of list)
# accumulator = {carry, enums}
zip(enums, head)
|> foldr({true, []}, fn
{[_ | []], head}, {true, acc} -> {true, [head | acc]}
# {if the list has no more elements} and {carry in} -> {carry out and set back to begining on list (head)}
{[_ | tail], _head}, {true, acc} -> {false, [tail | acc]}
# {if the list does have more elements} and {carry in} -> {do NOT carry out and move to next element in list (tail)}
{enum, _head}, {false, acc} -> {false, [enum | acc]}
@BadBastion
BadBastion / BreadthFirst.ex
Last active May 11, 2017 01:10
Improved breadth first product
defmodule BreadthFirst do
defp init_cursor(dimension) do (for _ <- 1..dimension, do: 0) end
defp increment_cursor(cursor, depth, max, carry) do
cursor
|>List.foldr(
{carry, false, []},
fn elem, {carry, unique, acc} ->
case elem + carry do
defmodule T do
defp init_cursor(dimension) do (for _ <- 1..dimension, do: 0) end
defp increment_cursor(cursor, depth) do
max = depth-1
cursor
|>List.foldr(
{1, false, []},
defmodule Test do
defp add(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
reverse(p, {j, list_i}, {i+1, list_j}, max)
end
defp reverse(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
@BadBastion
BadBastion / new_gist_file_0
Created October 10, 2015 18:37
Javascript getters and setters
var person = {sutff:"stuff"};
Object.defineProperty(person, 'fullName', {
get: function() {
return firstName + ' ' + lastName;
},
set: function(name) {
var words = name.split(' ');
this.firstName = words[0] || '';
this.lastName = words[1] || '';
}