Skip to content

Instantly share code, notes, and snippets.

Steve J Donovan stevedonovan

Block or report user

Report or block stevedonovan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stevedonovan
stevedonovan / shared.rs
Created Apr 14, 2017
An ergonomic way of saying Rc<RefCell>
View shared.rs
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
#[derive(Clone)]
struct Shared<T> {
v: Rc<RefCell<T>>
}
@stevedonovan
stevedonovan / ChartExample.java
Last active Jan 7, 2019
Android Example using AChartEngine to plot JSON data
View ChartExample.java
package com.example.testchart;
import java.util.*;
import java.io.*;
import java.text.DateFormat;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.*;
@stevedonovan
stevedonovan / css.lua
Created Aug 30, 2011
A little Lua DSL for generating CSS
View css.lua
--[[
A Lua module that defines a little DSL for generating CSS
-- csstest.lua
require 'css'
width = 500
lmargin = 50
leftm = 150
gap = 10
@stevedonovan
stevedonovan / csvdta.go
Created Dec 2, 2011
A Go package which reads structure data from CSV data using reflection
View csvdta.go
package csvdata
// csvdata complements the csv package by allowing you to map a custom structure to
// the columns of data in a CSV file. The struct needs to be annotated so that each
// field can match a column in the data
//
// type Person struct {
// FirstName string `field:"First Name"`
// Second_Name string
// Age int
// }
View common-rust-traits.md

What is a Trait?

In Rust, types containing data - structs, enums and any other 'aggregate' types like tuples and arrays - are dumb. They may have methods but that is just a convenience; they are just functions. Types have no relationship with each other.

Traits are the abstract mechanism for adding functionality to types and establishing relationships between them.

@stevedonovan
stevedonovan / closures.md
Last active May 19, 2018
Rust Closures Article
View closures.md

Why Rust Closures are (Somewhat) Hard

The Easy Case: Lua

Since hard is always relative to something else, I'd like to start with a dynamic language. Functions in Lua are essentially anonymous and can capture variables from their environment (pretty much like with JavaScript, which Lua resembles in several important ways):

@stevedonovan
stevedonovan / runner-article.md
Last active Dec 15, 2017
Temporary staging area for article
View runner-article.md

Cargo Manages Crates

Cargo is an important feature of the Rust ecosystem, using a central repository of versioned packages and ensuring reproducible builds. It has learned important lessons from more ad-hoc solutions like Go's 'go get' and is miles ahead from what is available for C++; it is like Maven, except TOML is easier to write and read than XML.

So suggesting that it is not ideal for some situations may come across as being perverse. I've seen people

@stevedonovan
stevedonovan / loader.lua
Created Oct 19, 2011
A Custom Lua module loader for Lua 5.2
View loader.lua
-- This allows a more restricted module() style; the key feature
-- is that each module is loaded in a custom environment, and the actual module
-- table is a copy of that environment after initial load.
-- clone _G so that globals from the program don't invade the module
local lua_libs = {}
for k,v in pairs(package.loaded._G) do
lua_libs[k] = v
end
@stevedonovan
stevedonovan / foo.c
Created May 25, 2012
A Lua script to embed Lua code in a C module.
View foo.c
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
static const char * lua_code = \
@stevedonovan
stevedonovan / html.lua
Created Sep 5, 2011
Orbit-style Htmlification using LuaExpatUtils
View html.lua
--[[
See http://steved-imaginaryreal.blogspot.com/2011/09/htmlification-with-lua.html
Example usage:
-- test2.lua
require 'html'
html {
body { title 'Test' },
h2 'title',
p 'first para',
You can’t perform that action at this time.