Skip to content

Instantly share code, notes, and snippets.

View hackjutsu's full-sized avatar
:octocat:
building something great

CosmoX hackjutsu

:octocat:
building something great
View GitHub Profile
@hackjutsu
hackjutsu / ObjectWaitNotifyExample.java
Last active February 28, 2018 10:17
[wait/notify/notifyAll] Example for Java Object's wait/notify/notifyAll #concurrency mechanism.
public class ObjectWaitNotifyExample {
private static final long SLEEP_INTERVAL_MS = 1000;
private boolean running = true;
private Thread thread;
public void start() {
print("Inside start()...");
thread = new Thread(new Runnable() {
@Override
public void run() {
@hackjutsu
hackjutsu / lexical_scope.js
Last active October 15, 2016 00:28
Example explaining the lexical scope in JS
var a = 10;
function add() {
var b = 20;
return a + b; // a is bound to the global a when the function object add() is created.
}
// call add() -> 30
(function() {
var a = 20;
@hackjutsu
hackjutsu / print_local_repo_path.sh
Created October 20, 2016 21:42
Print out the path to the local Maven Repo
mvn help:evaluate -Dexpression=settings.localRepository | grep -v '\[INFO\]'
public static boolean[][] deepCopy(boolean[][] original) {
if (original == null) {
return null;
}
final boolean[][] result = new boolean[original.length][];
for (int i = 0; i < original.length; i++) {
result[i] = Arrays.copyOf(original[i], original[i].length);
// For Java versions prior to Java 6 use the next:
// System.arraycopy(original[i], 0, result[i], 0, original[i].length);
@hackjutsu
hackjutsu / 7z_install.sh
Last active January 17, 2017 01:35
Steps to install 7z executable on Mac via Terminal.
# Homebrew
brew update
brew install p7zip
# Macport
sudo port install p7zip
@hackjutsu
hackjutsu / clearView.js
Last active January 17, 2017 04:10
Method to clear nodes inside a html element with specific id
// Clear all the nodes inside the element with id 'main-area'
function clearView() {
var mainArea = document.getElementById('main-area');
var firstChild = mainArea.firstChild;
while (firstChild) {
mainArea.removeChild(firstChild);
firstChild = mainArea.firstChild;
}
}
@hackjutsu
hackjutsu / time_benchmark.js
Last active February 2, 2017 08:36
The time benchmark in Nodejs #tags: lepton
let startTime = process.hrtime();
//...
let diff = process.hrtime(startTime);
console.log('benchmark took %d nanoseconds', diff[0] * 1e9 + diff[1]);
@hackjutsu
hackjutsu / IPC_electron.js
Last active February 2, 2017 08:35
[Sending IPC events from main to renderer in Electron] (http://stackoverflow.com/a/36809014/3697757) #tags: electron,lepton
// To send events to particular window you can use webContents.send(EVENT_NAME, ARGS) (see docs). webContents is a property of a window instance:
// main process
storeWindow.webContents.send('store-data', store);
// To listen for this event being sent, you need a listener in a window process (renderer):
// renderer process
// ipcRenderer is provided by electron package. You can import it like this: var ipcRenderer = require('electron').ipcRenderer; or es6 import { ipcRenderer } from 'electron';
import { ipcRenderer } from 'electron';
ipcRenderer.on('store-data', function (store) {
@hackjutsu
hackjutsu / app.js
Last active October 27, 2017 14:47
[How to store user data in Electron] (https://goo.gl/FPbs8z) #tags: electron, lepton
// vim: syntax=javascript
const { app, BrowserWindow } = require('electron');
const path = require('path');
const Store = require('./store.js');
let mainWindow; //do this so that the window object doesn't get GC'd
// First instantiate the class
const store = new Store({
// We'll call our data file 'user-preferences'
@hackjutsu
hackjutsu / create_dir_if_not_exist.js
Created January 8, 2017 16:19
Create a directory if not exist
var fs = require('fs');
var dir = './tmp';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}