Skip to content

Instantly share code, notes, and snippets.

@rshaker
rshaker / reference.md
Last active June 21, 2024 07:39
Reference desk

nada

@rshaker
rshaker / ultimate-ut-cheat-sheet.md
Created December 7, 2023 14:40 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@rshaker
rshaker / interfaces.md
Created November 23, 2023 16:13
Iterating over Interface properties in Typescript
interface MyInterface {
    prop1: string;
    prop2: number;
    // other properties
}

const myObject: MyInterface = {
    prop1: "value1",
 prop2: 123,
@rshaker
rshaker / programming-languages.csv
Created November 14, 2023 16:57 — forked from turicas/programming-languages.csv
Download list of programming languages from Wikipedia
name wikipedia_url
A# .NET https://en.wikipedia.org/wiki/A_Sharp_(.NET)
A# (Axiom) https://en.wikipedia.org/wiki/A_Sharp_(Axiom)
A-0 System https://en.wikipedia.org/wiki/A-0_System
A+ https://en.wikipedia.org/wiki/A%2B_(programming_language)
A++ https://en.wikipedia.org/wiki/A%2B%2B
ABAP https://en.wikipedia.org/wiki/ABAP
ABC https://en.wikipedia.org/wiki/ABC_(programming_language)
ABC ALGOL https://en.wikipedia.org/wiki/ABC_ALGOL
ABSET https://en.wikipedia.org/wiki/ABSET
@rshaker
rshaker / Nonsense.md
Last active September 6, 2023 18:05
An idea for mouse events that never worked, but at least I learned a little more Mermaid
%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#BB2528',
      'primaryTextColor': '#fff',
      'primaryBorderColor': '#7C0000',
      'lineColor': '#F8B229',
      'secondaryColor': '#000',
@rshaker
rshaker / README.md
Created August 24, 2023 18:21
Injecting CSS into a web page using Javascript

Injecting CSS into a web page using Javascript

Using createTextNode to set the content of a <style> element is generally considered a safer practice compared to using innerHTML. Using createTextNode ensures that the content is treated as pure text and not parsed as HTML. This can prevent potential cross-site scripting (XSS) attacks if the CSS content were to somehow include malicious code.

Also, using the createTextNode approach is a more standards-compliant way to insert text content into the DOM. It ensures that the content is treated exactly as text, without any ambiguity. While the performance difference is usually negligible, createTextNode can sometimes be more efficient as it doesn't involve the HTML parser.

But in tightly controlled cases, innerHTML is fine. Here's an example of injection from a URL:

function injectCSS(url: string, id: string) {
@rshaker
rshaker / README.md
Last active September 7, 2023 18:01
WEBPACK_IMPORTED_MODULE_2__ is not a constructor

WEBPACK_IMPORTED_MODULE_2__ is not a constructor

An error encountered while trying to instantiate a class from the node package I'm builiding, blockly_multiselect_plugin.

Bundling a node project for distribution as a library should be the same as bundling an application. One exception is that you need to expose exports from the package's entry point using Webpack's output.library option.

When targeting a library, especially when libraryTarget is 'umd', the globalObject option indicates what global object will be used to mount the library. To make UMD build available on both browsers and Node.js, set output.globalObject option to 'this'. The globalObject option defaults to 'self' for Web-like targets.

The following fragment of webpack.config.js shows how to correctly export the entry point for consumption by other packages.

@rshaker
rshaker / downloadBlocklyWorkspaceAsImage.ts
Created July 3, 2023 16:31 — forked from kyoncy/downloadBlocklyWorkspaceAsImage.ts
Download Blockly.Workspace as SVG or PNG file
import Blockly from 'blockly';
declare interface CustomNode extends Node {
removeAttribute(arg0: string);
}
const DOMURL = window.URL || window.webkitURL;
const getSvgBlob = (workspace: Blockly.WorkspaceSvg) => {
const canvas = workspace.svgBlockCanvas_.cloneNode(true) as CustomNode;

R1CS

Equation

$$x^2 + x + 2 == 32$$

Gates

  • $x * x = sym_1$
  • $x + sym_1 = sym_2$
@rshaker
rshaker / README.md
Created March 25, 2023 23:09
Remote debugging Chrome extension from Visual Studio Code

On Mac, launch browser using a dedicated profile. This will create directory remote-profile in cwd.

% /Applications/GoogleChrome.app/Contents/MacOS/GoogleChrome --remote-debugging-port=9222 --user-data-dir=remote-profile

DevTools listening on ws://127.0.0.1:9222/devtools/browser/1f9619a3-abe2-449b-a81e-dde827123e20

Make sure that webroot points to the webpack-built distribution of your extension that's loaded by the browser.