Skip to content

Instantly share code, notes, and snippets.

View hengkiardo's full-sized avatar

Hengki Sihombing hengkiardo

  • Jakarta, Indonesia
View GitHub Profile
@hengkiardo
hengkiardo / gist:4023855
Created November 6, 2012 10:13
Create image data URIs (base64) using PHP
// A few settings
$image = 'cricci.jpg';
// Read image path, convert to base64 encoding
$imageData = base64_encode(file_get_contents($image));
// Format the image SRC: data:{mime};base64,{data};
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;
// Echo out a sample image
@hengkiardo
hengkiardo / convert-array.js
Created October 3, 2012 07:33
Convert simple array into two-dimensional array(matrix) in javascript
function listToMatrix(list, elementsPerSubArray) {
var matrix = [], i, k;
for (i = 0, k = -1; i < list.length; i++) {
if (i % elementsPerSubArray === 0) {
k++;
matrix[k] = [];
}
matrix[k].push(list[i]);
}
return matrix;
@hengkiardo
hengkiardo / MY_Log.php
Created November 3, 2012 05:26 — forked from mikedfunk/MY_Log.php
CodeIgniter MY_Log - fix chmod issues
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* fixes chmod issues
*
* @author Mike Funk
* @email mfunk@christianpublishing.com
*
* @file MY_Log.php
*/
@hengkiardo
hengkiardo / express-upload-multer-s3.js
Created March 2, 2022 02:37
Uploading files to Amazon S3 in ExpressJS with Multer
'use strict';
const express = require('express');
const app = express();
const multer = require('multer');
const multerS3 = require('multer-s3');
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: 'access-key-id',
@hengkiardo
hengkiardo / money-format.js
Created September 21, 2012 10:53
JavaScript Money Format
Number.prototype.formatMoney = function(places, symbol, thousand, decimal) {
places = !isNaN(places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : "$";
thousand = thousand || ",";
decimal = decimal || ".";
var number = this,
negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
SELECT
p.id as "Pool Id",
p.status,
p.province_id,
CASE
WHEN province_id = 11 THEN "Aceh"
WHEN province_id = 12 THEN "Sumatera Utara"
WHEN province_id = 13 THEN "Sumatera Barat"
WHEN province_id = 14 THEN "Riau"
WHEN province_id = 15 THEN "Jambi"
@hengkiardo
hengkiardo / jstz.js
Created November 27, 2012 09:02
Automatic Timezone Detection Using JavaScript
var jstz = function() {
var b = function(a) {
a = -a.getTimezoneOffset();
return null !== a ? a : 0
}, c = function() {
return b(new Date(2010, 0, 1, 0, 0, 0, 0))
}, f = function() {
return b(new Date(2010, 5, 1, 0, 0, 0, 0))
}, e = function() {
var a = c(),
@hengkiardo
hengkiardo / url-get
Created April 29, 2013 08:42
Read URL GET variables with Javascript
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
/// http://hengkiardo.com/index.php?id=123&page=home
@hengkiardo
hengkiardo / README.md
Created April 27, 2019 16:24 — forked from magnetikonline/README.md
CloudFormation example for an API Gateway endpoint calling a Lambda function using proxy integration.

CloudFormation example for API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway endpoint:
    • A single root method, accepting POST requests only with Lambda proxy integration to a function.
  • In-line Lambda function echoing back requesting users IP address to API Gateway requests:
    • IAM role for Lambda allowing CloudWatch logs access.
    • Permissions for Lambda that allow API Gateway endpoint to successfully invoke function.
  • CloudWatch logs group for Lambda, with 90 day log retention.

After standing up the template, you should be able to curl a POST request to the URL listed as the apiGatewayInvokeURL output value.