Skip to content

Instantly share code, notes, and snippets.

View bartlomieju's full-sized avatar
🦕

Bartek Iwańczuk bartlomieju

🦕
View GitHub Profile
@bartlomieju
bartlomieju / deno_dir.rs
Created July 20, 2019 18:45
Futures recursion
/// Asynchronously fetch remote source file specified by the URL following redirects.
fn fetch_remote_source_async(
self: &Self,
module_url: &Url,
) -> Box<impl Future<Item = SourceFile, Error = ErrBox>> {
use crate::http_util::FetchOnceResult;
let download_job = self.progress.add("Download", &module_url.to_string());
let module_uri = url_into_uri(&module_url);
@bartlomieju
bartlomieju / .DS_Store
Last active August 9, 2019 17:14
Deno profiles
'use strict';
const buff = new Uint8Array(16384);
const encode = new TextEncoder().encode;
function sendRequest (conn) {
console.log("sending request");
conn.write(encode('GET / HTTP/1.1\nHost: example.com\n\n')).then(() => console.log("request sent"));
}

CLI things that should be resources:

  • global_timer
  • start_time
  • other timers
  • metrics? (it'd be nice if they were resources, but I fear it might be slow because of double lookup for each op)

Problems with refactor:

  • no way for full polymorphism Tried with StreamResource enum:
@bartlomieju
bartlomieju / test.json
Created October 29, 2019 15:27
Named imports from JSON file
{
a: 123,
b: [ 1, 2, 3 ],
c: null
}
{"/npm:tough-cookie@3?dew":"12f344e27b9aa0c546fe4024c7d0a2c1df2a739bccd3a28c6aee58ec358a3969","/npm:request@2?dew":"bd8db8a82ddf8c4f17ef069b20e06eb7e9ff38246309c56f4aa1be04139838b0","/npm:[email protected]/lib/ber/errors.dew.js":"2cd0e8d7366a0a438d01fc7d3d490458e0b60a892c2434129bb3723f951329df","/npm:[email protected]/lib/jsdom/living/domparsing/parse5-adapter-serialization.dew.js":"1061cc61a18e2a50693160adda84181f568ac360d72932428839e6def70f9da1","/npm:[email protected]/lib/jsdom/living/generated/FileList.dew.js":"b9f55ccc0ba4dc48d3791b6f217c2b18c42a66cd523cbe7a49a491e00d3af018","/npm:decimal.js@10?dew":"76ae50f5ca5145ceeec3174ca28b81b770e83c2bdf9d13b4c953e7696edc9c1c","/npm:[email protected]/lib/jsdom/living/generated/PopStateEvent.dew.js":"dc8aa59e7433f0975f72095856a73cfa7a000c9ba256306368e99e42fe77a245","/npm:[email protected]/lib/sec.dew.js":"470b3aae4518a04c8cb91110082c3fbc1419c2b9021ece833b90ad8c37081102","/npm:[email protected]/lib/jsdom/living/window/Location-impl.dew.js":"f1ca3a20f73fecfb0e1eecca1a74d11e2e6135e98388a04f951e48338
let loader = Rc::new(RemoteLoader {});
let mut isolate = EsIsolate::new(loader, StartupData::None, false);
let mod_id = isolate.load_module(&specifier, Some(source_code)).await?;
isolate.mod_evaluate(mod_id)?;
DEBUG RS - deno::file_fetcher:545 - FileFetcher::fetch() - specifier: file:///Users/biwanczuk/dev/manual/.github/import_map.json
DEBUG RS - deno_runtime::permissions:51 - ⚠️️ Granted read access to "/Users/biwanczuk/dev/manual/.github/import_map.json"
DEBUG RS - deno::file_fetcher:545 - FileFetcher::fetch() - specifier: file:///Users/biwanczuk/dev/manual/README.md
DEBUG RS - deno_runtime::permissions:51 - ⚠️️ Granted read access to "/Users/biwanczuk/dev/manual/README.md"
DEBUG RS - deno::file_fetcher:545 - FileFetcher::fetch() - specifier: file:///Users/biwanczuk/dev/manual/continuous_integration.md
DEBUG RS - deno_runtime::permissions:51 - ⚠️️ Granted read access to "/Users/biwanczuk/dev/manual/continuous_integration.md"
DEBUG RS - deno::file_fetcher:545 - FileFetcher::fetch() - specifier: file:///Users/biwanczuk/dev/manual/contributing.md
DEBUG RS - deno_runtime::permissions:51 - ⚠️️ Granted read access to "/Users/biwanczuk/dev/manual/contributing.md"
DEBUG RS - deno::file_fetcher:545 - FileFetcher::fet
@bartlomieju
bartlomieju / inspector.js
Last active December 7, 2021 00:35
Demonstrate event loop hang if "Runtime.runIfWaitingForDebugger" is not called after connecting to Deno inspector. Forked from https://gist.github.com/evanwashere/04cfa233f613343e1c9d6fb72cfd628c
class Emitter {
#on = Object.create(null);
#once = Object.create(null);
on(n, fn) { (this.#on[n] ?? (this.#on[n] = [])).push(fn); }
once(n, fn) { (this.#once[n] ?? (this.#once[n] = [])).push(fn); }
emit(n, ...args) { this.#on[n]?.forEach(_ => _(...args)); if (this.#once[n]) this.#once[n] = (this.#once[n].forEach(_ => _(...args)), undefined); }
off(n, fn) { if (!fn) (delete this.#on[n], delete this.#once[n]); else { let o = this.#on[n]?.indexOf(fn) ?? -1; if (o !== -1) this.#on[n].splice(o, 1); o = this.#once[n]?.indexOf(fn) ?? -1; if (o !== -1) this.#once[n].splice(o, 1); } }
}
jupyter notebook
[I 2021-12-09 17:20:32.804 LabApp] JupyterLab extension loaded from /usr/local/Cellar/jupyterlab/3.2.4/libexec/lib/python3.9/site-packages/jupyterlab
[I 2021-12-09 17:20:32.804 LabApp] JupyterLab application directory is /usr/local/Cellar/jupyterlab/3.2.4/libexec/share/jupyter/lab
[I 17:20:32.813 NotebookApp] Serving notebooks from local directory: /Users/biwanczuk/dev/ideno
[I 17:20:32.813 NotebookApp] Jupyter Notebook 6.4.6 is running at:
[I 17:20:32.813 NotebookApp] http://localhost:8888/?token=6a1b4c6d4743e5dff339982ec80ac39e758c0dd3b7e7cded
[I 17:20:32.813 NotebookApp] or http://127.0.0.1:8888/?token=6a1b4c6d4743e5dff339982ec80ac39e758c0dd3b7e7cded
[I 17:20:32.813 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 17:20:32.823 NotebookApp]