Skip to content

Instantly share code, notes, and snippets.

@okwme
okwme / solidity - uint to hex string
Last active November 6, 2018 21:52
solidity - uint to hex string
function uint2hexstr(uint i) internal pure returns (string) {
if (i == 0) return "0";
uint j = i;
uint length;
while (j != 0) {
length++;
j = j >> 4;
}
uint mask = 15;
bytes memory bstr = new bytes(length);
@okwme
okwme / Upgradeable Metadata for NFT
Last active March 22, 2018 23:42
an attempt at an upgradeable metadata function for standard NFT
pragma solidity ^0.4.17;
pragma experimental ABIEncoderV2;
import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
contract NFT is ERC721Token, Ownable {
address private metadataContractAddress;
pragma solidity ^0.4.13;
contract ReversiContract {
// example moves = [[4,3],[3,3],[3,4],[3,5],[4,6],[6,4],[6,3],[5,3],[4,2],[5,2],[2,5],[2,6],[6,2],[5,6],[3,6],[6,5],[7,3],[6,6],[7,5],[5,7],[4,7],[6,7],[7,6],[7,4],[1,6],[8,6],[8,4],[8,2],[8,3],[8,5],[5,8],[1,5],[6,8],[1,7],[1,4],[1,3],[2,4],[3,1],[5,1],[3,7],[3,2],[3,8],[4,8],[7,8],[7,7],[7,1],[7,2],[2,1],[2,2],[8,1],[2,7],[2,8],[1,8],[8,7],[8,8],[2,3],[1,1],[4,1],[6,1],[1,2]]
function testGame(uint8[2][] moves) public returns(string) {
Game memory game = playGame(moves);
if (game.error) return game.msg;
if (!game.complete) return game.msg;
@okwme
okwme / Back In Stock with JS Buy SDK
Created July 27, 2017 19:20
Using Shopify's JS Buy SDK with the Back In Stock App outside of Shopify's Store Front
var processedProducts = []
var shopClient = ShopifyBuy.buildClient({
accessToken: 'your-access-token',
domain: 'your-shop-subdomain.myshopify.com',
appId: '6'
})
shopClient.fetchAllProducts().then((products) => {
@okwme
okwme / gist:5228616
Created March 23, 2013 17:35
browser notepad bookmarklet (saves as .txt)
data:text/html,<html> <head> <script type="application/ecmascript" async="" src="http://eligrey.com/demos/FileSaver.js/FileSaver.js"></script> <script type="application/ecmascript" async="" src="http://eligrey.com/demos/FileSaver.js/Blob.js"></script> </head> <style type="text/css"> #div{position:absolute; top:0px; left:0px; width:100%; height:10000px; border:none; font-family:arial; font-size:12pt; } #div:focus{ outline: none; } body{overflow:hidden;} #saveButton{z-index:2;position:absolute;top:0px;right:0px;} iframe{width:0; height:0; padding:0;margin:0;border:0;} </style> <form id="former"> <input type="submit" value="Save" id="saveButton"> </form><textarea onkeypress="javascript:keyPressed(event);" id="div"></textarea> <script> var lastKey = ""; var keyCount = 0; function keyPressed(e){ var code; if(window.event){ code = e.keyCode; } else{ code = e.which; } console.log(code); if(code == lastKey){ keyCount++; }else{ keyCount = 0; } lastKey = code; console.log(keyCount); if(keyCount >9){ keyCount = 0; } } f
@okwme
okwme / no command multiple select
Created October 15, 2012 18:51
multiple select without need for command key
var selected = [];
$(document).ready(function(){
$("#selected option:selected").each(function(i){
selected.push($(this).val());
});
$("#selected").click(function(e){
if($.inArray(e.target.value, selected) > -1){
selected.splice($.inArray(e.target.value, selected),1);
}else{
selected.push(e.target.value);