Skip to content

Instantly share code, notes, and snippets.

@iiLaurens
iiLaurens / code.js
Last active April 22, 2024 12:36
Get all clickable elements on a page
window.scrollTo(0, 0)
var bodyRect = document.body.getBoundingClientRect();
var items = Array.prototype.slice.call(
document.querySelectorAll('*')
).map(function(element) {
var rect=element.getBoundingClientRect();
return {
element: element,
include: (element.tagName === "BUTTON" || element.tagName === "A" || (element.onclick != null) || window.getComputedStyle(element).cursor == "pointer"),
@veox
veox / erc20.abi.json
Created January 21, 2018 14:59
ERC20 ABI in JSON format
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
@maaku
maaku / .gitignore
Last active November 17, 2020 21:53
BIP specifying fast merkle trees, as used in the Merkle branch verification opcodes
*~
@Rich-Harris
Rich-Harris / footgun.md
Last active April 19, 2024 07:47
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@dcaoyuan
dcaoyuan / akka-http-client.scala
Created August 26, 2016 12:23
akka-http-client-example
val uri = "http://www.yahoo.com"
val reqEntity = Array[Byte]()
val respEntity = for {
request <- Marshal(reqEntity).to[RequestEntity]
response <- Http().singleRequest(HttpRequest(method = HttpMethods.POST, uri = uri, entity = request))
entity <- Unmarshal(response.entity).to[ByteString]
} yield entity
val payload = respEntity.andThen {
@macalinao
macalinao / sad.go
Created August 4, 2016 19:10
i cry every time
// StatusesWithIds finds all condition statuses that match the given ids.
func StatusesWithIds(in []*cpb.ConditionStatus, ids []*cpb.ConditionId) []*cpb.ConditionStatus {
// create our filter set
set := map[string]bool{}
for _, id := range ids {
set[util.StringifyID(id)] = true
}
// i.e. ids.map(util.StringifyID).toSet
@ResidentMario
ResidentMario / top_500.txt
Created May 28, 2016 05:27
Top 500 Wealthiest Landowners in New York City
OwnerName
DCAS/DEPARTMENT OF ED 1.820269e+10
PORT AUTHORITY NY & N 1.801034e+10
PARKS AND RECREATION 1.163104e+10
NYC HOUSING AUTHORITY 9.589786e+09
HEALTH AND HOSPITALS 2.717476e+09
JOINTLY OWNED PLAYGRO 2.424863e+09
DEPT OF PARKS AND REC 2.386076e+09
NEW YORK UNIVERSITY 2.260595e+09
RCPI HOLDCO LCC 1.923597e+09
import com.amazonaws.HttpMethod
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model._
...
val s3Client = new AmazonS3Client
private def getFlow(pathRaw: String, method: HttpMethod) = {
// clean the path
val path = pathRaw.dropWhile(_ == '/').trim
@bigsnarfdude
bigsnarfdude / t-digetst.scala
Last active November 5, 2019 03:37
T-Digest in Scala Algebird Plus method
/**
* Example of T-Digest plus method with Algebird Semigroup
*/
import com.tdunning.math.stats.TDigest
import com.twitter.algebird.{Group, Semigroup}
import io.koff.t_digest._
case object TDigestSemigroup extends Semigroup[TDigest] {
@pathikrit
pathikrit / EquivalenceLock.scala
Last active February 7, 2017 21:14
Locking based on object equality rather than referential equality in Scala
/**
* An util that provides synchronization using value equality rather than referential equality
* It is guaranteed that if two objects are value-equal, their corresponding blocks are invoked mutually exclusively.
* But the converse may not be true i.e. if two objects are not value-equal, they may be invoked exclusively too
* Note: Typically, no need to create instances of this class. The default instance in the companion object can be safely reused
*
* @param size There is a 1/size probability that two invocations that could be invoked concurrently is invoked sequentially
*
* Example usage:
* import EquivalenceLock.{defaultInstance => lock}