Skip to content

Instantly share code, notes, and snippets.

@newhope
newhope / Pointer.php
Last active July 6, 2022 03:37
PHP Pointer Class
<?php
class Pointer {
private $obj;
public function __construct( & $anything) {
$this->obj = & $anything;
}
@newhope
newhope / bookmarklet.js
Created January 31, 2020 06:39 — forked from brumm/bookmarklet.js
Find out which element is scrolling
javascript:!function() { var slice = Array.prototype.slice; function throttle(type, name, obj) { obj = obj || window; var running = false; var func = function() { if (running) { return; } running = true; requestAnimationFrame(function() { obj.dispatchEvent(new CustomEvent(name)); running = false; }); }; obj.addEventListener(type, func); } slice .call(document.querySelectorAll("*")) .filter( e => e.scrollWidth > e.offsetWidth || e.scrollHeight > e.offsetHeight ) .filter(e => { var style = window.getComputedStyle(e); return [style.overflow, style.overflowX, style.overflowY].some( e => e === "auto" || e === "scroll" ); }) .forEach(e => { var color = Math.floor(Math.random() * 16777215).toString(16); e.style.backgroundColor = "#" + color; throttle("scroll", "optimizedScroll", e); e.addEventListener("scroll", event => { console.log("%c[scroll]", "color: white; background-color:#" + color, event.target); }); }); }()
@newhope
newhope / firestore2json.js
Created April 15, 2019 07:22 — forked from sturmenta/firestore2json.js
firestore to json & json to firestore
const admin = require('firebase-admin');
const fs = require('fs');
const serviceAccount = require('../../../../../../Private/myschool-data_transfer-key.json');
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
const schema = require('./schema').schema;
const firestore2json = (db, schema, current) => {
@newhope
newhope / reportValidity.js
Created November 21, 2018 07:41
reportValidity polyfill for IE 10, 11
/**
Only work if your form has a submit button
*/
if ( ! HTMLFormElement.prototype.reportValidity) {
HTMLFormElement.prototype.reportValidity = function () {
var validity = this.checkValidity();
if ( ! validity) {
@newhope
newhope / embedded-file-viewer.md
Created October 30, 2018 09:27 — forked from tzmartin/embedded-file-viewer.md
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@newhope
newhope / find-oversized-element.js
Created October 25, 2017 17:37 — forked from headquarters/find-oversized-element.js
Find the offending element causing a horizontal scrollbar at any screen width (requires jQuery).
var screenWidth = window.innerWidth;
var visibleElements = jQuery(":visible");
visibleElements.each(function(){
var $this = jQuery(this);
if($this.width() > screenWidth){
$this.css("border", "1px solid green");
console.log("Screen width is " + screenWidth + " and the following element is " + $this.width(), $this);
}
});
@newhope
newhope / readAsBinaryStringPolyfill.js
Created October 17, 2017 07:31 — forked from zuraruby/readAsBinaryStringPolyfill.js
readAsBinaryStringPolyfill for internet explorer
/*
This polyfil is probably incomplete, I made this just to use localforage on internet explorer.
This polyfill is tested only with this library and works well, but I don't know if it will work i other cases.
This polyfill is based on this code: https://github.com/nolanlawson/blob-util/blob/4ae6c7a14d3240d977bbdab9ae2f0bb8905ecc37/lib/index.js#L123-L141
*/
if (window.FileReader){
if(typeof FileReader.prototype.readAsBinaryString !== 'function'){
console.log("Warning: Using readAsBinaryString polyfill");
FileReader.prototype.readAsBinaryString = function(blb){