Skip to content

Instantly share code, notes, and snippets.

View matijs's full-sized avatar
:dependabot:
Scouting turtles

matijs matijs

:dependabot:
Scouting turtles
View GitHub Profile
@matijs
matijs / svgDetection.js
Last active December 18, 2015 02:18
Detect support for SVG
(function() {
return !!document.createElementNS && !!document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGRect;
}());
@matijs
matijs / inlineSVGDetection.js
Created June 4, 2013 22:17
Detect support for inline SVG
(function() {
var div = document.createElement("div");
div.innerHTML = "<svg/>";
return !!div.firstChild && div.firstChild.namespaceURI === "http://www.w3.org/2000/svg";
}());
(function() {
var timeouts = [];
var messageName = "zero-timeout-message";
function handleMessage(event) {
if (event.source === window && event.data === messageName) {
event.stopPropagation();
if (timeouts.length > 0) {
var fn = timeouts.shift();
fn();
@matijs
matijs / snippets.sh
Created September 4, 2013 04:43
git snippets
# list deleted files
git log --diff-filter=D --summary
# find last commit that affected a file
git rev-list -n 1 HEAD -- path/to/filename
# restore one specific deleted file
@matijs
matijs / create-mavericks-usb.sh
Created October 23, 2013 06:54
Create a OS X Mavericks bootable USB drive
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
@matijs
matijs / changeViewport.js
Created November 16, 2013 12:24
set the viewPort to 1024 if it was
javascript:void(function() {
var metaViewport = document.querySelector("meta[name=viewport]");
if (metaViewport) {
var content = metaViewport.getAttribute("content").replace("device-width","1024");
metaViewport.setAttribute("content", content);
}
})();
@matijs
matijs / genpassword.js
Last active December 28, 2015 16:08
Random password generator bookmarklet
javascript:void(function() {
var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var password = "";
for (var i = 0, length = 64; i < length; ++i) {
password += chars[~~(Math.random() * chars.length)];
}
var input = document.getElementById("f773da90-5044-11e3-8f96-0800200c9a66") || document.createElement("input");
if (!input.id) {
input.id = "f773da90-5044-11e3-8f96-0800200c9a66";
input.setAttribute("style", "background:deeppink;border:2px solid #000;border-radius:.25em;box-shadow:0 0 1em .25em rgba(0,0,0,.5);color:#fff;position:fixed;top:1em;left:1em;font:16px/1 Helvetica,sans-serif;padding:.5em;z-index:9999;opacity:1;transition:opacity .5s;");
@matijs
matijs / scrollbarsize.js
Last active December 30, 2015 21:39
calculate the size of the scrollbar
var scrollbarSize = (function() {
var inner = document.createElement( "div" ),
outer = document.createElement( "div" );
inner.style.width = "100%";
inner.style.height = "60px";
outer.style.position = "absolute";
outer.style.top = "0";
outer.style.left = "0";
outer.style.visibility = "hidden";
outer.style.width = "50px";
@matijs
matijs / textarea-keyboard-save.js
Created January 26, 2016 12:26
Trigger a click on a 'save' button by pressing cmd/ctrl-s in a textarea (adapt as needed)
(function() {
'use strict';
document.addEventListener('keydown', function(event) {
var S = 83,
activeElement = document.activeElement,
saveButtonId,
saveButton;
if ((event.key === S || event.keyCode === S) && (event.metaKey || event.ctrlKey) && activeElement.nodeName === 'TEXTAREA') {
@matijs
matijs / .editorconfig
Last active February 9, 2016 14:21
Sensible EditorConfig defaults
# For more information about the properties used in
# this file, please see the EditorConfig documentation:
# http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2