Skip to content

Instantly share code, notes, and snippets.

View bonniss's full-sized avatar
🥐
Cancer - Croissant

Dan Teddy bonniss

🥐
Cancer - Croissant
View GitHub Profile
@bonniss
bonniss / array.js
Last active October 24, 2020 10:38
Useful snippets in Javascript for up and running project. @link: https://github.com/bootstrap-vue/bootstrap-vue/tree/dev/src/utils
// @link: https://github.com/bootstrap-vue/bootstrap-vue/blob/dev/src/utils/array.js
const from = (...args) => Array.from(...args)
const isArray = val => Array.isArray(val)
const arrayIncludes = (array, value) => array.indexOf(value) !== -1
const concat = (...args) => Array.prototype.concat.apply([], args)
export const createAndFillArray = (size, value) => Array(size).fill(value)
@bonniss
bonniss / better-sqlite3-cheatsheet.md
Last active October 30, 2023 19:14
better-sqlite3 cheatsheet

Refs:

// Init new db
// If the database file does not exist, it is created
// This happens synchronously, which means you can start executing queries right away
const Database = require('better-sqlite3');
@bonniss
bonniss / cors.md
Created June 10, 2020 00:39 — forked from jesperorb/cors.md
Handle CORS Client-side

Handle CORS Client-side

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served. This is set on the server-side and there is nothing you can do from the client-side to change that setting, that is up to the server/API. There are some ways to get around it tho.

Sources : MDN - HTTP Access Control | Wiki - CORS

CORS is set server-side by supplying each request with additional headers which allow requests to be requested outside of the own domain, for example to your localhost. This is primarily set by the header:

Access-Control-Allow-Origin
# Node-WebKit CheatSheet
# Download: https://github.com/rogerwang/node-webkit#downloads
# Old Versions: https://github.com/rogerwang/node-webkit/wiki/Downloads-of-old-versions
# Wiki: https://github.com/rogerwang/node-webkit/wiki
# How: https://github.com/rogerwang/node-webkit/wiki/How-node.js-is-integrated-with-chromium
# 1. Run your application.
# https://github.com/rogerwang/node-webkit/wiki/How-to-run-apps
@bonniss
bonniss / svelte-notes.md
Last active April 5, 2020 04:38
An introduction note on Svelte

Svelte notes

Features

Homepage

  • Write less code: Build boilerplate-free components using languages you already know - HTML, CSS, Javascript
  • No Virtual DOM: Svelte compiles your code to tiny, framework-less vanilla JS - your app starts fast and stay fast
  • Truly reactive: no more complex state management libraries - Svelte brings reactivity to JS itself.
@bonniss
bonniss / JapaneseRegex.js
Created April 4, 2020 09:11 — forked from ryanmcgrath/JapaneseRegex.js
Regex to test for presence of Japanese characters
// REFERENCE UNICODE TABLES:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
// http://www.tamasoft.co.jp/en/general-info/unicode.html
//
// TEST EDITOR:
// http://www.gethifi.com/tools/regex
//
// UNICODE RANGE : DESCRIPTION
//
// 3000-303F : punctuation
@bonniss
bonniss / regex-japanese.txt
Created April 4, 2020 07:53 — forked from terrancesnyder/regex-japanese.txt
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
@bonniss
bonniss / count-days.js
Created March 16, 2020 03:06
Count the days of a given month and year
// determine how many days are in a given month
// http://stackoverflow.com/questions/315760/what-is-the-best-way-to-determine-the-number-of-days-in-a-month-with-javascript
function daysInMonth( m, y ) {
return m === 2 ? y & 3 || !( y % 25 ) && y & 15 ? 28 : 29 : 30 + ( m+ ( m >> 3 ) & 1 );
}
// determine the day number since beginning of the year
// http://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366/27790471#27790471
function dayNo( y, m, d ){
return --m * 31 - ( m > 1 ? ( 1054267675 >> m * 3 -6 & 7 ) - ( y & 3 || !( y % 25 ) && y & 15 ? 0 : 1 ) : 0 ) + d;
@bonniss
bonniss / oct-twig-extension.md
Created March 15, 2020 02:49
README of Twig Extension OctoberCMS

Twig extensions

Build Status Codacy Scrutinizer Coverage License

Twig extensions plugin for OctoberCMS adds new filter and functions to your templates. No other plugin dependencies.

Tested with the latest stable OctoberCMS build 420 (with Laravel 5.5). For Laravel 5.4 use special branch laravel54.

@bonniss
bonniss / vanilla-js-cheatsheet.md
Created February 12, 2020 19:45 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet