Skip to content

Instantly share code, notes, and snippets.

Avatar

Iddan Aaronsohn iddan

View GitHub Profile
@iddan
iddan / mouseeventbuttens.js
Last active Jul 5, 2016
MouseEvent.prototype.buttons Polyfill
View mouseeventbuttens.js
if (!MouseEvent.prototype.hasOwnProperty('buttons')) {
let mousedown = 0;
addEventListener('mousedown', e => mousedown = e.button || 1);
addEventListener('mouseup', () => mousedown = 0);
Object.defineProperty(MouseEvent.prototype, 'buttons', {
get () {
return mousedown;
}
@iddan
iddan / elementsfrompoint.js
Last active Sep 29, 2020
document.elementsFromPoint Polyfill
View elementsfrompoint.js
'use strict';
if (!document.elementsFromPoint) {
document.elementsFromPoint = elementsFromPoint;
}
function elementsFromPoint(x, y) {
var parents = [];
var parent = void 0;
do {
@iddan
iddan / mail.js
Last active Aug 2, 2016
Hack the Web nodemailer script
View mail.js
const sent = require('./sent.js');
const nodemailer = require('nodemailer');
const PEOPLE = require('./people.js').filter(person => person.Approval === 1).filter(person => !sent.includes(person.Email));
// const PEOPLE = [{
// Email: 'idan.a@icloud.com',
// 'Full Name': 'Iddan Aharonson'
// }];
View webpack.config.js
module.exports = {
entry: './index.js',
module: {
loaders: [
{
test: /.js$/,
loader: 'babel'
}
@iddan
iddan / evaluateelement.js
Created Aug 2, 2016
XPath Evaluation Iterator
View evaluateelement.js
function* evaluateElement (el, xpath) {
let evaluation = document.evaluate(xpath, el);
let iterated;
while (iterated = evaluation.iterateNext()) {
yield iterated;
}
}
@iddan
iddan / id.js
Created Oct 22, 2016
JavaScript String Id for OOP Junkies
View id.js
export default class ID extends String {
constructor () {
super(Math.random().toString(36).slice(2));
}
}
View yyyymmdd-regexp.js
/^\d\d\d\d(?:(?:0[1-9])|(?:1[0-2]))((?:[0-2]\d)|(?:3[01]))$/
@iddan
iddan / index.jsx
Last active Jan 4, 2017
Simple complex React App Example
View index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './store';
import Toolbox from './toolbox';
import Feed from './gallery';
import Chat from './chat';
function App () {
return (
@iddan
iddan / insert.jsx
Created Jan 8, 2017
insert to document collection with unique ids
View insert.jsx
/**
* Insert documents to a document collection with unique ids. Override if exists.
* @param {array} state
* @param {array} newState
* @param {string} id
*/
function insert(state, newState, id) {
let ids = newState.reduce((ids, item) => ({ ...ids, [item[id]]: true }), {});
return [...state.filter(item => !ids[item[id]]), ...newState];
}
@iddan
iddan / extract.js
Created Jan 10, 2017
Extract Instagram Profile Images
View extract.js
// open Chrome Dev Tools
// go to the network tab
// open Instagram.com/:profile
// scroll until all the request images are displayed
// right click on one of the names to the left under the graph.
// choose "Save as HAR with content"
// save it as log.json
const extractMatch = (string, regexp, index) =>
string.match(regexp) && string.match(regexp)[index];