Skip to content

Instantly share code, notes, and snippets.

@akhawaja
akhawaja / json-map-converter.js
Created February 28, 2019 03:49
JSON-to-Map and Map-to-JSON converter.
/**
* Convert a Map to a JSON object.
*
* @param {Map<any, any>} map - The Map to convert to JSON.
* @returns {Object} The converted JSON object.
*/
const mapToJson = (map) => {
let obj = Object.create(null)
for (let [key, val] of map) {
@akhawaja
akhawaja / pom.xml
Created February 10, 2018 18:13
Use this starter Maven POM file to create a Spring Boot app without Spring Boot as a parent BOM.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amirkhawaja</groupId>
<artifactId>spring-poc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@akhawaja
akhawaja / ByteUtils.java
Created July 8, 2017 20:59
Some utility functions for handling byte conversions.
package com.amirkhawaja;
import java.nio.ByteBuffer;
public final class ByteUtils {
private ByteUtils() {
}
public static long stringToLong(String s) {
@akhawaja
akhawaja / Utilities.java
Last active July 8, 2017 20:58
Utility methods for the Java programming language.
package com.amirkhawaja;
import java.security.SecureRandom;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Utilities() {
private static final SecureRandom random;
@akhawaja
akhawaja / waterfall.js
Last active May 7, 2017 23:02
Process a series of JavaScript functions in the order supplied.
/**
* Process a set of functions in order supplied.
*
* @author Amir Khawaja <[email protected]>
* @param {array} funcs - An array of functions
*/
function waterfall(funcs, done) {
if (funcs !== void 0 && funcs !== null) {
if (typeof funcs !== 'object' && funcs.shift !== void 0) {
throw new Error('Array of functions expected');
@akhawaja
akhawaja / xRequest.js
Created October 24, 2016 15:07
Async Cross-Domain Ajax helper without jQuery and uses Promises.
"use strict";
/**
* Cross-Domain Ajax helper.
* @author Amir Khawaja <[email protected]>
* @license MIT
* @constructor
*/
var XRequest = function () {
var self = this;
@akhawaja
akhawaja / countries_and_us_states.sql
Created October 23, 2016 20:25
PostgreSQL reference table for Countries and US States
-- Reference tables
DROP TABLE IF EXISTS public.ref_country CASCADE;
DROP TABLE IF EXISTS public.ref_us_state CASCADE;
CREATE TABLE public.ref_country (
id SERIAL NOT NULL,
country_code CHAR(2) NOT NULL,
country_name VARCHAR(45) NOT NULL,
currency_code CHAR(3),
fips_code CHAR(2),
@akhawaja
akhawaja / loadScripts.js
Created October 23, 2016 20:23
Load JavaScripts from a URL.
if (!window.loadScripts) {
/**
* Load scripts given an array of URLs.
* @author Amir Khawaja <[email protected]>
* @license MIT
* @param {array} scripts - An array of URLs of scripts.
* @param {function} done - The function to call once the scripts are loaded.
*/
window.loadScripts = function (scripts, done) {
var loader = function (src, handler) {
@akhawaja
akhawaja / cookieManager.js
Created October 23, 2016 20:16
JavaScript Cookie Manager class.
/**
* Cookie manager.
* @author Amir Khawaja <[email protected]>
* @license MIT
* @constructor
*/
var CookieStore = function () {
/**
* Indicate if value is of type integer.
* @param {*} value - The value to test.
@akhawaja
akhawaja / us_states.osql
Created November 25, 2015 02:50
Create US States SQL for OrientDB
CREATE CLASS USState EXTENDS V;
CREATE PROPERTY USState.name string;
CREATE INDEX USState.generalSearch ON USState (name COLLATE ci) FULLTEXT;
CREATE VERTEX USState SET name = "Alabama";
CREATE VERTEX USState SET name = "Alaska";
CREATE VERTEX USState SET name = "Arizona";
CREATE VERTEX USState SET name = "Arkansas";
CREATE VERTEX USState SET name = "California";