Skip to content

Instantly share code, notes, and snippets.

@ripter
ripter / gist:4270799
Created December 12, 2012 19:29 — forked from hashmal/gist:874792
Added check for boolean.
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint (tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
elseif type(v) == 'boolean' then
@ripter
ripter / event-offset-polyfill.js
Last active October 2, 2021 18:18
Adds MouseEvent .offsetX and .offsetY to Firefox
// polyfill for event.offsetX/offsetY
// Firefox is the only browser that doesn't support it (IE has since 4)
(function() {
var evt = document.createEvent('MouseEvent');
if (evt.offsetX === void 0) {
Object.defineProperties(MouseEvent.prototype, {
'offsetX': {
get: function() {
return this.layerX - this.target.offsetLeft;
}
@ripter
ripter / useValidationHook.ts
Created March 24, 2020 18:45
simple validation hook
export function useValidationHook(defaultItemState: Partial<KeywordAdItem>) {
// Allow partial a partial state to be used as the default/inital render.
let defaultState = {...DEFAULT_STATE};
if (defaultItemState) {
Object.assign(defaultState.item, defaultItemState);
}
return useReducer((state: State, action: Action) => {
const { field, value } = action;
// Create a shallow copy of the old data and add/repace the new value.
@ripter
ripter / updateList.ts
Created March 23, 2020 19:26
Reducer Array CRUD
/**
* Returns a new list, based on the previous list.
* Action describes how to create the new list.
* Shallow Copy
*/
export function updateList(prevList: objectList, action: KeywordDispatchAction): objectList {
const { type, listIndex, data } = action;
// console.group('Action', type);
switch (type) {
// https://threejs.org/examples/webgl_lights_hemisphere.html
AFRAME.registerShader('gradient', {
schema: {
timeMsec: {type: 'time', is: 'uniform'},
topColor: {type: 'color', is: 'uniform', default: '#0077ff'},
bottomColor: {type: 'color', is: 'uniform', default: '#ffffff'},
offset: {is: 'uniform', default: 33},
exponent: {is: 'uniform', default: 0.6},
},
raw: false,
[
["KIAA0141",-7.583179872,-0.03334987 ],
["EIF2AK1",-5.286158957,-0.038206876 ],
["URI1",-5.023483452,0.021195171 ],
["KIAA0947",-3.960840625,-0.389346067 ],
["TAZ",1.393157325,4.844039489 ],
["BRPF1",-3.668330762,-0.487446006 ],
["NELFE",-3.745420274,-0.603712746 ],
["GRSF1",-0.374317963,2.701531952 ],
["EIF4E2",-2.884958128,0.076901041 ],
[
["A1BG__P1_h3_Top5",-0.02149393,0.322957496 ],
["A1BG__P2_h3_Top5",-0.948661145,0.087967564 ],
["A1CF__P1P2_h3_Top5",-0.787883758,-0.14937761 ],
["AAAS__P1P2_h4_Top5",1.458158366,0.303433169 ],
["AADAC__P1P2_h3_Top5",-0.153730471,0.021665742 ],
["AAMP__P1P2_h3_Top5",-2.900039485,-2.12058401 ],
["AASDH__P1P2_h4_Top5",1.241920441,0.019673949 ],
["AASDHPPT__P1P2_h3_Top5",-0.753686771,-0.3382019 ],
["ABCA12__P1P2_h3_Top5",-2.208185006,-0.121822514 ],
@ripter
ripter / SandwichFactory.sol
Created August 10, 2018 20:43
Storage vs Memory in Solidity
// From: https://cryptozombies.io/en/lesson/2/chapter/7
contract SandwichFactory {
struct Sandwich {
string name;
string status;
}
Sandwich[] sandwiches;
function eatSandwich(uint _index) public {
pragma solidity ^0.4.0;
contract BOSGame {
struct Vote {
uint choice;
uint amount;
address owner;
}
mapping(address => Vote) playerVote;
@ripter
ripter / BankContract.sol
Created July 18, 2018 19:41
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.24;
contract BankContract {
uint balane;
function deposit() public payable {
balane += msg.value;
}
function getBalance() public view returns (uint) {