Skip to content

Instantly share code, notes, and snippets.

View cjus's full-sized avatar
🤓

Carlos Justiniano cjus

🤓
View GitHub Profile
@cjus
cjus / buildFixup.js
Last active June 12, 2018 17:01
Fixup file for Preact build
const fs = require('fs');
const path = require('path');
const packageJson = require('./package.json');
let filePath = path.join(__dirname, '/build/index.html');
let html = fs.readFileSync(filePath, 'utf8');
html = html.replace('<head>', `<head><base href="${packageJson.homepage}">`);
fs.writeFileSync('build/index.html', html);
@cjus
cjus / preact.config.js
Last active June 15, 2018 11:48
Preact Webpack Hook
export default (config, env, helpers) => {
config.target = 'electron-renderer';
if (env.production) {
config.output.publicPath = env.pkg.homepage;
let {plugin} = helpers.getPluginsByName(config, 'DefinePlugin')[0];
plugin.definitions['PUBLIC_PATH'] = env.pkg.homepage;
}
};
@cjus
cjus / main.js
Created June 12, 2018 16:12
loadURL
const startUrl = process.env.ELECTRON_START_URL || url.format({
pathname: path.join(__dirname, '/../build/index.html'),
protocol: 'file:',
slashes: true
});
win.loadURL(startUrl);
@cjus
cjus / main.js
Created June 9, 2018 22:57
Electron main.js file
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
/**
* @name createWindow
@cjus
cjus / electron-wait-react.js
Last active June 9, 2018 23:59
Electron Wait React
const net = require('net');
const port = process.env.PORT ? (process.env.PORT - 100) : 5000;
process.env.ELECTRON_START_URL = `http://localhost:${port}`;
const client = new net.Socket();
let startedElectron = false;
const tryConnection = () => client.connect({port: port}, () => {
client.end();
@cjus
cjus / countdown.sh
Last active March 29, 2018 21:59
Shell based countdown timer
#!/bin/bash
COUNTER=$1
while [ $COUNTER -gt 1 ]; do
let COUNTER=COUNTER-1
echo -ne "Seconds remaining: $COUNTER\033[0K\r"
sleep 1
done
echo -ne "\033[0K\r"
@cjus
cjus / config.json
Last active February 19, 2018 04:00
Hydra getServicePresence example
{
"hydra": {
"serviceName": "caller",
"serviceDescription": "",
"serviceIP": "",
"servicePort": 0,
"serviceType": "",
"redis": {
"url": "redis://localhost:6379/15"
}
@cjus
cjus / node-interfaces.md
Last active August 10, 2017 12:09
Show available network interfaces in a Node JS app
const os = require('os');
let interfaces = os.networkInterfaces();
Object.keys(interfaces).
  forEach((interface) => {
    interfaces[interface].forEach((interfaceRecord)=>{
      if (interfaceRecord.family === 'IPv4') {
        console.log(`${interface}: ${interfaceRecord.address}`);
 }
@cjus
cjus / `Hydra-workshop.md
Last active December 15, 2016 15:25
Hydra workshop files
@cjus
cjus / nodejs-project-backup.md
Last active January 2, 2021 16:58
NodeJS project backup script

NodeJS project backup script

The following shell script backups up the currrent node project by performing the following actions:

  • Assumes that the back script is bundled with the actual NodeJS projecxt foler.
  • Uses the current directory as the backup file name.
  • Moves to the parent folder to create a tarball using the project name and the current date stamp and excludes the node_modules folder.
  • Lists the backups created using the script.