package main
import (
"fmt"
"math"
"strings"
)
func main() {
Discover gists
View Filename extension list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.php | |
.html | |
.txt | |
.htm | |
.aspx | |
.asp | |
.js | |
.css | |
.pgsql.txt | |
.mysql.txt |
View bind-vs-variable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Why use an explicit variable... | |
function lame() { | |
var args = arguments; | |
return function(fn) { | |
console.group.apply(console, args); | |
fn(); | |
console.groupEnd(); | |
}; | |
} |
View why.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an UBER simplified example, but I hope you get the idea... | |
function thisIsHowWeWriteSyncCode(arg) { | |
var foo = doSomething(arg); | |
var bar = doSomethingElse(foo); | |
var baz = doSomethingWith("test", bar, 123); | |
return doLastThing(baz); | |
} | |
function soThisSeemsSensibleForAsyncCode(arg) { |
View delayify.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.doesMyAsyncAbstractionWork = function() { | |
var fn = this; | |
var args = arguments; | |
setTimeout(function() { | |
fn.apply(null, args); | |
}, Math.random() * 5000); | |
}; |
View promise-batch-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Promise from 'bluebird'; | |
function getBatches(arr, length) { | |
let i = 0; | |
const result = []; | |
while (i < arr.length) { | |
result.push(arr.slice(i, i + length)); | |
i += length; | |
} | |
return result; |
View objects-vs-tuples.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function returns 2 separate values via an object with 2 properties. | |
function returnTwoValuesObj(str) { | |
const length = str.length; | |
const hasSpaces = str.indexOf(' ') !== -1; | |
return {length, hasSpaces}; | |
} | |
// This function returns 2 separate values via an array (effectively a tuple) with 2 items. | |
function returnTwoValuesTuple(str) { | |
const length = str.length; |
View mixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This mixin might be used to extend a class with or without its | |
// own "foo" method | |
const mixin = Base => class extends Base { | |
foo() { | |
// Only call super.foo() if it exists! | |
if (super.foo) { | |
super.foo(); | |
} | |
console.log('mixin'); |
View GoLangCrash.md
View paperclips.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_toggles = {} | |
makeToggle = (id, fn, delay = 250) => { | |
const elem = document.querySelector('#' + id) | |
elem.onclick = () => { | |
if (_toggles[id]) { | |
clearInterval(_toggles[id]) | |
_toggles[id] = null | |
} else { | |
_toggles[id] = setInterval(() => elem.disabled || fn(), delay) | |
} |
View ordinals...Inscription.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "./Logarithm.sol"; | |
import "./TransferHelper.sol"; | |
// This is common token interface, get balance of owner's token by ERC20/ERC721/ERC1155. | |
interface ICommonToken { | |
function balanceOf(address owner) external returns(uint256); |
NewerOlder