Skip to content

Instantly share code, notes, and snippets.

View jbnv's full-sized avatar
🙂
Life is good.

Jay Bienvenu jbnv

🙂
Life is good.
View GitHub Profile
@jbnv
jbnv / svg-to-png.js
Created October 7, 2024 01:11
Script I use to save an SVG image on an HTML page as a PNG, JPG or WEBP image.
const dataHeader = 'data:image/svg+xml;charset=utf-8';
const $svg = document.getElementById('svg-container').querySelector('svg'); // <svg> element to save
const $holder = document.getElementById('img-container'); // <div> element
const destroyChildren = $element => {
while ($element.firstChild) {
const $lastChild = $element.lastChild ?? false
if ($lastChild) $element.removeChild($lastChild)
}
}
@jbnv
jbnv / roam.css
Last active July 29, 2023 20:22
Stylesheet for Roam Research
/* Based on original Dark Age theme by @shodty */
/* MAIN BODY AND BLOCK COLORS */
.roam-body-main {
margin-top: 45px;
border-radius: 12px;
background: var(--background);
margin-right: 6px;
margin-left: 9px;
@jbnv
jbnv / registerVueComponents.js
Last active June 17, 2020 13:54
Various functions associated with programming in Vue.
import Vue from '../app/mount.js';
import Clipboard from 'clipboard';
function clipboardSuccess() {
Vue.prototype.$message({
message: 'Copy successfully',
type: 'success',
duration: 1500,
});
}
@jbnv
jbnv / split.js
Created June 14, 2020 11:37
Node script to split a JSON file containing a single object into a folder of files.
const fs = require('fs');
const directory = process.argv[2];
fs.mkdir(directory, {
recursive: false
}, (err) => {
fs.readFile(`./${directory}.json`, 'utf8', (err, data) => {
if (err) throw err;
Object.entries(JSON.parse(data)).forEach(pair => {
const key = pair[0];
@jbnv
jbnv / Authenticate.php
Last active April 29, 2021 02:31
Debugging 401 Unauthorized on Laravel web/auth route
class Authenticate extends \Illuminate\Auth\Middleware\Authenticate
{
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
@jbnv
jbnv / Basic Commands.md
Last active January 12, 2018 16:28
Vim Quick Reference

Note: These apply to the Vim-Mode-Plus plugin for Atom and my custom keymaps. This is not a generic reference for Vim.

A "word" is an alphanumeric string. A "WORD" is any series of non-whitespace separated by whitespace.

  • a Append after cursor/at end of line.
  • b Previous word/WORD ("backword").
  • c Change. 🔠 Change to end of line.
  • d Delete. 🔠 Delete to end of line.
  • e End of word.
  • f
@jbnv
jbnv / js.cson
Created September 11, 2017 18:06
Atom Snippets
'.source.js':
'alert':
'prefix':'//a'
'body': """
//BEGIN TEMP
alert($1);
//END TEMP
"""
'console.log':
'prefix':'//c'
@jbnv
jbnv / csv.php
Created February 15, 2017 17:09
Convert various list formats to arrays.
$csv = <<<CONTENT
...
CONTENT;
$outbound = array();
foreach(explode("\n",$tsv) AS $line) {
$a = explode(",",$line);
$outbound[$a[0]] = $a[1];
}
@jbnv
jbnv / shim.php
Created February 3, 2017 22:15
Debugging shim for PHP.
//BEGIN TEMP
echo '<p>['.__FILE__.':'.__LINE__.'] GOOD</p>';
try {
// some command here
} catch (Exception $e){
NsStrings::print_r_block($e);
}
echo '<p>['.__FILE__.':'.__LINE__.'] DIE</p>';
die;
//END TEMP
@jbnv
jbnv / coalesce.php
Created February 3, 2017 21:48
Return the first value that isn't unset, null or empty.
// Return the first value that isn't unset, null or empty.
function coalesce() {
foreach(func_get_args() as $arg) {
if (!empty($arg)) return $arg;
}
return null;
}