Skip to content

Instantly share code, notes, and snippets.

View Tarabyte's full-sized avatar
🏠
Working from home

Yury Tarabanko Tarabyte

🏠
Working from home
  • Belgorod, Russia
View GitHub Profile
@Tarabyte
Tarabyte / machine.js
Created January 13, 2021 14:32
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@Tarabyte
Tarabyte / machine.js
Last active January 13, 2021 14:35
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
export default class MyClass {
constructor(x) {
this.val= x ? x: 'Hello!'
console.log(`MyClass: ${x}`)
}
}
@Tarabyte
Tarabyte / file.js
Last active February 28, 2019 12:24
Nested callbacks
addStepsAttachments(fileName, folder, callback) {
fileName = '12345';
fs.readdir(folder, 'utf8', function(err, filesList) {
if (!err && filesList.length > 0) {
const results = [];
const matchingFiles = filesList
.filter(file => file.startsWith(fileName))
.map(file => path.resolve(folder, file));
// just in case there were no matching files
@Tarabyte
Tarabyte / getRaven.js
Created December 22, 2017 21:05
Get correct sentry client in next.js app w/o custom webpack config
// @see package.json#browser field
const Raven = require('raven')
if (process.env.NODE_ENV === 'production') {
Raven.config('YOUR_SENTRY_DSN').install()
}
module.exports = Raven
/**
* Code which I test on twitter.com
* Both tests were runing in Chrome 35.x dev tools
*
* This test just gets all a tags from html and read their content
* and then write it on end of document (body element)
*
**/
@Tarabyte
Tarabyte / test.js
Last active August 29, 2015 14:01
Get path from script
var id = 'id' + (Math.random()*1e6|0).toString(16);
document.write('<script id="' + id + '" type="text/noexec"></script>');
var marker = document.getElementById(id);
alert(marker.previousElementSibling.src||'inline');
marker.parentNode.removeChild(marker);