Skip to content

Instantly share code, notes, and snippets.

View iddan's full-sized avatar

Iddan Aaronsohn iddan

View GitHub Profile
@iddan
iddan / mouseeventbuttens.js
Last active July 5, 2016 11:43
MouseEvent.prototype.buttons Polyfill
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 June 11, 2021 07:10
document.elementsFromPoint Polyfill
'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 August 2, 2016 07:02
Hack the Web nodemailer script
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'
// }];
module.exports = {
entry: './index.js',
module: {
loaders: [
{
test: /.js$/,
loader: 'babel'
}
@iddan
iddan / evaluateelement.js
Created August 2, 2016 05:57
XPath Evaluation Iterator
function* evaluateElement (el, xpath) {
let evaluation = document.evaluate(xpath, el);
let iterated;
while (iterated = evaluation.iterateNext()) {
yield iterated;
}
}
@iddan
iddan / id.js
Created October 22, 2016 23:00
JavaScript String Id for OOP Junkies
export default class ID extends String {
constructor () {
super(Math.random().toString(36).slice(2));
}
}
@iddan
iddan / yyyymmdd-regexp.js
Created December 20, 2016 22:43
YYYYMMDD RegExp
/^\d\d\d\d(?:(?:0[1-9])|(?:1[0-2]))((?:[0-2]\d)|(?:3[01]))$/
@iddan
iddan / index.jsx
Last active January 4, 2017 02:25
Simple complex React App Example
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 January 8, 2017 15:50
insert to document collection with unique ids
/**
* 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 January 10, 2017 13:28
Extract Instagram Profile Images
// 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];