Skip to content

Instantly share code, notes, and snippets.

use std::fs::File;
use std::io::{BufReader, Read};
use std::iter::Peekable;
use std::str::Chars;
use std::string::String;
use std::vec::Vec;
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Location {
offset: u64,
// Hat tip to Adam Klein for an explanation.
// v8's code generation goes through phases that roughly correspond to:
// Parse -> Analyze -> Generate Code
// During Parse/analyze, v8 tracks which variables in scope are used by closures in that scope
// All closures declared in a function keep references to any variables used by any closure
// in that function.
// In the following example, each function returned by retainTooMuch will retain bbz, even though
// the returned closure doesn't reference that variable, because another closure in the same scope
// did reference bbz.
function retainTooMuch() {
@garlicnation
garlicnation / queries.js
Last active December 20, 2016 21:25
Two different deep queries
/**
* Find all elements inside `root` that match `selector`, even inside shadow roots.
*/
function qsAllDomTreeWalker(root, selector, results){
if (!results) {
results = []
}
var queue = [];
const newWalker = (root) => document.createTreeWalker(
@garlicnation
garlicnation / roots.js
Last active July 10, 2018 15:22
Select inside shadow roots
/**
* Find all elements inside `root` that match `selector`, even inside shadow roots.
*/
function qsAllDom(root, selector, results){
if (!results) {
results = []
}
var newResults = root.querySelectorAll(selector);
for (var result of newResults) {
results.push(result);
@garlicnation
garlicnation / github.ts
Created December 13, 2016 22:50
Async await github api example
let tagResponse = await api.gitdata.getTags({owner: org, repo: component});
let allTags = tagResponse.slice();
while (api.hasNextPage(tagResponse)) {
tagResponse = await api.getNextPage(tagResponse);
allTags = allTags.concat(tagResponse);
}
1) Given N endpoints, build map from endpoint -> dependency[]
2) Given endpoint -> dep map, build dep -> endpoint[] map
3) Apply user-provided function to the results from step 2 to build bundle manifest
4) Bundle endpoints according to map from step 3
bundle(["shop-app.html", "shop-list.html", "shop-cart.html"], analyzer, appShellHeuristic("end1.html"))
async bundle(url: string|string[], orchestrator?: BundleOrchestrator): Promise<DocumentCollection> {}
const func = () => {
return {};
};
// TSLint requires whitespace after ;, clang-format forcibly removes the whitespace.
for (let variable; variable = func();) {
break;
}
while(htmlImportRemaining()) {
// Get the first inlinable HTML import
let nextImport = getNextImport();
// Resolve the paths relative to the current document URL
let resolvedImport = resolvePaths(
thisDocument,
nextImport.href,
nextImport.document
)
// Replace <link rel="import"> with the document's DOM
<head>
<style is="custom-style" include="shared-styles"></style>
</head>
<body>
<div>Content goes here</div>
<link rel="vulcanized.html">
<!--<script src="init.js"></script>-->
</body>
@garlicnation
garlicnation / biz.html
Created June 7, 2016 01:48
Element style project pathological paths. Since gists can't be subdirs, imagine this file is /components/bar/subfolder/biz.html
<link rel="import" href="/components/biz/bizdep.html"> <!-- should be /bower_components/biz/bizdep.html -->
<link rel="import" href="../boo.html"> <!-- should be /biz.html-->
<link rel="import" href="../../biz/bizdep.html"> <!-- Should be the same as the absolute path above.-->