Skip to content

Instantly share code, notes, and snippets.

View isu3ru's full-sized avatar

Isuru Ranawaka isu3ru

  • Sri Lanka
  • 14:55 (UTC +05:30)
View GitHub Profile
/**
* Creates a Javascript Object with gender and date of birth
* - extracted from a given valid Sri Lanka N.I.C. Number
* [email protected]
*/
function parseNIC(nic) {
var nicdata = {
gender: '',
dob: ''
};
@isu3ru
isu3ru / bootstrap_model
Created January 13, 2015 03:25
Bootstrap Modal Window
<style>
body {
background: white;
font-size: 13px;
overflow: hidden;
}
#notifcation_overlay {
position: absolute;
left: 0px;
top: 0px;
@isu3ru
isu3ru / gradle-settings
Last active January 28, 2017 16:03
gradle offline and parallel setting
org.gradle.daemon=true
org.gradle.parallel=true
@isu3ru
isu3ru / jasper-selected-printer.java
Created February 26, 2017 19:21
A java method to prompt a printer selection and send jasper report print to the selected printer.
private void PrintReportToPrinter(JasperPrint jp) throws Exception {
PrintService[] lps = PrintServiceLookup.lookupPrintServices(null, null);
PrintService srv = (PrintService) JOptionPane.showInputDialog(this, "Select printer", "Printer", JOptionPane.PLAIN_MESSAGE, null, lps, lps[0]);
PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintService(srv);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new Copies(1));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
@isu3ru
isu3ru / slugify.js
Created May 29, 2017 06:09 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@isu3ru
isu3ru / phperrreporting.txt
Created September 6, 2017 16:33
Error reporting control in PHP
if (defined('DEVELOPMENT') && DEVELOPMENT === true)
{
ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set("display_errors", 1);
}
<?php
function base_url() {
$isSecure = false;
if (isset($_SERVER['HTTPS'])) {
$isSecure = $_SERVER['HTTPS'] == 'on';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';
<?php
function p($key, $num = FALSE)
{
$var = filter_input(INPUT_POST, $key);
if ($var) {
if (is_array($var)) {
return $var;
}
if (!is_numeric($var) && $num && empty($var)) {
return intval(0);
@isu3ru
isu3ru / reloadUrlWithParams.php
Created September 24, 2017 12:59
Reload current url with some parameters
<?php
function reloadUrlWithParams($anchor = false, $params = false)
{
$temparr = array();
if ($params && is_array($params)) {
foreach ($params as $k => $v) {
$temparr[] = urlencode($k) . "=" . urlencode($v);
}
}
<?php
function setFlashDataItem($key, $value)
{
if (!array_key_exists('flashdata', $_SESSION)) {
$_SESSION["flashdata"] = array();
}
$_SESSION["flashdata"][$key] = $value;
}