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
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 / 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 / CMakeLists.txt
Last active Aug 3, 2016
An extension module for Lily provding extra string functions.
View CMakeLists.txt
include_directories("../src/")
add_library(xstr SHARED lily_xstr.c)
set_target_properties(
xstr
PROPERTIES
PREFIX ""
COMPILE_FLAGS "-fPIC -g"
)
@stevedonovan
stevedonovan / from.lua
Last active Aug 29, 2015
Utility module to simplify initializing locals from tables or modules.
View from.lua
local debug = require 'debug'
-- from.lua
-- supports some useful shortcuts when creating locals from tables or modules
-- require 'from'
-- local sin,cos,tan = slots(3) from(math)
-- local import,printf = slots(2) from 'pl.utils'
-- local pretty,utils,xml = slots(3) from 'pl.*'
--
-- Uses the debug library, so it's not very fast - only use for top-level initialization!
View luarocks.tags
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR steve.j.donovan@gmail.com
!_TAG_PROGRAM_NAME ltags //
!_TAG_PROGRAM_URL http://github.com/stevedonovan/ltags /official site/
!_TAG_PROGRAM_VERSION 0.1 //
Q fs\win32.lua /^function Q(arg)$/;" m struct:luarocks.fs.win32
Q fs\lua.lua /^function Q(arg)$/;" m struct:luarocks.fs.lua
_ fs\lua.lua /^local _, ftp = pcall(require, "socket.ftp")$/;" v file:
absolute_name fs\win32.lua /^function absolute_name(pathname, relative_to)$/;" m struct:luarocks.fs.win32
@stevedonovan
stevedonovan / append-test.lua
Created Nov 27, 2013
Some experiments with new Lua table functions.
View append-test.lua
require 'tablex'
local M = tonumber(arg[1]) or 10000
local N = tonumber(arg[2]) or 1000
local t_msg, t_start
function start_t (msg)
t_msg = msg
t_start = os.clock()
@stevedonovan
stevedonovan / install.lua
Created Sep 28, 2013
A simple Lua install script for Lua modules, extensions and scripts. Tested on Windows and Linux.
View install.lua
#!/usr/bin/env lua
--[[ -- installing LDoc
function install()
-- requires('pl','Penlight')
-- install_script 'ldoc'
end
--]]
-- --[[
@stevedonovan
stevedonovan / SciteUser.properties
Created Sep 2, 2013
SciTE User properties for working with Nimrod
View SciteUser.properties
tabsize=4
indent.size=4
use.tabs=0
split.vertical=0
open.dialog.in.file.directory=1
statusbar.visible=1
# treat Nimrod like Python
file.patterns.nim=*.nim
lexer.$(file.patterns.nim)=python
You can’t perform that action at this time.