Skip to content

Instantly share code, notes, and snippets.

View amrishodiq's full-sized avatar

Amri Shodiq amrishodiq

  • Depok, Jawa Barat, Indonesia
View GitHub Profile
@amrishodiq
amrishodiq / gist:cffcd03a48c5bf9b10edec5d406b2fd4
Created May 9, 2016 03:45
Lazy Load Singleton JavaScript Database
var db = null;
function getDatabase() {
if (db == null) {
db = openDatabase('smartCitizen', '1.0', 'Smart Citizen', 2 * 1024 * 1024);
}
return db;
}
// Try to load 'worship.js' asynchronously, then
$.getScript("worship.js", function( data, textStatus, jqxhr ) {
whenWorshipJsLoaded();
});
function whenWorshipJsLoaded() {
// Todo: Do something after 'worship.js' successfully loaded.
}
@amrishodiq
amrishodiq / distance.java
Last active April 20, 2016 06:42
Solving distance of two cities
double perfectCity(double[] departure, double[] destination) {
double minorVert = 0;
double minorHor = 0;
minorVert = minorDistance(departure[1], destination[1]);
minorHor = minorDistance(departure[0], destination[0]);
return minorVert + minorHor;
}
@amrishodiq
amrishodiq / ECIESExample.java
Created March 27, 2014 23:24
An example of how to use ECIES encryption.
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.ECGenParameterSpec;
import javax.crypto.Cipher;
import org.bouncycastle.jce.spec.IEKeySpec;
import org.bouncycastle.jce.spec.IESParameterSpec;
@amrishodiq
amrishodiq / analogclock.qml
Created November 2, 2012 09:41
QML Analog Clock with ability to rotate clock's hand on action press
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {}
ImageView {
imageSource: "asset:///images/bg-wall-blue.jpg"
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
}
@amrishodiq
amrishodiq / ContohEnkripsi.java
Created September 18, 2012 07:52
This is a simple example of how to use Triple DES with Blackberry java. Please beware that I use '0' as padding (see doPadding()) to make the implementation comply with PHP's mcrypt.
package com.durianberry.contohenkripsi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.rim.device.api.crypto.BlockDecryptor;
import net.rim.device.api.crypto.BlockEncryptor;
import net.rim.device.api.crypto.CryptoTokenException;
import net.rim.device.api.crypto.CryptoUnsupportedOperationException;
@amrishodiq
amrishodiq / BrandApp.java
Created June 21, 2012 08:42
Splash screen implementation for Blackberry Java application
/**
* This is how to use ScreenSplash.java
*/
package com.durianapp.brandapp;
import com.durianapp.brandapp.ui.ScreenSplash;
public class BrandApp extends UiApplication {
public BrandApp() {
@amrishodiq
amrishodiq / Lbs.php
Created April 2, 2012 07:57
PHP Code Igniter library class to get latitude & longitude, get address for specified latitude & longitude, get direction from one place to another place, and so on. Most LBS concept I implemented with PHP.
<?php
/**
* Written by Amri Shodiq.
* Do not hesitate to copy and paste this code.
* It's not embarassing.
*/
if (!defined('BASEPATH'))
exit ('No direct script access allowed');
@amrishodiq
amrishodiq / app.css
Created February 5, 2012 14:48
Simple sencha touch 1.1 snippet to show how to use Panel, Toolbar, List, Model, and Store
.list-item-title
{
float:left;
width:100%;
font-size:90%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.list-item-narrative
@amrishodiq
amrishodiq / CryptoUtilities.cs
Created January 16, 2012 20:11
Triple DES encryption and MD5 for Windows Phone 7 with C#
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;