Skip to content

Instantly share code, notes, and snippets.

@octosteve
octosteve / genserver.rb
Created December 11, 2020 00:22
GenServer implementation in Ruby
class Stack
def self.start_link(state)
GenServer.start_link(new(state))
end
def self.push(ractor, value)
GenServer.cast(ractor, [:push, value])
end
def self.pop(ractor)
#!/bin/bash
old="$IFS"
IFS='_'
notes_dir="~/Documents/notes"
filename="$*"
sep=""
date=$(date +'%Y-%m-%d')
IFS=$old
if [ $filename != "" ]; then
sep="-"
@octosteve
octosteve / fake_dux.ex
Created June 20, 2019 14:13
Separate state
defmodule Reducer do
use GenServer
def start_link(state_pid, options \\ []) do
GenServer.start_link(__MODULE__, state_pid, options)
end
def init(state_pid) do
{:ok, %{state_pid: state_pid}}
end
defmodule Store do
@initializer_action %{type: "@@INIT"}
# Code your Mom calls
def start_link(reducer, initial_state \\ nil) do
GenServer.start_link(__MODULE__, [reducer, initial_state])
end
def get_state(store) do
require 'pry'
def r_count(list)
return 0 if list.empty?
_head, *tail = list
1 + r_count(tail)
end
def r_sum(list)
return 0 if list.empty?
head, *tail = list
// function showVideo(localMediaStream) {
// var video = document.querySelector('video');
// video.src = window.URL.createObjectURL(localMediaStream);
// }
//
// navigator.webkitGetUserMedia({video: true, audio: true}, function(localMediaStream) {
// showVideo(localMediaStream)
// }, function(e){
// console.log("Noooope");
// });
var Person = (function() {
'use strict';
// using named expressions for no special reason
var sayHi = function(){
console.log(`Hi, it's ${this.name}`);
}
var addFriend = function (friendName) {
this.friends.push(friendName)
};
// // var me = {
// // name: "Steven",
// // sayHi: function(){
// // console.log(`Hi, my name is chicka chicka ${this.name}`);
// // }
// // }
//
// function Person(name){
// this.name = name
// this.friends = []
def create(%{req_headers: headers, remote_ip: remote_ip, request_path: path, body_params: payload, query_params: query_params} = conn, %{"source" => source }) do
Task.async fn ->
merged_headers = headers
|> add_path(path)
|> add_ip(remote_ip)
|> Enum.into(%{})
changeset = Event.validate(%Event{}, source, merged_headers, payload, query_params)
case Repo.insert(changeset) do
{:ok, event} ->