Skip to content

Instantly share code, notes, and snippets.

View nchevobbe's full-sized avatar

Nicolas Chevobbe nchevobbe

View GitHub Profile
@nchevobbe
nchevobbe / download.js
Last active July 28, 2016 06:54
Download d'un fichier PDF en JS, avec fallback pour les navigateurs ne supportant pas les blobs
if (!Ext.isEmpty(window.URL) && Ext.isFunction(window.URL.createObjectURL)) {
//Alors on va effectuer une requête ajax
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
//Et si tout s'est bien passé
if (this.status == 200) {
//Alors on construit un blob avec la réponse
@nchevobbe
nchevobbe / scope.js
Last active September 26, 2016 07:18
function A (name) {
this.name = name;
this.sayMyName = this.sayMyName.bind(this);
}
A.prototype = {
sayMyName: () => {
console.log(this.name); // -> undefined
}
};
@nchevobbe
nchevobbe / create-dom-element.js
Last active August 22, 2021 12:03
Utility function to create DOM element
/**
* Utility function to create DOM element with populated attributes and content
*
* Usage :
*
* // simple element
* let input = createDomElement("input", {
* type: "search",
* placeholder: "Enter what pleases you"
* });
@nchevobbe
nchevobbe / array_fill.js
Created January 27, 2017 08:21
Array.fill
let [a, b] = (new Array(2)).fill(Symbol());
console.log(a === b); // -> true
@nchevobbe
nchevobbe / screenshot.js
Last active May 14, 2024 11:17
Log a data URL containing a screenshot of the window
let canvas = window.document.createElementNS("http://www.w3.org/1999/xhtml", "html:canvas");
let context = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
context.drawWindow(window, 0, 0, canvas.width, canvas.height, "white");
console.log(`
📸 📸 📸 📸
${canvas.toDataURL()}
var index = 0;
var nodes = document.querySelectorAll(".tree-node");
function scrollNext() {
index = index + 40;
nodes[index].scrollIntoView();
if (index < nodes.length - 1) {
requestAnimationFrame(scrollNext);
}
}
scrollNext();
@nchevobbe
nchevobbe / gist:431fed66e0f20a991b048316f27b4855
Created December 12, 2017 22:02
Push to another person PR
git push [email protected]:user/repo local_branch_name:remote_branch_name
@nchevobbe
nchevobbe / get-console-state-from-browser-console.js
Last active August 28, 2019 14:27
Get console state from hud
// With the console open, in the browser console:
async function getOpenedConsoleReference() {
var loader = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {gDevTools} = loader.require("devtools/client/framework/devtools");
var target = await gDevTools.getTargetForTab(gBrowser.selectedTab);
var toolbox = gDevTools.getToolbox(target);
return toolbox.getCurrentPanel();
}
@nchevobbe
nchevobbe / fake-typing-in-console-from-browser-console.js
Last active March 28, 2019 09:05
Fake typing in the console and executing commands, from the browser console
// With the console open, in the browser console:
async function getOpenedConsoleReference() {
var {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var target = await devtools.TargetFactory.forTab(gBrowser.selectedTab);
var {gDevTools} = devtools.require("devtools/client/framework/devtools");
var toolbox = gDevTools.getToolbox(target);
return toolbox.getCurrentPanel();
}
@nchevobbe
nchevobbe / prompt_hg.sh
Created June 30, 2020 15:53
get repo information in prompt fast
prompt_hg() {
local HG_ROOT
find_hg_root() {
local dir="$( pwd )"
while test $dir != "/"; do
if test -f $dir'/.hg/dirstate'; then
HG_ROOT=$dir"/.hg"
return 0
fi