Skip to content

Instantly share code, notes, and snippets.

View nash403's full-sized avatar
🦄
want a cookie ?

Honoré Nintunze nash403

🦄
want a cookie ?
View GitHub Profile
@jrop
jrop / webpack.config.js
Last active November 21, 2017 19:32
Electron/Backend webpack.config.js
//
// Bundles everything *except* dependencies/builtins
// npm install webpack-configify builtin-modules
//
const builder = require('webpack-configify').default
const builtins = require('builtin-modules')
const PROD = process.env.NODE_ENV == 'production'
const DEPS = Object.keys(require('./package').dependencies || {})
@eloone
eloone / binaryInsert.js
Last active June 22, 2019 15:43
Binary Insert
/**
* Example :
* var a = [2,7,9];
* binaryInsert(8, a);
*
* It will output a = [2,7,8,9]
*
*/
function binaryInsert(value, array, startVal, endVal){
@icebob
icebob / webpack.server.config.js
Last active February 23, 2021 17:52
NodeJS server/backend bundle with webpack
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
@igogrek
igogrek / Vue code style.md
Last active April 11, 2021 06:58
Code style and application structure

Application structure

General

  1. Application has tree structure with folders for each "feature"
  2. Feature folders are named with lowerCamelCase → myComponentDashboard
  3. Feature can contain any number of components and nested features
  4. Components are named using UpperCamelCase → MyWidgetComponent.vue
  5. Component can have translation .yml file named correspondingly → MyWidgetComponent.yml
  6. If component requires more than 2 files: .vue and .yml file - folder is created with the same name → MyWidgetComponent
@ericelliott
ericelliott / naive-runtime-type-checking.js
Last active September 1, 2022 02:56
Naive runtime type checking example
const fn = (fn, {required = []}) => (params = {}) => {
const missing = required.filter(param => !(param in params));
if (missing.length) {
throw new Error(`${ fn.name }() Missing required parameter(s):
${ missing.join(', ') }`);
}
return fn(params);
};
@nfreear
nfreear / floating-point-compare.js
Created July 4, 2013 13:02
Floating point Javascript: less than & greater than comparisons.
/*
http://stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison
*/
var EPSILON = 0.000001;
function fp_less_than(A, B, Epsilon) {
Epsilon = Epsilon || EPSILON;
return (A - B < Epsilon) && (Math.abs(A - B) > Epsilon);
};
@szalishchuk
szalishchuk / ip.js
Last active December 14, 2022 11:04
Get local external ip address with nodejs
var
// Local ip address that we're trying to calculate
address
// Provides a few basic operating-system related utility functions (built-in)
,os = require('os')
// Network interfaces
,ifaces = os.networkInterfaces();
// Iterate over interfaces ...
@TooTallNate
TooTallNate / http-error.js
Created August 3, 2016 00:48
HTTPError class for JavaScript HTTP errors
import { format } from 'url';
import { STATUS_CODES } from 'http';
import uppercamelcase from 'uppercamelcase';
class HTTPError extends Error {
constructor(code, message, extras) {
super(message || STATUS_CODES[code]);
if (arguments.length >= 3 && extras) {
Object.assign(this, extras);
}
@nash403
nash403 / normalizeChar.mjs
Last active February 15, 2023 10:39
Normalize a character/string to remove accents. (For comparison)
/*
Two things will happen here:
1) normalize()ing to NFD Unicode normal form decomposes combined graphemes into the combination of simple ones. The è of Crème ends up expressed as e + ̀.
2) Using a regex character class to match the U+0300 → U+036F range, it is now trivial to globally get rid of the diacritics, which the Unicode standard conveniently groups as the Combining Diacritical Marks Unicode block.
*/
export const normalizeChar = char => char.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
export const normalizeStr = str => str.split('').map(normalizeChar).join('')
@nash403
nash403 / decorators.js
Created June 20, 2019 07:05
JS Decorators How to example
// Prop/Method Decorator with no arguments
function logDecorator(t, n, descriptor) {
const original = descriptor.value;
if (typeof original === 'function') {
descriptor.value = function(...args) {
console.log(`Arguments: ${args}`);
try {
const result = original.apply(this, args);
console.log(`Result: ${result}`);
return result;