Skip to content

Instantly share code, notes, and snippets.

@neomantra
neomantra / thing-o-matic-command-line-update.md
Created January 14, 2014 04:30
Thing-o-matic Firmware Upgrade from command-line. Using the ReplicatorG and MakerWare I was getting errors like "upload failed".... and endlessly pressing reset and upload. This worked without any tricky timing. I did this on OSX, but I don't know why it wouldn't work similarly on another OS...

After spending two hours fucking with pushing my reset-button and clicking upload in both ReplicatorG and Makerware, I figured out how to do it from the command line. The command line was determined from running ReplicatorG on the console and trying to upgrade the firmware.

Install ReplicatorG

Download and install it from http://www.makerbot.com/sailfish/install/

Get the 4.4 firmware from Makerbot

wget http://firmware.makerbot.com/firmware/MB-mb24-2560-Sailfish-v4.4-r1029.hex
@neomantra
neomantra / spawn.lua
Last active December 22, 2017 09:38
Using LuaJIT FFI, spawn a Linux command in the background.
-- Spawn a command in the background, optionally redirecting stderr and stdout
--
-- requiring this file returns a function(cmd_line, stdout_redirect, stderr_redirect)
--
-- `cmd_line` is the command with possible arguments
-- optional `stdout_redirect` is io.stdout, io.stderr, or a filename. default/nil is io.stdout
-- optional `stderr_redirect` is io.stdout, io.stderr, or a filename. default/nil is io.stderr
--
-- Example:
-- luajit -e 'require("spawn")("cat /etc/network/interfaces", "foo1", io.stdout)'
@neomantra
neomantra / gethostbyname.lua
Created September 25, 2013 20:25
Exercising gethostbyname with LuaJIT FFI
#!/usr/bin/luajit
local ffi = require 'ffi'
ffi.cdef([[
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
@neomantra
neomantra / get_interrupt_affinity.sh
Created August 22, 2013 14:27
Scans for smp affinity for the interrupts on the passed interfaces.
#!/bin/bash
usage()
{
cat >&2 <<EOF
usage: $0 [-h] iface [iface2 [...]]
Scans for smp affinity for the interrupts on the passed interfaces.
Must be run as root.
@neomantra
neomantra / nanomsg_echo_client.c
Created March 18, 2013 21:33
Sample echo client for nanomsg
// gcc -o echo_client -g examples/echo_client.c -I ../nanomsg/src -L ../nanomsg/build -l nanomsg
// LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../nanomsg/build" ./echo_client foobar
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "nn.h"
#include "reqrep.h"
int main( int argc, const char* argv[] )
@neomantra
neomantra / nanomsg.lua
Last active January 14, 2016 09:18
LuaJIT FFI binding for nanomsg
--[[
nanomsg LuaJIT FFI binding
Copyright (c) 2013 Evan Wies <evan at neomantra dot net>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
@neomantra
neomantra / permute_string.lua
Last active December 14, 2015 14:39
permute_string: returns a table of all permutations of `str`
--- returns a table of all permutations of `str`
local function permute_string( str )
local string_byte, string_char = string.byte, string.char
local src = {}
for i = 1, #str do
src[i] = string_byte( str, i )
end
local perm = {}
#include <cstdint>
#include <iostream>
#include <unordered_map>
struct Foo
{
int a;
};
uint64_t some_func();
ffi.cdef([[
struct ifaddrs {
struct ifaddrs *ifa_next; /* Next item in list */
char *ifa_name; /* Name of interface */
unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */
struct sockaddr *ifa_addr; /* Address of interface */
struct sockaddr *ifa_netmask; /* Netmask of interface */
union {
struct sockaddr *ifu_broadaddr; /* Broadcast address of interface */
struct sockaddr *ifu_dstaddr; /* Point-to-point destination address */
@neomantra
neomantra / gist:1540945
Created December 30, 2011 18:35
luamongo dbclient_get_last_error
/*
* str = db:get_last_error()
*/
static int dbclient_get_last_error(lua_State *L) {
DBClientBase *dbclient = userdata_to_dbclient(L, 1);
string result = dbclient->getLastError();
lua_pushlstring(L, result.c_str(), result.size());
return 1;
}