Skip to content

Instantly share code, notes, and snippets.

@eric-wieser
eric-wieser / gist:2831136
Created May 29, 2012 22:16
Javascript key mapping
var keys = {up: 38, right: 39, down: 40, left: 37}; for(var i = 65; i < 91; i++) keys[String.fromCharCode(i+32)] = i;
if(location.search == "?music") {
//Do music!
var clientId = "dd250c3d9ef318565e6f22e871b87fb8";
var musicUrl = "http://soundcloud.com/alex-nicholls/snakes-theme";
$.getJSON(
'http://api.soundcloud.com/resolve.json?callback=?', {
url: musicUrl,
client_id: clientId
}, function(data) {
if(data.streamable && data.stream_url) {
groups:
default:
default: true
permissions:
- modifyworld.*
- bukkit.broadcast.user
- group.default
- ultimatearena.player
- hcw.ban.world.world
@eric-wieser
eric-wieser / 2.py
Created August 4, 2012 09:55 — forked from kragniz/2.py
A2S 2
#!/usr/bin/env python
import itertools
def f(a, b, c, d):
return a*b + b*c + c*d + a*d
print max(f(*p) for p in itertools.permutations([1,2,3,4]))
@eric-wieser
eric-wieser / Indent.tmPreferences
Created August 11, 2012 14:53 — forked from stravant/Indent.tmPreferences
Roblox Lua completion support for SublimeText
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Indent</string>
<key>scope</key>
<string>source.lua</string>
<key>settings</key>
<dict>
<snippet>
<content><![CDATA[for _, child in pairs(${1:parent}:GetChildren()) do
${0}
end]]></content>
<tabTrigger>children</tabTrigger>
<scope>source.lua</scope>
<description>iterate children</description>
</snippet>
@eric-wieser
eric-wieser / pyclass.lua
Created September 26, 2012 07:26
Python-style classes in lua
--quick implementation of python's id function. Fails for built in roblox objects
id = function(o)
return type(o) == "table" and o.__id__ or tonumber(tostring(o):sub(-8, -1). 16)
end
class = setmetatable({}, {
__call = function(_, name, implementer)
local cls = {__init__ = function() end, __name__ = name}
local instancemt = {}
@eric-wieser
eric-wieser / gist:3804277
Created September 29, 2012 15:03
Pythons MRO implemented in Lua
merge = function(seqs)
local res = {}
while true do
--filter out empty sequences
local nonemptyseqs = {}
for _, seq in ipairs(seqs) do
if #seq > 0 then table.insert(nonemptyseqs, seq) end
end
--all sequences empty? we're done!
if #nonemptyseqs == 0 then return res end
@eric-wieser
eric-wieser / itemset.lua
Last active August 9, 2024 02:47
A library to make inventory management with computercraft turtles more straightforward
local ItemSet = {}
ItemSet.__index = ItemSet
ItemSet.new = function(mapping)
return setmetatable({mapping=mapping}, ItemSet)
end
-- internal functions
local _useItem = function(self, fn, name)
local i = self:slot(name)
turtle.select(i)

Want to fork your own gists? No fork button? No problem! Install this user script by clicking refork.user.js' "raw" link down below: ⇓