Skip to content

Instantly share code, notes, and snippets.

@innermond
innermond / gist:17e5e6ab3f0c09d909c98b9bdaca33e9
Created October 6, 2020 10:46
thumbify images or image-like series
for img in <path/to/images>/*<.extension>; do noext="${img%.*}"; other=<path/to/thumb>/"${noext#*/}".<other-extension>; convert -resize 300x "$img" "$other" ; done
@innermond
innermond / gist:3db8fad1bccac4bcd357dacb8d41e833
Created August 30, 2020 14:14
reading a file in rust using buffered reader
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
fn main() {
let s = match read_as_string("<path/to/file>".to_string()) {
Ok(content) => content,
Err(e) => format!("{:?}", e),
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@innermond
innermond / gist:e5a315843874043e13a66cb8e19c078c
Created March 4, 2020 10:09
svg text elements aligned to center
var centerTextAlign = function($elem) {
if ($elem.tagName != 'text') return false;
var bb=$elem.getBBox();
var x0=bb.x,y0=bb.y;
$elem.style.setProperty('text-align', 'center');
$elem.style.setProperty('text-anchor', 'middle');
bb=$elem.getBBox();
var x1=bb.x,y1=bb.y;
// position changed because of alignment alteration
var offset = x0 - x1;
@innermond
innermond / gist:787ce0187986833659fa76b3b50bf7de
Created March 2, 2020 17:55
calculate next y line of a text tspan
var replaceTextNode = function($parent, txt) {
// has a textPath?
var $textPath = $parent.getElementsByTagName('textPath');
if ($textPath) $textPath = $textPath[0];
// clean off
while ($parent.hasChildNodes())
$parent.removeChild($parent.lastChild);
// white space off
txt = txt.trim();
// get array of lines
@innermond
innermond / gist:e5750af0da6a8bef9b411f33e9574d01
Last active February 28, 2020 21:30
svg element scales arround its center
$img = document.querySelector('image:nth-of-type(2)')
$svg = document.querySelector('svg')
k = 2.5
bb = $img.getBBox()
x = bb.x + bb.width/2
x *= (1-k)
y = bb.y + bb.height/2
y *= (1-k)
@innermond
innermond / gist:08124bd00308d31da8a4e8ac73c0b337
Created February 6, 2020 16:45
get link to image of a google search result
out=''
src=''
document.querySelectorAll('img[class^=rg_i]').forEach(x=>{
src=x.dataset.src??x.dataset.iurl??x.src??'none'
if (src === 'none') {
console.log(x)
return
}
out+=src+"\n"
})
<style>
#box {
background-color: rgba(40, 40, 190, 255);
border: 4px solid rgb(20, 20, 120);
transition: background-color 1s, border 1s;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
* {
box-sizing: border-box;
}
ul {
padding: 0;
margin: 0;
}
body {
background-color: #eee;
margin: 0px;
#!/bin/bash
rm -rf optimized/**
mkdir -p optimized/400w
convert unoptimized/*.jpg -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG -colorspace sRGB -set filename:base "%[base]" -resize 700x -sigmoidal-contrast 5,50% optimized/"%[filename:base].jpg"
convert unoptimized/*.jpg -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG -colorspace sRGB -set filename:base "%[base]" -resize 400x -sigmoidal-contrast 5,50% optimized/400w/"%[filename:base].jpg"
find ./optimized -regex '.*\.\(jpg\|png\)$' -exec bash -c 'convert "$@" -define webp:lossless=false "${@%.*}".webp' _ {} \;