Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
vbarbarosh / svg_pattern_dots.svg
Last active December 8, 2020 22:40
svg_pattern_dots – Drawing dots on each 5th pixel https://codescreens.com
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vbarbarosh
vbarbarosh / shell_lines_prefix_time
Last active October 3, 2020 22:05
shell_lines_prefix_time – Add a timestamp to beginning of each line https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Add a timestamp to beginning of each line
# The fastest
# https://unix.stackexchange.com/a/26797/121657
@vbarbarosh
vbarbarosh / js_html_escape.js
Last active April 27, 2020 17:45
js_html_escape – Make a string safe to put into html https://codescreens.com
// Make a string safe to put into html
// https://stackoverflow.com/a/6234804/1478566
//
// Consider using https://github.com/mathiasbynens/he for production
function html_escape(s)
{
return s
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
@vbarbarosh
vbarbarosh / node_csv_write.js
Last active June 27, 2019 20:12
node_csv_write – Create csv files from arrays https://codescreens.com
const {createObjectCsvWriter} = require('csv-writer');
// Create csv files from arrays
main().catch(panic);
// https://stackabuse.com/reading-and-writing-csv-files-with-node-js/
async function main()
{
const rows = [
@vbarbarosh
vbarbarosh / shell_lines_common
Last active June 23, 2019 14:46
shell_lines_common – Show common lines in two files https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Show common lines in two files
# https://unix.stackexchange.com/a/398143/121657
# > Use comm -12 file1 file2 to get common lines in both files.
@vbarbarosh
vbarbarosh / node_csv_parse.js
Last active June 21, 2019 19:05
node_csv_parse – Parsing csv files and strings https://codescreens.com
const csv = require('neat-csv');
const fs = require('fs');
const path = require('path');
// Parsing csv files and strings
main().catch(panic);
// https://stackabuse.com/reading-and-writing-csv-files-with-node-js/
async function main()
@vbarbarosh
vbarbarosh / math_line_intersection.html
Last active June 18, 2019 20:02
math_line_intersection – Calculating the point of intersection of two lines https://codescreens.com
<!-- Calculating the point of intersection of two lines -->
<svg id="app" xmlns="http://www.w3.org/2000/svg">
<line :x1="x1" :y1="y1" :x2="x2" :y2="y2" stroke="black" />
<line :x1="x3" :y1="y3" :x2="x4" :y2="y4" stroke="black" />
<circle :cx="c.x" :cy="c.y" r="3" fill="red" />
</svg>
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script>
// https://stackoverflow.com/a/38977789/1478566
@vbarbarosh
vbarbarosh / css_keyframes_values_at.html
Last active June 17, 2019 12:18
css_keyframes_values_at – Get property values from keyframes at specific time https://codescreens.com
<div id="app">
Get property values from keyframes at specific time.
<br>
<textarea v-model="keyframes" cols="50" rows="5"></textarea>
<br>
<input v-model="time" type="number" min="0" max="1" step="0.01">
<pre>{{ values }}</pre>
</div>
<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
@vbarbarosh
vbarbarosh / css_pretty_format
Last active June 14, 2019 19:54
css_pretty_format – How to pretty print css https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# How to pretty print css
#
# usage
# $ cat a.css | ./css_pretty_format > out.css
@vbarbarosh
vbarbarosh / css_autoprefixer_clean
Last active June 13, 2019 20:21
css_autoprefixer_clean – Remove prefixes from css https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Remove prefixes from css
#
# usage
# $ cat a.css | ./css_autoprefixer_clean > out.css