Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am badcc on github.
  • I am badcc (https://keybase.io/badcc) on keybase.
  • I have a public key whose fingerprint is 6410 C592 E518 BF12 9E27 D51F E989 C9CB 5A73 9B21

To claim this, I am signing this object:

@badcc
badcc / EasingFunctions.lua
Last active December 30, 2017 20:49
Simple, clean easing functions in Lua. Will add more as I need them.
-- Input: Time value scaled [0,1]
-- Output: Transformed time value
local function Ease_InOutQuad(t)
return t<0.5 and 2*t*t or -1-2*(t-2)*t
end
local function Ease_OutQuad(t)
return -(t-2)*t
end
local function Ease_InBack(t)
local s = 1.70158
@badcc
badcc / RobloxServerFindAutoJoin.js
Last active July 13, 2017 02:07
Binary search. Some logic. Some API stuff. Quite hacked together.
// @badccvoid
var PLACE_ID = 539494517
var TARGET_PLAYERS = 7
var queue = [0]
function req(placeid, startindex, cb) {
$.get('https://www.roblox.com/games/getgameinstancesjson?placeId='+placeid+'&startindex='+startindex, cb)
}
function finish(id) {
console.log('found maximum', id)
var list=[];var items = $('.items-container:last table tbody tr td.name-col a.title'); for (var i = 0; i < items.length; i++){ list.push(items[i].href) }; console.log(list.join('\n'))
-- How many pixels (width) is 1 stud at depth d from camera
local function DepthToPixels(Depth)
local Camera = workspace.CurrentCamera
local Viewport = Camera.ViewportSize
local Ratio = Viewport.X/Viewport.Y
local h = math.tan(math.rad(Camera.FieldOfView)*0.5)
return Viewport.X/(2*Depth*h*Ratio)
end
print(DepthToPixels(1))
@badcc
badcc / DoNotUseThis.lua
Created May 27, 2017 19:24
Meta hax. I tried using __lt to get `#include<` but working but you can't compare table/userdata with strings. This is good enough.
local _ = function() end
local include=setmetatable({},{__call=function(b,c)local d=newproxy(true)local e=getmetatable(d)e.__len=function()print('You included:',c)end return d end})
_(
#include 'stdio.h',
#include 'test'
)
--> You included: stdio.h
--> You included: test
local FormatSeconds do
-- Seconds: %s; Minutes: %m; Hours: %h
-- Days: %D; Months: %M; Years: %Y
local floor = math.floor
local q={60,60,24,365/12,12} -- Remove/add from here to change max precision from years to some other value.
local m={['s']=1,['m']=2,['h']=3,['D']=4,['M']=5,['Y']=6}
local qb={1}
for i = 1,#q do table.insert(qb,1,q[i]*qb[1]) end
function FormatSeconds(f,t)
local r={}
-- Easy use
local Price0 = 50
local Sales0 = 10000
local Visits0 = 50000
local Price1 = 200
local Sales1 = 9000
local Visits1 = 70000
-- Math :)
local p0,s0,p1,s1=Price0,Sales0,Price1,Sales1*(Visits0/Visits1)
local m=(s1-s0)/(p1-p0)
@badcc
badcc / ChangeClassName.lua
Last active April 14, 2017 19:52
Change ClassName of Roblox instance (using Anaminus' API dump)
local ClassName = 'TextButton'
local Object = game.Selection:Get()[1]
local HttpService = game:GetService('HttpService')
local API = HttpService:JSONDecode(HttpService:GetAsync('http://anaminus.github.io/rbx/json/api/latest.json'))
local function ChangeClass(ClassName, Object, NewObject)
for _,v in next,API do
if (v['type'] == 'Class' and v['Name'] == ClassName and v['Superclass']) then
ChangeClass(v['Superclass'], Object, NewObject)
elseif (v['type'] == 'Property' and v['Class'] == ClassName) then
pcall(function() -- If property is not allowed to be changed, do not error.
-- FastBuffer
-- @BadccVoid
-- Tell me if you have optimizations!
local pow,log,ceil,floor=math.pow,math.log,math.ceil,math.floor
local insert,concat=table.insert,table.concat
local char,byte=string.char,string.byte
local abs=math.abs
local frexp,ldexp=math.frexp,math.ldexp
local log2=log(2)