Skip to content

Instantly share code, notes, and snippets.

View makoConstruct's full-sized avatar

mako yass makoConstruct

View GitHub Profile
@makoConstruct
makoConstruct / easingWithInitialVelocity.rs
Last active April 27, 2016 10:15
Methods for easing in and out at constant accelerations, starting with a given velocity and ending at 0.
//an easing function that eases in and out by constant acceleration in either direction (parabolic), that allows the user to specify a starting velocty. This allows a user to interrupt the animation partway through and send it in a different direction without any sudden jerks.
fn sq(a:f32)-> f32 { a*a }
//I'm including these because the way the constant acceleration functions handle cases where initial_velocity > 2 doesn't look very good, it overshoots the target, then comes back to it. You will probably prefer to use these linear acceleration-deceleration functions for those cases instead. You might like to use them instead of constant acceleration methods altogether, but I find they look a bit too jerky.
fn linear_acceleration_ease_in_out_with_initial_velocity(t:f32, initial_velocity:f32)-> f32 {
t*(t*((initial_velocity - 2f32)*t + (3f32 - 2f32*initial_velocity)) + initial_velocity)
}
@makoConstruct
makoConstruct / hex_spiral.rs
Last active April 17, 2016 08:12
An iterator that spirals out over the cells of a hexagonal grid
use std::iter::Iterator;
//for hex schemes like this:
//. . x->
// . . .
// y . .
// \
// v
#[derive(Debug)]
@makoConstruct
makoConstruct / relsat.rs
Created March 9, 2016 00:32
A frustratingly incomplete illustration of what textual relsat code might be like
//let's break down the highlevel relsat code:
addAndTriple := fn a b ->
3*(a + b)
//First we'll break down the syntactical sugars until we can see how it translates to a tree
//note that each of these stages are valid rel code, it's all equivalent.
(:= addAndTriple fun( vars(a b) block(
3*(a + b)
//ImportByProxySuccess.hx
using A;
class Main{
var b:B;
static public function main(){
trace("runs fine");
}
}
@makoConstruct
makoConstruct / timed_functions
Created April 16, 2015 00:08
scheduled tasks functions for nouvion
#usage: schedule_scheduled_task(time:Time, task_name:String, task_parameter:String)
# runs the function task_name refers to(big trouble if it doesn't refer to a function) with task_parameter.
# Will record the task to DB if the bot is shut down. Will restore to the schedule when bot is restarted.
#TODO:
# implement schedule_task(time, callback) [where time is the time at which it should run, rather than how long till it should run]
# do we have simple memory access shims for mem_load_all(key), and mem_save(key, value)? If not, we should, please write them.
# mem_delete_k_v(key, value) , this is new functionality, but greatly needed
# run reinstate_scheduled_tasks on initialization (note, may execute tasks during the call, make sure initialization is at a stage where it's ready for that)
# should work at that point.
@makoConstruct
makoConstruct / dependent types in a nicer scala
Last active August 29, 2015 14:18
Application of dependent types
class SizedArray[V, length:Int]
def zipmap[T, otherLength:Int](f:(V, V)=>T, other:SizedArray[otherLength,T]):SizedArray[math.min(length, otherLength),T] =
const val minLength = math.min(length, otherLength)
retval = new SizedArray[V,minLength]
for i in range(0, minLength)
retval(i) = f(this(i), other(i))
return retval
class Array[V]
def zipmap[T](f:(V, V)=>T, other:Array[T]):Array[T] =
@makoConstruct
makoConstruct / basicProgram.termpose
Created March 27, 2015 05:49
example of the termpose representation of a simple Treesh0 program.
def
name a
type Int32
assign
i 1
def
name b
type Int32
assign
//no annotations, executing:
performing macro expansion julienrf.variants.Variants.format[controllers.Application.SA] at source-/home/mako/programming/calf/app/controllers/Application.scala,line-23,offset=545
play.api.libs.json.Format[SA](play.api.libs.json.Reads[SA](((json) => json.$bslash(Impl.this.defaultDiscriminator).validate[String].flatMap(<empty> match {
}))), play.api.libs.json.Writes[SA](<empty> match {
}))
Apply(TypeApply(Select(Select(Select(Select(Ident(newTermName("play")), newTermName("api")), newTermName("libs")), newTermName("json")), newTermName("Format")), List(Ident(controllers.Application.SA))), List(Apply(TypeApply(Select(Select(Select(Select(Ident(newTermName("play")), newTermName("api")), newTermName("libs")), newTermName("json")), newTermName("Reads")), List(Ident(controllers.Application.SA))), List(Function(List(ValDef(Modifiers(PARAM), newTermName("json"), TypeTree(), EmptyTree)), Apply(Select(TypeApply(Select(Apply(Select(Ident(newTermName("json")), newTermName("$bslash")),
@makoConstruct
makoConstruct / UISpec.coffee
Created October 12, 2014 03:20
code for specifying and switching between modal UIs
class UIMode
constructor = (uiControls, subModes = [], inf = ()->, out = ()->)->
@uiControls = uiControls
#hides all uiControls managed by the system until their mode comes up
for con in uiControls
con.style.opacity = 0
con.style.display = 'none'
@subModes = subModes
for subs in subModes
subs.parent = @
@makoConstruct
makoConstruct / gist:336a91ddb06c1b17bca4
Created September 14, 2014 23:53
Possible bug about an inconsistency between borrowing from boxeds and borrowing from &muts
struct Thing{ a: u8, b: u8 }
fn main(){
let mut boxed_thing = box Thing{a:2, b:2};
let btr = &mut boxed_thing;
let mut unboxed_thing = Thing{a:3, b:3};
let utr = &mut unboxed_thing;
fn pass(a:&mut u8, b:&mut u8){}
pass(&mut utr.a, &mut utr.b); //< this is allowed
pass(&mut btr.a, &mut btr.b); //< while this is not.
//error: cannot borrow `btr.b` as mutable more than once at a time