Skip to content

Instantly share code, notes, and snippets.

View bmwalters's full-sized avatar

Bradley Walters bmwalters

  • Affirm
  • United States
View GitHub Profile
@bmwalters
bmwalters / hashleet.lua
Created October 12, 2015 02:11
hash.js leet
cookie.maymays.leetwords = {destroyed = "rekt"}
cookie.maymays.leetpatts = {["(%w+)er"] = "%1or", ["hack(%w+%s)"] = "haxor%1"}
cookie.maymays.leetchars = {a = 4, ["4"] = "a", e = 3, ["3"] = "e", o = "0", ["0"] = "o", l = "1", ["1"] = "l", s = "5", ["5"] = "s", t = "7", ["7"] = "t"}
cookie.maymays.leet = function(inp)
inp = string.lower(inp)
for patt, replacement in pairs(cookie.maymays.leetpatts) do
inp = string.gsub(inp, patt, replacement)
end
for word, replacement in pairs(cookie.maymays.leetwords) do
inp = string.gsub(inp, " "..word.." ", " "..replacement.." ")
@bmwalters
bmwalters / maybe.py
Created November 14, 2015 03:15
Object that acts like a boolean, but may be True or False
import random
class _Maybe(object):
def __nonzero__(self):
return bool(random.getrandbits(1))
def __repr__(self):
return repr(self.__nonzero__())
def __str__(self):
@bmwalters
bmwalters / array2arnoldcfunc.lua
Created November 22, 2015 04:28
converts a lua array to an arnoldc function
local template_start = [[
LISTEN TO ME VERY CAREFULLY %s
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE key
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE val
YOU SET US UP 0
HEY CHRISTMAS TREE isKeyEqualToOurCurrentValue
YOU SET US UP @I LIED
@bmwalters
bmwalters / basecalc.lua
Last active December 17, 2015 04:10
anybase^tm calculator (for some reason)
local charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function ToBase10(num, curbase) -- tonumber has a static charset, we might want to change it in the future so we roll our own
local out = 0
num = tostring(num)
for i = 1, #num do -- this goes left to right
local cur = string.sub(num, i, i)
local val = string.find(charset, cur)
if not val then error("Number '" .. cur .. "' in base " .. curbase .. " not supported by charset '" .. charset .. "'") return end
@bmwalters
bmwalters / b1count.lua
Last active January 13, 2016 22:23
Counts my B1s
local function GetB1Count(sid, callback)
http.Fetch(string.format("http://steamcommunity.com/profiles/%d/inventory/json/753/6", sid), function(c, b)
if c ~= 200 then print("bad code", c) callback(false) return end
local data = json.decode(b)
if data and data.rgInventory then
local count = 0
for _, info in pairs(data.rgInventory) do
if info and tonumber(info.classid) == 171857344 then
count = count + 1
@bmwalters
bmwalters / coolnumbers.py
Created February 9, 2016 16:49
Cool Numbers (http://www.coolnumbers.com) API for Python
import requests
import re
pat_coolness = re.compile(r"<b>Universal Coolness Index</b></a> of <i>([\d\.]+?)%</i>")
pat_attribute = re.compile(r"<li>(.+?)[\.!].+?([\d\.]+?)\%")
pat_tags = re.compile(r"<[^>]+>")
def coolness_to_string(num):
if num >= 99:
@bmwalters
bmwalters / rotatopotato.user.js
Last active April 13, 2016 15:43
shift+p to activate
// ==UserScript==
// @name Rotato Potato
// @namespace zerf
// @description Yep
// @include *
// @version 1.3
// @downloadURL https://gist.github.com/zerfgog/3695d12eac2061f6e29930d7c4fb91ff/raw/master/rotatopotato.user.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// ==/UserScript==
@bmwalters
bmwalters / examples_superfuncs.lua
Last active April 17, 2016 01:15
Lua SuperFuncs!
require("superfuncs")
-- example_variables
local function has_variables()
self.call = self.call + 1
print("congratulations! you are has_variables caller number", self.call)
end
has_variables = f(has_variables)
has_variables.call = 0
@bmwalters
bmwalters / Facepunch_GLua_Wiki_Tokenizer.user.js
Last active August 30, 2016 23:29
Get the power of the GLua Wiki Tokenizer in your Facepunch [lua] tags!
// ==UserScript==
// @name Facepunch GLua Wiki Tokenizer
// @namespace zerf
// @description Get the power of the GLua Wiki Tokenizer in your Facepunch [lua] tags!
// @version 1.5
// @include https://facepunch.com/showthread.php*
// @downloadURL https://gist.github.com/bmwalters/6d4cc5499378711de0f46028e565cc8d/raw/master/Facepunch_GLua_Wiki_Tokenizer.user.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @run-at document-start
// @grant GM_xmlhttpRequest
@bmwalters
bmwalters / set.lua
Last active November 20, 2016 02:59
Yet another Lua Set class
local SET = {}
if gmod then debug.getregistry().Set = SET end
function SET:Add(item)
self._data[item] = true
end
function SET:Remove(item)
self._data[item] = nil