Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
vbarbarosh / app_svgtext.js
Last active May 24, 2019 18:36
app_svgtext – Render a text into .svg file https://codescreens.com
#!/usr/bin/env node
const TextToSVG = require('text-to-svg');
const path = require('path');
const puppeteer = require('puppeteer');
// Render a text into .svg file
//
// $ svgtext.js font.ttf Hello
// <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://...
#!/usr/bin/env node
const path = require('path');
const puppeteer = require('puppeteer');
// Get bounding box of an svg
//
// $ node app_svgbbox.js a.svg
// 2.74 -61.85 180.86 62.43
@vbarbarosh
vbarbarosh / php_class_clone_alt.php
Last active May 22, 2019 17:48
php_class_clone_alt – Clone an object, then alter it a little https://codescreens.com
<?php
// Clone an object, then alter it a little
//
// Object Cloning
// http://php.net/manual/en/language.oop5.cloning.php
//
// Magic Methods
// http://www.php.net/manual/en/language.oop5.magic.php
@vbarbarosh
vbarbarosh / php_class_ctor_parent.php
Last active May 21, 2019 18:32
php_class_ctor_parent – Generic way to call base class constructor https://codescreens.com
<?php
# Generic way to call base class constructor
class Foo
{
public function __construct()
{
echo "FOO\n";
}
@vbarbarosh
vbarbarosh / shell_bash_jobs_fg
Created May 20, 2019 17:49
shell_bash_jobs_fg – Using fg command 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
# Using fg command
# https://www.gnu.org/software/bash/manual/html_node/Job-Control-Basics.html
# Enable job control. Otherwise, `fg` will yield "fg: no job control"
@vbarbarosh
vbarbarosh / shell_curl_post_put_patch_delete
Last active May 18, 2019 17:57
shell_curl_post_put_patch_delete – Sending POST|PUT|PATCH|DELETE requests with curl 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
# Sending POST|PUT|PATCH|DELETE requests with curl
# https://ec.haxx.se/http-post.html
# https://curl.haxx.se/docs/manpage.html
@vbarbarosh
vbarbarosh / shell_curl_post_multipart_detailed
Last active May 17, 2019 18:08
shell_curl_post_multipart_detailed – POST as multipart/form-data with curl 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
# POST as multipart/form-data with curl
# https://curl.haxx.se/docs/manpage.html
# Send name=value (`<`, `@`, and `;` in value has special meaning)
@vbarbarosh
vbarbarosh / js_pager_numerate_ellipsis.js
Last active May 16, 2019 17:58
js_pager_numerate_ellipsis – Generate page numbers like Amazon does https://codescreens.com
// Generate page numbers like Amazon does
//
// The algorithm:
// 1) Represent a result as three ranges: first, middle, last
// 2) Merge three ranges into single array, sort then remove duplicates.
// 3) Insert N between two adjacent numbers with values N-1 and N+1.
// 4) Insert ... between two adjacent numbers with difference more than 1.
//
// Inspired by https://gist.github.com/kottenator/9d936eb3e4e3c3e02598
@vbarbarosh
vbarbarosh / shell_curl_post_urlencoded_unsafe
Last active May 15, 2019 18:32
shell_curl_post_urlencoded_unsafe – POST as application/x-www-form-urlencoded with curl 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
# POST as application/x-www-form-urlencoded with curl
# https://curl.haxx.se/docs/manpage.html
# No encoding will be made at all. If contents are taken from a file
@vbarbarosh
vbarbarosh / shell_files_truncate
Last active May 14, 2019 18:34
shell_files_truncate – Truncate 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
# Truncate files
# Shrink existing file to 4096 bytes
truncate -s 4K foo