Skip to content

Instantly share code, notes, and snippets.

Avatar

Damien Seguin dmnsgn

View GitHub Profile
@dmnsgn
dmnsgn / resize-electron-window-from-devtools-in-renderer-process.js
Last active Nov 12, 2020
Resize Electron window from devtools in renderer process.
View resize-electron-window-from-devtools-in-renderer-process.js
const { remote } = require("electron");
remote.getCurrentWindow().setBounds({
x: 0,
y: 0,
width: 1920,
height: 1080,
});
@dmnsgn
dmnsgn / resize-application.applescript
Created Nov 10, 2020
Resize the current front macOS window of an application
View resize-application.applescript
tell application "Google Chrome"
set bounds of front window to {0, 0, 1440, 900}
end tell
View uuid.js
// Author: Abhishek Dutta, 12 June 2020
// License: CC0 (https://creativecommons.org/choose/zero/)
export default function uuid() {
var temp_url = URL.createObjectURL(new Blob());
var uuid = temp_url.toString();
URL.revokeObjectURL(temp_url);
return uuid.substr(uuid.lastIndexOf('/') + 1); // remove prefix (e.g. blob:null/, blob:www.test.com/, ...)
}
View es-modules-in-the-browser-almost-now-sw.js
// Disclaimer: this is not stable nor properly tested
// Not sure about the security implications of hijacking the fetch request either
// https://gist.github.com/pilwon/ff55634a29bb4456e0dd
const ES_MODULE_IMPORT_REGEX = /\bimport\s+(?:.+\s+from\s+)?[\'"]([^"\']+)["\']/g;
const packages = new Map().set(
"lodash/clamp",
"https://cdn.jsdelivr.net/npm/lodash-es@4.17.8/clamp.js"
);
View es-modules-in-the-browser-app.js
import clamp from "lodash/clamp";
const num = Infinity;
const answer = clamp(num, 0, 42);
console.log(answer);
export default answer;
View package-name-maps.html
<!DOCTYPE html>
<html>
<head>
<title>ES modules in the browser - almost - now | Package name maps</title>
</head>
<body>
<!-- Declare the package map -->
<script type="packagemap">
View es-modules-service-worker.html
<!DOCTYPE html>
<html>
<head>
<title>ES modules in the browser - almost - now | Service worker</title>
</head>
<body>
<script>
// Register
View unpkg-getlibs.html
<!DOCTYPE html>
<html>
<head>
<title>ES modules in the browser - almost - now | unpkg getLibs</title>
<!-- Include the getlibs endpoint -->
<script src="https://unpkg.com/getlibs"></script>
</head>
<body>
View basics-script-type-module.html
<!DOCTYPE html>
<html>
<head>
<title>ES modules in the browser - almost - now | Basics: script type module</title>
</head>
<body>
<!-- Use a type set to "module" with a fallback -->
<script type="module" src="app.js"></script>
@dmnsgn
dmnsgn / listAllEventListeners.js
Created Apr 5, 2017
List all event listeners in a document
View listAllEventListeners.js
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];