Skip to content

Instantly share code, notes, and snippets.

View acfatah's full-sized avatar
🏠
Working from home

Achmad F. Ibrahim acfatah

🏠
Working from home
  • Temerloh, Pahang, Malaysia
  • 04:00 (UTC +08:00)
  • X @acfatah
View GitHub Profile

JavaScript Modules

  1. How do I make the tree shakeable?
  2. What JS module systems should I target (CommonJS, AMD, ES6).
  3. Should I transpile the source?
  4. Should I bundle the source?
  5. What files should I publish?

Let's try to address all the above questions now.

@acfatah
acfatah / bash_strict_mode.md
Created April 1, 2023 02:33 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@acfatah
acfatah / sleep.js
Last active March 17, 2023 02:38
Javascript ES Module - sleep.js
/**
* Sleep, delay, pause or wait in Javascript
* @link https://www.sitepoint.com/delay-sleep-pause-wait/
* @param {Number} timeout Number in miliseconds
* @return {Promise}
*/
export const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))
@acfatah
acfatah / component-app.js
Created February 7, 2023 08:16 — forked from kesor/component-app.js
Vue.js 3.x with ES6 modules in the browser using import-map
import { defineAsyncComponent } from 'vue'
const Content = defineAsyncComponent(() => import('./component-content.js'))
export default {
name: 'App',
components: { Content },
template: /*html*/`
<Content />
`
@acfatah
acfatah / bash_template.sh
Created February 2, 2023 02:46 — forked from rsperl/bash_template.sh
bash script templates #shell #template #snippet
#!/bin/bash
# see also
# - Google's Shell Style Guide: https://google.github.io/styleguide/shell.xml
# - ShellCheck: https://github.com/koalaman/shellcheck
# src:
# - http://hackaday.com/2017/07/21/linux-fu-better-bash-scripting
# - https://dev.to/thiht/shell-scripts-matter
@acfatah
acfatah / unix-digitalocean-spaces-s3cmd.md
Last active January 27, 2023 03:39 — forked from jbutko/unix-digitalocean-spaces-s3cmd.md
Unix (ubuntu): setup and use s3cmd to upload files to digitalocean spaces
@acfatah
acfatah / singleton_logger.rb
Created December 19, 2022 03:21 — forked from cheeyeo/singleton_logger.rb
Simple logger using Ruby's built in Singleton module
require 'singleton'
class SimpleLogger
include Singleton
attr_accessor :level
ERROR=1
WARNING=2
INFO=3
@acfatah
acfatah / authenticable.rb
Created December 7, 2022 08:52 — forked from esteedqueen/authenticable.rb
JSON API User Registration and Sessions with Devise
module Authenticable
# Devise methods overwrite
def current_user
@current_user ||= User.find_by(authentication_token: request.headers['Authorization'])
end
def authenticate_with_token!
render json: { errors: "Not authenticated" },
status: :unauthorized unless user_signed_in?
The MIT License (MIT)
Copyright (c) 2013 Jamar Parris
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE S
@acfatah
acfatah / node-sample.js
Created May 13, 2022 00:36 — forked from gus3inov/node-sample.js
get battery info with node.js
const http = require('http');
const PORT = Number(process.argv[2]) || 8080;
const child_process = require('child_process');
const Routes = {
BATTERY: /\/battery\/?/
};
const Status = {
NOT_FOUND: 404,