Skip to content

Instantly share code, notes, and snippets.

@snirp
snirp / svgo_config.js
Last active October 17, 2020 13:45
Workaround to prefix the SVG id's with a random number. Solves id collisions with multiple SVG files
{
cleanupIDs: {
prefix: {
toString() {
return `${Math.random().toString(36).substr(2, 9)}`;
}
}
}
}
@snirp
snirp / update.sh
Created October 12, 2020 07:55
brew update --debug --verbose
snirp@SB eal-website % brew update --debug --verbose
+ [[ -z '' ]]
+ [[ -z '' ]]
+ [[ -n '' ]]
+ [[ -n '' ]]
+ export HOMEBREW_UPDATE_TO_TAG=1
+ HOMEBREW_UPDATE_TO_TAG=1
+ [[ -z '' ]]
+ HOMEBREW_AUTO_UPDATE_SECS=300
+ [[ -e /usr/local/Cellar ]]
@snirp
snirp / optimize-svg.sh
Last active October 9, 2020 08:26
Optimize SVG
# Batch operation on folder using config file
svgo -f ../path/to/svg/files -o ../path/to/svg/output --context=svgo.yml
@snirp
snirp / ready.js
Created January 12, 2020 14:50
Document ready function (similar to jQuery $)
const ready = fn =>
document.readyState != "loading"
? fn()
: document.addEventListener("DOMContentLoaded", fn)
// Use as follows
ready(() => {})
@snirp
snirp / make_sprite.py
Last active January 10, 2020 09:33
Create an SVG sprite from a folder of SVG files
import os
from bs4 import BeautifulSoup
path = 'packs/ant'
sprite = 'sprites/ant.svg'
prefix = 'ant-'
f = open(sprite,"w+")
f.write('<svg xmlns="http://www.w3.org/2000/svg">' + '\n')
@snirp
snirp / glyphs.scss
Created October 4, 2019 18:57
Custom implementation of Bootstrap 3 glyphicons
/* Drop-in replacement for Bootstrap3 icon font */
@font-face {
font-family: 'Glyphicons Halflings';
src: url('glyphicons-halflings-regular.woff2') format('woff2'),
url('glyphicons-halflings-regular.woff') format('woff');
}
// Catchall baseclass
.glyphicon {
@snirp
snirp / nginx.conf
Created October 1, 2019 12:40
nginx config
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@snirp
snirp / component.js
Created September 4, 2019 09:09
React submit non controlled form
handleSubmit = e => {
e.preventDefault()
const formObj = Array.from(new FormData(e.target).entries())
.reduce((obj, pair) => ({...obj, [pair[0]]: pair[1]}), {})
this.props.submitObject(formObj)
}
@snirp
snirp / split-svg-sprites.js
Created June 4, 2019 11:17
Split SVG sheet into individual svg's
var fs = require('fs');
var path = require('path');
var markup = fs.readFileSync('sprite.svg').toString();
var lines = markup.split(/\n/g);
var symbols = {};
var currentSymbol = null;
lines.forEach(function(line){
var open = line.match(/symbol.*?id="(.*?)"/);
@snirp
snirp / vue-polar-clock.html
Last active January 8, 2019 16:51
code sample for vue polar
<div style="position:relative; height:400px;" id="app4">
<!-- numbers -->
<polar v-for="n in 12" :key="n" :angle="n*30-90" :offset="'150px'" :width="'40px'" :height="'40px'">
<div class='clock-number'>
{{n}}
</div>
</polar>
<!-- minute markers -->
<polar v-bind="minutesPropsObj" v-for="n in 60" :key="n" :angle="n/60*360"></polar>
<!-- hour markers -->