Skip to content

Instantly share code, notes, and snippets.

View MTco's full-sized avatar
😞

Mathew Tyler MTco

😞
View GitHub Profile
@stefanmaric
stefanmaric / copy-to-clipboard-bookmarklet.md
Created September 7, 2016 20:54
Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard

Copy-to-clipboard Bookmarklet

Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard.

This is the base javascript:

(function (text) {
  var node = document.createElement('textarea')
  var selection = document.getSelection()
@AdReVice
AdReVice / storagePolyfill.js
Created July 6, 2016 10:19 — forked from hasdavidc/storagePolyfill.js
A LocalStorage polyfill that also works in private browsing Safari (by doing window.localStorage.__proto__ = ourPolyfillObject) (where window.localStorage !== 'undefined', but has a quota of 0 and throws an error when you try to setItem)
//variant of https://gist.github.com/Contra/6368485
(function () {
var isStorageAvailable = function (storage) {
if (typeof storage == 'undefined') return false;
try { // hack for safari incognito
storage.setItem("storage", "");
storage.getItem("storage");
storage.removeItem("storage");
@Shaked
Shaked / kindle.meta.js
Last active June 27, 2022 22:56
Kindle Keywords Exporter
// ==UserScript==
// @name KindleKeywordsExporter
// @namespace https://kindle.amazon.com/your_highlights
// @version 0.0.8
// @downloadURL https://gist.github.com/raw/65e198dcda8784c557075b9b89265a16/kindle.user.js
// @updateURL https://gist.github.com/raw/65e198dcda8784c557075b9b89265a16/kindle.meta.js
// @description Helps exporting highlighted keywords from Kindle
// @include https://kindle.amazon.com/your_highlights
// @match https://kindle.amazon.com/your_highlights
// @grant GM_setValue
import c3 from 'c3';
export function charts() {
const errorChart = c3.generate({
bindto: '.js-chart',
data: {
x: 'date',
y: 'errors',
url: './data/dummydata.json',
@gorhill
gorhill / gist:ef1b62d606473c68d524
Last active February 16, 2023 21:17
Disqus comments widget: on-demand
! Title: Disqus click-to-load
# Copy-paste the static filters below into your "My filters" pane in the
# dashboard.
# Purpose is to load Disqus comments on demand only, so that no connection
# to `disqus.com` occurs by default when you land on a site which uses
# Disqus comments widget.
# Not connecting to Disqus by default is a good thing for such a
# ubiquitous server as `disqus.com`, which can be used to build a
@joseluisq
joseluisq / stream_get_line.md
Last active March 17, 2022 07:09
Comparative between PHP `stream_get_line` and `fgets` about processing large files

Comparative between PHP stream_get_line and fgets about processing large files

Source: http://ie2.php.net/manual/en/function.fgets.php#113113

Regarding Leigh Purdie's comment (from 4 years ago) about stream_get_line being better for large files, I decided to test this in case it was optimized since then and I found out that Leigh's comment is just completely incorrect fgets actually has a small amount of better performance, but the test Leigh did was not set up to produce good results.

The suggested test was:

@vincentorback
vincentorback / elementInViewport.js
Last active June 30, 2019 19:04
Check if element is in viewport
/**
* Check if element is in viewport
* @param {Node} el
* @return {Object}
*/
export function elementInViewport(el) {
let top = el.offsetTop;
let left = el.offsetLeft;
let width = el.offsetWidth;
let height = el.offsetHeight;
@spiralx
spiralx / User script templates for Tampermonkey
Last active September 23, 2024 18:22
Tampermonkey user script templates
For
* ES5
* ES6
* CoffeeScript
@yangchenyun
yangchenyun / fetch_kindle.js
Last active July 29, 2026 08:42
Get back my books from Kindle
/*
* @fileoverview Program to free the content in kindle books as plain HTML.
*
* This is largely based on reverse engineering kindle cloud app
* (https://read.amazon.com) to read book data from webSQL.
*
* Access to kindle library is required to download this book.
*/
// The Kindle Compression Module copied from http://read.amazon.com application
@dgrijuela
dgrijuela / index.html
Created January 12, 2016 15:17
Code for the article How to Make Your Blog Work Offline: https://blog.redradix.com/how-to-make-your-blog-work-offline
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
// Test if service workers are supported
if ('serviceWorker' in navigator) {