Skip to content

Instantly share code, notes, and snippets.

View nijikokun's full-sized avatar
🍀
working

Niji nijikokun

🍀
working
  • Product Manager
  • San Diego, California
View GitHub Profile
@nijikokun
nijikokun / template.js
Created March 21, 2024 01:32
String Template
// Map from lowercase to flag emoji
const mapLowerUpper = {
'a': '🇦', 'b': '🇧', 'c': '🇨', 'd': '🇩', 'e': '🇪',
'f': '🇫', 'g': '🇬', 'h': '🇭', 'i': '🇮', 'j': '🇯',
'k': '🇰', 'l': '🇱', 'm': '🇲', 'n': '🇳', 'o': '🇴',
'p': '🇵', 'q': '🇶', 'r': '🇷', 's': '🇸', 't': '🇹',
'u': '🇺', 'v': '🇻', 'w': '🇼', 'x': '🇽', 'y': '🇾', 'z': '🇿'
};
// Map for Morse code
@nijikokun
nijikokun / base64-utf8.module.js
Last active February 11, 2024 23:16
Javascript Base64 UTF8 for the Browser / Server. Base64 UTF-8 Encoding and Decoding Libraries / Modules for AMD, CommonJS, Nodejs and Browsers. Cross-browser compatible.
// UTF8 Module
//
// Cleaner and modularized utf-8 encoding and decoding library for javascript.
//
// copyright: MIT
// author: Nijiko Yonskai, @nijikokun, nijikokun@gmail.com
(function (name, definition, context, dependencies) {
if (typeof context['module'] !== 'undefined' && context['module']['exports']) { if (dependencies && context['require']) { for (var i = 0; i < dependencies.length; i++) context[dependencies[i]] = context['require'](dependencies[i]); } context['module']['exports'] = definition.apply(context); }
else if (typeof context['define'] !== 'undefined' && context['define'] === 'function' && context['define']['amd']) { define(name, (dependencies || []), definition); }
else { context[name] = definition.apply(context); }
@nijikokun
nijikokun / about.md
Last active January 24, 2024 08:48
Cool ways to Diff two HTTP Requests in your terminal!

Basic diffing

  • Line by line
  • No colors
  • Able to be piped into vim (shown later on)
diff <(curl -vs https://reddit.com 2>&1) <(curl -vs https://reddit.com 2>&1)
@nijikokun
nijikokun / doc.md
Last active August 21, 2023 08:00
Building Javascript Frontend / Backend Applications

Document for the best design choices you can make for your software.

Terminology

  • DDD - [Domain Driven Design][ddd-wikipedia]
  • FF or FTF - Function First Design, or File-type First Design is structuring your application by it's function before the files such as a directory named components containing all component files.

File Structure

Structuring applications is hard, here are a few resources to help.

@nijikokun
nijikokun / css-notes.css
Created July 23, 2011 02:30
CSS & CSS3 Notes, Constantly Used, Very helpful.
/*
* CSS & CSS3 Notepad
*
* These were made for my personal usage, as I constantly use them.
* I have decided to open-source the file.
*
* Some is very useful, other things may be re-dundant.
*
* Once again, these are simply my css notes.
*
@nijikokun
nijikokun / bench-execution.md
Last active March 12, 2023 12:24
Benchmark single method execution time easily using Node.js or Javascript in general.

So, I was developing a node shell script and wanted to determine the time it took from start, to finish to generate the output of a file. Simple, right? It is, but the problem is that if you want a clean way to do it... you have to develop it, otherwise you'll have a lot of wrapper code surrounding methods and such. So I wrote a small method to simplify it even further.

Benchmark Method:

function benchmark (method) {
  var start = +(new Date);

  method && method(function (callback) {
 var end = +(new Date);
@nijikokun
nijikokun / karabiner-elements.fn-wasd-to-arrow-keys.json
Last active January 12, 2023 05:34
FN+WASD -> Arrow Keys (Simple key caps_lock to fn)
{
"description": "caps_lock + w,a,s,d to arrow_keys",
"manipulators": [
{
"from": {
"key_code": "w",
"modifiers": {
"mandatory": [
"fn"
],
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@nijikokun
nijikokun / command.system.js
Last active September 22, 2022 09:48
Javascript Function Annotations, can be used for anything. Enjoy.
/*
* Javascript Annotations
*
* Maybe I am ahead of my time, or behind the times (asm.js).
* Either way, this is how they work (or could work) if you aren't afraid of some simple RegExp magic.
*
* @author Nijiko Yonskai
* @license MIT (or whatever college/license/name you prefer ;)
* @copyright 2013
*/
@nijikokun
nijikokun / RMMZ_DataManager_Store.js
Created May 27, 2022 13:57
How to extend the RPG Maker MZ DataManager to store custom stuff for your plugin.
//===========================================================================
// Extend DataManager to persist specific changes
//===========================================================================
const RMMZ_DataManager_makeSaveContents = DataManager.makeSaveContents;
const RMMZ_DataManager_extractSaveContents = DataManager.extractSaveContents;
const RMMZ_DataManager_onLoad = DataManager.onLoad;
DataManager.makeSaveContents = function() {
const contents = RMMZ_DataManager_makeSaveContents.call(this);