Skip to content

Instantly share code, notes, and snippets.

View IhostVlad's full-sized avatar
💻
Senior full-stack developer

Vladislav V IhostVlad

💻
Senior full-stack developer
View GitHub Profile
@IhostVlad
IhostVlad / DockerTestcafe.hint
Last active April 14, 2019 09:04
Docker for TestCafe + Chrome + X11 + VNC
##### ./testcafe_ubuntu.dockerfile #####
# Pull base image.
FROM ubuntu:16.04
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
# Install.
RUN \

resolve-bus-memory npm version

This package is a driver for resolve-es to emit events using memory.

Usage

import createDriver from 'resolve-bus-memory';

const driver = createDriver();
@IhostVlad
IhostVlad / babel-object-source.js
Created October 24, 2017 10:10
Babel plugin adds meta-information to all objects in source code, including file name, line number and original text, where object had been declated
module.exports = function ({ types: t }) {
const WRAP_NAME = '__WRAP_OBJECT_CREATION_WITH_SOURCE_MAP__';
const SOURCE_NAME = '__SOURCE_DELCARATION__';
return {
visitor: {
'ObjectExpression|ArrayExpression|NewExpression': function (path, state) {
const wrappedParent = path.findParent(
parent =>
parent.node &&
parent.node.callee &&
(function() {
!(function(global) {
"use strict";
var Op = Object.prototype;
var hasOwn = Op.hasOwnProperty;
var undefined;
var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
@IhostVlad
IhostVlad / SafeInvokeFs
Created April 3, 2018 15:31
SafeInvokeFs
const safeInvokeFs = (funcName, ...args) =>
new Function(
'context',
`try {
return require('fs')[context.funcName].apply(null, context.args)
} catch(err) {}`
)({ funcName, args })
function conditionalRequireModuleByPath(modulePath, condition) {
try {
var packageJson = require(path.join(modulePath, './package.json'))
if (condition(packageJson)) {
return require(path.join(
modulePath,
'./',
packageJson.main || 'index.js'
))
}
@IhostVlad
IhostVlad / Eval with CSP
Created April 19, 2019 09:26
Eval with CSP
window.metaEval = async (code) => {
const evalId = "META_EVAL_"+ Date.now() + "_" + Math.floor(Math.random() * 1000000000)
document.body.innerHTML += "<iframe id=\""+ evalId +"\" src=\"about:blank\"></iframe>"
const ifr = document.getElementById(evalId)
let makeResolve = null
const promise = new Promise((resolve) => (makeResolve = resolve))
let result = null
const listener = (msg) => { result = msg.data; makeResolve(); }
window.addEventListener("message", listener)
curl "https://api.github.com/repos/ORG/REPO/statuses/COMMIT_SHA?access_token=ACCESS_TOKEN" -H "Content-Type: application/json" -X POST -d "{\"state\": \"success\", \"context\": \"continuous-integration/drone/push\", \"target_url\": \"\"}"
fixture`ResolveJS`.page`https://github.com/reimagined/resolve`
test('ResolveJS', async t => {
await t.setNativeDialogHandler(() => true)
const locationPath = (await t.eval(() => window.location)).pathname
await t.expect(locationPath).eql('/reimagined/resolve')
// await t.expect(locationPath).eql('/reimagined/resolve2')
})
fixture`HackerNews`.page`https://jd05ienjxfkjegg8mim64t8z1e.resolve.sh/`
test('HackerNews 1', async t => {
await t.setNativeDialogHandler(() => true)
const pageContent = (await t.eval(() => window.document.body.innerHTML))
console.log(pageContent)
})
test('HackerNews 2', async t => {
await t.setNativeDialogHandler(() => true)