Skip to content

Instantly share code, notes, and snippets.

View arturparkhisenko's full-sized avatar
:octocat:
www. www always changes

Artur Parkhisenko arturparkhisenko

:octocat:
www. www always changes
View GitHub Profile
@arturparkhisenko
arturparkhisenko / js-fun.js
Last active January 11, 2021 16:47
js fun
// https://twitter.com/MylesBorins/status/929414418680643585?s=09
const context = new window.AudioContext();
for (let i = 0; i < 10; i++) {
let osc = context.createOscillator();
osc.type = 'square';
osc.frequency.value = 40 + i * 0.1111;
osc.connect(context.destination);
osc.start();
}
// second part
<!-- https://philipwalton.com/articles/deploying-es2015-code-in-production-today/ -->
<!-- Browsers with ES module support load this file. -->
<script type="module" src="main.js"></script>
<!-- Older browsers load this file (and module-supporting -->
<!-- browsers know *not* to load this file). -->
<script nomodule src="main-legacy.js"></script>
<!-- safari fix https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc -->
@arturparkhisenko
arturparkhisenko / css-invert-theme.css
Last active October 2, 2017 17:50
css invert theme
/* https://medium.com/web-standards/a-theme-switcher-96174d95be75 */
:root {
background-color: #fefefe;
filter: invert(100%);
}
* {
background-color: inherit;
}
@arturparkhisenko
arturparkhisenko / js-promises.js
Last active October 23, 2017 16:39
js promises
// finally --------------------------------------------
const fetchAndDisplay = async ({url, element}) => {
showLoadingSpinner();
try {
const response = await fetch(url);
const text = await response.text();
element.textContent = text;
} catch (error) {
element.textContent = error.message;
} finally {
@arturparkhisenko
arturparkhisenko / git-hints.sh
Created September 20, 2017 08:17
git hints
# https://stackoverflow.com/questions/17667023/git-how-to-reset-origin-master-to-a-commit
git checkout master
git reset --hard e3f1e37 # put here the latest commit
git push --force origin master
# Then to prove it (it won't print any diff)
git diff master..origin/master
@arturparkhisenko
arturparkhisenko / js-utils.js
Last active January 13, 2019 04:58
js-utils.js
// https://twitter.com/0x00A/status/904419238110261250
// Unique array (of primitives)
const haystack = ['a', 'b', 'a']
const unique = [...new Set(haystack)]
// --------------------------------------------------
// https://twitter.com/rauschma/status/961020269446991872
// Removing duplicate characters from a string:
@arturparkhisenko
arturparkhisenko / node.js
Created June 7, 2017 17:20
node-hints-and-snippets.js
// DevTools: Quick debugging of your Node.js code straight from DevTools
node --inspect --debug-brk node-script.js
const costlyFunction = () => 'finished :)';
performance.mark('costlyFunction Start');
costlyFunction();
performance.mark('costlyFunction End');
performance.measure(
'costlyFunction',
@arturparkhisenko
arturparkhisenko / dispatch.js
Last active January 24, 2018 13:26
redux node
import makeStore from './src/store';
import startServer from './src/server';
export const store = makeStore();
startServer(store);
store.dispatch({
type:'SET_ENTRIES',
entries:require('./entries.json')
});
@arturparkhisenko
arturparkhisenko / js-dom-event-listeners.js
Created March 17, 2017 18:43
js-dom-event-listeners
// https://www.webreflection.co.uk/blog/2015/10/22/how-to-add-dom-events-listeners
// arrow function for a click
let click = (evt)=>{evt.preventDefault(); alert('CLICK')}
// arrow function add or remove
node.addEventListener('click', click);
node.removeEventListener('click', click);
// anonymous bound (WeakMap between DOM nodes and objects)
node.addEventListener('click', {