Skip to content

Instantly share code, notes, and snippets.

@fflorent
fflorent / t2.js
Last active November 1, 2017 17:57
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
const page = await browser.newPage();
await page.goto('https://dofusama.fr/treasurehunt/stats/tous-les-indices.html')
const href = await page.evaluate(async () => {
const link = document.querySelectorAll('table a')[0]
return Promise.resolve(link.href);
})
@fflorent
fflorent / Array.prototype.equals.js
Last active August 29, 2015 14:25
Array.prototype.equals
/**
* [1,2,3].equals([1,2,3]); // true
* [1,2,3].equals([1,2]); // false
* [1,2,3].equals([1,2,4]); // false
* [1,2,3].equals("123"); // false
* Array.prototype.equals.call("123", "123"); // true
* Array.prototype.equals.call("123", [1,2,3]); // false
* [1,2,3].equals([1,2,{value: 3}], (x, y) => (x.value || x) === (y.value || y)); // true
*/
Array.prototype.equals = function (other, callback = (x, y) => (x === y)) {
@fflorent
fflorent / gist:135aff827a2e6af96229
Last active August 29, 2015 14:16
A Symbol use-case ?
var symbol = Symbol("foo");
var object = {
"key": "value",
set value(val) {
return this.value = val;
},
[symbol]: (bar) => "" + bar
};
@fflorent
fflorent / wrapPromise.js
Created June 14, 2014 14:01
wrapping promise using AOP
(function()
{
var wrappedPromiseConstructor = Promise;
Promise = function(...args)
{
// Do whatever you want here
console.log("trapped");
var func = args[0];
args[0] = function(resolve, reject)
{
@fflorent
fflorent / amd_default_parameter.js
Last active August 29, 2015 14:00
AMD using require and the default parameters
/**
* AMD's define function using ES6 default parameter and require.
*
* With some tweaks of AMD and using an ES6 Browser, this idioms intends to improve readability
* and maintainability of modules declared with define()... At least, until browsers implement
* ES6 Modules.
*/
define("mymodule", function(
r = require,
/**
* Instructions :
* 1) Go to https://getfirebug.com/testresults, select the "Users" tab
* 2) Expand two groups of your choice
* 3) Run the snippet below in the Console of your choice, as long as it is Firebug :)
*
* License: WTFPL (https://fr.wikipedia.org/wiki/WTF_Public_License)
*/
var groups = $$(".groupBodyRow");
if (groups.length !== 2)
@fflorent
fflorent / this_strict_mode.html
Last active January 2, 2016 21:09
this in global code using strict mode
<html>
<head>
<script>
"use strict";
console.log(this);
</script>
</head>
</html>
@fflorent
fflorent / failing-test-case-debugger-frame-onPop.js
Created December 30, 2013 16:48
Failing test case of Debugger.Frame.onPop when the execution of a frame is about to end (i.e. when the return value is displayed in the DevTools or in Firebug + JSD2)
/*
Failing test case:
1. Open this page: https://getfirebug.com/tests/head/script/4213/issue4213.html
2. With the DevTools, set a breakpoint at line 4 of issue4213-1.js (in myFunc1)
3. Click on the "Execute Test" button of the webpage
|=> the breakpoint is hit
4. Step over
|=> the return value is displayed
5. Run this in Scratchpad (environment = browser)
6. Resume the execution
@fflorent
fflorent / gist:5474810
Created April 27, 2013 21:29
A meta-proxy to debug __exposedProps__ (mozilla-specific) ... brrrrr
// (sure, just for debugging!)
var target = {};
target.__exposedProps__ = new Proxy(Object.freeze({}),
new Proxy({
get: function()
{
return "rw";
},
getOwnPropertyDescriptor: function()
{
@fflorent
fflorent / gist:5155923
Last active December 14, 2015 22:08
Create console object as binding object
function evaluate(context, expr, origExpr, onSuccess, onError)
{
var result;
var commandLine = createFirebugCommandLine(context, win);
// gets the debuggee object:
var dglobal = DebuggerLib.getDebuggeeGlobal(context.window, context);
var resObj;
// that works:
commandLine.someFunction = dglobal.makeDebuggeeValue(function()