Skip to content

Instantly share code, notes, and snippets.

@mprymek
mprymek / langosh-plain.c
Created February 4, 2019 00:03
First Langosh language proof of concept implementation
/*
Just a small weekend experiment...
First experimental implementation of the Langosh language ("plain", i.e. really minimal version).
Langosh is meant to be a language which:
- can be easily machine-generated from Scratch-like visual programming tools (Blockly preferably)
- interpreter is small enough to fit in a small MCU (ATMega328 preferably)
/* Pleroma light theme customization */
#app {
background-image: none !important;
background-color: rgba(241, 241, 241, 1);
}
#heading {
background-image: none !important;
background-color: rgba(255, 255, 255, 1) !important;
/*
Golang's methods are not "virtual" or "overridable".
Don't expect OOP-like inheritance, use composition instead.
Try it here: https://play.golang.org/p/DujbnuHDZAW
*/
package main
@mprymek
mprymek / main.go
Last active February 25, 2018 11:23
/*
Basic Golang struct embedding example
Try it here: https://play.golang.org/p/HGfzu4m6AB8
*/
package main
@mprymek
mprymek / main.go
Last active February 24, 2018 10:02
/*
Duck typing in golang example.
You can try it here: https://play.golang.org/p/kHRnpmA206r
*/
package main
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Pop item at index i from list. Returns (item,new_list)
def pop2(l,i):
l1 = l[0:i]
l2 = l[(i+1):]
return (l[i],l1+l2)
def solve(numbers,goal):
solutions = []
for i in range(len(numbers)):
(num,numbers2) = pop2(numbers,i)
# Simple Phoenix authentication plug
#
# - based on Plug's session store
# - redirects unauthenticated requests to login page "/login/<request url>"
# - /static/... requests are not authenticated
# - authentication is valid as long as session is valid (you can change this behaviour easily)
# Because we need session to be fetched BEFORE this plug, we must put this to router.ex:
#----------------------------
defmodule TokenHolder do
require Logger
def start_link(user,passwd) do
Agent.start_link(fn ->
tok_time = get_token user, passwd
{user,passwd,tok_time}
end, name: __MODULE__)
end
@mprymek
mprymek / gist:c3c3cac7e25404811001
Created May 25, 2015 17:36
Untrusted code compilation experiment in Elixir
defmodule SafeCode do
def compile code do
# we can use [existing_atoms_only: true] here
{:ok, qcode} = code |> Code.string_to_quoted()
unless safe? qcode do
raise "Code is unsafe"
else
qcode |> Code.compile_quoted
end