Skip to content

Instantly share code, notes, and snippets.

View atomize's full-sized avatar
🎹
♩♩

Berti atomize

🎹
♩♩
View GitHub Profile
@atomize
atomize / filehighlight.js
Created March 15, 2019 19:13
reminder for Prism
function loadFile(src, cb) {
var xhr = new XMLHttpRequest();
var s = [];
xhr.open("GET", src, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status < 400 && xhr.responseText) {
s = [src,xhr.responseText]
} else if (xhr.status >= 400) {
s = [src, "✖ Error " + xhr.status + " while fetching file: " + xhr.statusText]
@atomize
atomize / gulpfile.js
Created March 22, 2019 19:25 — forked from danharper/gulpfile.js
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
@atomize
atomize / data-markdown.user.js
Created March 28, 2019 20:36 — forked from paulirish/data-markdown.user.js
*[data-markdown] - use markdown, sometimes, in your HTML
// ==UserScript==
// @name Use Markdown, sometimes, in your HTML.
// @author Paul Irish <http://paulirish.com/>
// @link http://git.io/data-markdown
// @match *
// ==/UserScript==
// If you're not using this as a userscript just delete from this line up. It's cool, homey.
@atomize
atomize / prism-static.js
Created April 1, 2019 16:45
Static HTML generator for Prism.js highlighted sites.
const fetch = require('node-fetch');
const fs = require('fs');
const jsdom = require("jsdom");
const {
JSDOM
} = jsdom;
const argv = require('minimist')(process.argv.slice(2))
const options = {
runScripts: "dangerously",
resources: "usable",
@atomize
atomize / watchxscreensaver.pl
Created May 25, 2019 16:49
Example of how to run a shell script based on xscreensaver daemon output.
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while (<IN>) {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "sound-off";
$blanked = 1;
}
// MIT License:
//
// Copyright (c) 2010-2012, Joe Walnes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@atomize
atomize / Search my gists.md
Created June 5, 2019 17:41 — forked from santisbon/Search my gists.md
How to search gists

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon

Find all gists with a .yml extension.
extension:yml

Find all gists with HTML files. language:html

function getFlatObject(object) {
function iter(o, p) {
if (Array.isArray(o) ){
o.forEach(function (a, i) {
iter(a, p.concat(i));
});
return;
}
if (o !== null && typeof o === 'object') {
Object.keys(o).forEach(function (k) {
@atomize
atomize / exposeSVGDOM.js
Created July 30, 2019 19:08
Hook into an svg's dom. Note that you need to run this after the object tag has loaded (so you can trigger it with an onload function). It may require adaptation for non-svg elements.
/*
https://stackoverflow.com/a/50059015/8652537
*/
function hooksvg(elementID) { //Hook in the contentDocument of the svg so we can fire its internal scripts
var svgdoc, svgwin, returnvalue = false;
var object = (typeof elementID === 'string' ? document.getElementById(elementID) : elementID);
if (object && object.contentDocument) {
svgdoc = object.contentDocument;
}
else {
@atomize
atomize / fetchProgress.js
Created August 19, 2019 01:59
get progress of fetch()
async function newguy(){
let response = await fetch('https://api.github.com/repos/javascript-tutorial/en.javascript.info/commits?per_page=100');
const reader = response.body.getReader();
// Step 2: get total length
const contentLength = +response.headers.get('Content-Length');
// Step 3: read the data