Skip to content

Instantly share code, notes, and snippets.

@jsolid
jsolid / CommonInvoiceQuery.class.php
Last active December 15, 2015 20:09
Add a "Show All" link as search criteria in Invoices module
<?php
public function status($status, $is = true)
{
// $status = 99 to show all result, ignore filtering
if($status !== null && $status != "" && (int)$status < 10)
{
$status = (array) $status;
$statusString = implode(", ", (array) $status);
if($is)
@jsolid
jsolid / MY_url_helper.php
Last active December 14, 2015 23:29
How to cache/refresh static resources (server and client side)
<?php
/**
* Auto-versioning. Append last modified datetime to filename, .htaccess needs to have the corresponding rule
* Similar function, same name in javascript, common.js
* E.g. "assets/css/style.css" converts to "assets/css/style.1363054031.css"
* @param $url String Relative path
* @return String Modified relative path
*/
if ( ! function_exists('site_ver_url')) {
@jsolid
jsolid / .htaccess
Last active December 14, 2015 21:18
How to cache/refresh static resources (server side)
# Default cache values
ExpiresActive ON
ExpiresByType text/html "access plus 1 minute"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType application/x-javascript "access plus 7 days"
ExpiresByType application/javascript "access plus 7 days"
ExpiresByType application/x-shockwave-flash "access plus 7 days"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
@jsolid
jsolid / rowexpDT.js
Last active December 12, 2015 10:39
YUI2 DataTable Row Expansion on certain rows
// HTML page
// <h2>Customer Summary</h2>
// <div>
// <button id="esLastHour">Last Hour</button>&nbsp;
// <button id="esDaily">24 Hours</button>&nbsp;
// <button id="esWeekly">1 Week</button>&nbsp;
// <button id="esMonthly">4 Weeks</button>
// </div>
// <div id="errorSummaryDT" class="dataTable"></div>
@jsolid
jsolid / Common_Twig_Extension.php
Last active December 11, 2015 16:58
Siwapp: Printing template should return a number with precision specified by the user, don't truncate zeros
// File location: siwapp/lib/templating/Common_Twig_Extension.php
function common_twig_extension_round($amount, $decimals = 2)
{
//return round($amount, $decimals);
return number_format(round($amount, $decimals), $decimals, '.', '');
}
@jsolid
jsolid / _invoiceRow.php
Last active December 11, 2015 16:49
Siwapp: Show product description as well in AutoComplete drop-down, instead of showing only the ambiguous product reference code. Width is adjusted to accommodate long description string. If it's more than 40 characters, truncate it and append '...'
// File location: siwapp/apps/siwapp/modules/common/templates/_invoiceRow.php
//connect the selection of a product to update the row item
$('#".$invoiceItemForm['product_autocomplete']->renderId()."')
.autocomplete('".$urlAjaxSelectProduct."', jQuery.extend({}, {
dataType: 'json',
parse: function(data) {
var parsed = [];
for (key in data) {
parsed[parsed.length] = {
@jsolid
jsolid / my-invoice-template.html
Last active July 25, 2017 14:05
Custom invoice template for Siwapp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang="{{lang}}" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Invoice</title>
<style type="text/css">
@page { margin:0.5cm 0.5cm 0.8cm 1.5cm; }
body { margin:0.8cm auto;font:1em;}
div { display:block; }
table { border-collapse:collapse; border-spacing:0; width:99%;}
@jsolid
jsolid / actions.class.php
Last active December 11, 2015 09:59
A simple hack to setup database without password
/**
* Step #4: Database
* The validator of this form checks database connection
* and creates the database if it doesn\'t exists
* See lib/validator/dbConnectionValidator.class.php
* File location: siwapp/apps/installer/modules/static/actions/actions.class.php
*
* @param $request
*/
public function executeStep4(sfWebRequest $request)
@jsolid
jsolid / badge.php
Created October 26, 2012 04:43
PHP - Achievement event trigger
class Badge {
public function __construct() {
// Define all the achievements
Events::register('badges', array($this, 'badgeCommentator'));
Events::register('badges', array($this, 'badgeContributor'));
}
public function badgeCommentator($comment = '') {
if (!empty($comment) && strlen($comment) > 5) {
return 'Achievement: Badass Commentator';
@jsolid
jsolid / MyMailMessage.cpp
Last active May 23, 2020 03:55
POCO library: Calling from .cpp
/**
* @name EmailInbound (Mail Message Handler for POCO)
* @description Receive and sort emails
*/
#include "MyMailMessage.h"
/**
* POCO::Net::MailMessage
*/