Skip to content

Instantly share code, notes, and snippets.

@aharpole
aharpole / .powrc
Last active March 12, 2024 23:11 — forked from 8bitDesigner/.powrc
Everything you need to use RVM sanely. Check out the instructions in the rvm-setup file to get started.
if [ -f ".rvmrc" ]; then
source ".rvmrc"
fi
@aharpole
aharpole / badfizzbuzz.js
Created January 30, 2016 01:14
Remarkably wrong FizzBuzz
function counter(){
for (i=0; i<100; i++) {
var countThree=i/3;
var countSeven=i/7;
if (countThree.indexOf(“.”)==null){
document.write(i + “fizz”);
} else {
if (countSeven.indexOf(“.”)==null){
document.write(i + “buzz”);
} else {
@aharpole
aharpole / simple_genserver.ex
Created March 9, 2019 00:03
Simple GenServer with incrementing integer
defmodule IncrementableValue do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, [])
end
def init(_) do
{:ok, 1}
end
@aharpole
aharpole / defstruct.ex
Created March 9, 2019 00:04
defstruct for map based state gen servers blog post
defstruct [:value, :increment_by]
@aharpole
aharpole / type.ex
Created March 9, 2019 00:05
type for elixir blog post
@type t :: %__MODULE__{
value: integer,
increment_by: integer
}
@aharpole
aharpole / start_link.ex
Created March 9, 2019 00:05
new start_link
@aharpole
aharpole / new_init.ex
Created March 9, 2019 00:06
new init for elixir blog post
def init(%{increment_by: increment_by}) do
{:ok, %__MODULE__{value: 1, increment_by: increment_by}}
end
@aharpole
aharpole / handle_call.ex
Created March 9, 2019 00:06
new handle call
def handle_call(:get_data, _, %{value: value} = state) do
{:reply, value, state}
end
@aharpole
aharpole / handle_cast.ex
Created March 9, 2019 00:06
new handle cast
def handle_cast(:increment, state) do
new_state = Map.put(state, :value, &(&1 + state.increment_by))
{:noreply, state}
end