Skip to content

Instantly share code, notes, and snippets.

/**
* This is how you intval in PostgreSQL
**/
SELECT cast( coalesce( nullif( column_name_here, 0 ), '0') as integer ) AS column_name_alias_here FROM table_name_here
@abelcallejo
abelcallejo / function_name_here.sql
Created June 27, 2018 02:14
Creating a user-defined PostgreSQL function
CREATE FUNCTION function_name_here(character varying) RETURNS text AS $$
SELECT column_name FROM "TABLE_NAME" GROUP BY "_ORDINAL_NUMBER" ORDER BY "_ORDINAL_NUMBER"; $$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
@abelcallejo
abelcallejo / README.md
Last active January 3, 2020 08:51
Minimalistic git commands

git

Minimalistic git commands

git status

Lists all the modified files only. The number of lines of the output determines the number of files/folders modified.

git status --short --untracked-files=no

Shows the number of modified files

@abelcallejo
abelcallejo / datetime.php
Created August 31, 2018 01:23
Converting an ISO-8601 formatted data into a specific format
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
@abelcallejo
abelcallejo / postgre.sql
Last active August 31, 2018 06:18
Using CASE-WHEN statement in PostgreSQL
/** Minimal example **/
SELECT
CASE
WHEN 1 > 0 THEN 'one is greater than zero'
ELSE 'something else'
END AS "ALIASED_FIELD_NAME_HERE"
/** In table example **/
SELECT
CASE
@abelcallejo
abelcallejo / postgre.sql
Created September 6, 2018 08:05
PostgreSQL function that returns zero for a zero divisor
CREATE FUNCTION safe_divide(numeric, numeric) RETURNS numeric AS $$
SELECT
CASE
WHEN $2 = 0 THEN 0
ELSE $1/$2
END AS quotient; $$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
@abelcallejo
abelcallejo / MARKDOWN.md
Last active May 8, 2019 02:39
This is a great alternative on building web services that display chart/graph images rendered in PNG.

Generating graph/chart using R and PHP

php r

Google Image Charts API is dead! This is a great alternative on building web services that display chart/graph images rendered in PNG.

Files

  • hello.r - generates the graph
  • hello.php - displays the graph
  • rplot.jpg - temporary file output that gets generated by R of which later is read by PHP
@abelcallejo
abelcallejo / CommandLineArguments.py
Last active July 18, 2019 22:43
Crash course on Python
import sys
print(sys.argv[0]) # CommandLineArguments.py
print(sys.argv[1]) # hello
print(sys.argv[2]) # world
#python CommandLineArguments.py hello world
@abelcallejo
abelcallejo / post-receive
Created November 27, 2018 02:35
Git hook post-receive template
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
WORKTREE=/var/www/html/app/
git --work-tree=$WORKTREE checkout -f $branch
echo "Changes were successfully pushed to staging server at location $WORKTREE"
find $WORKTREE -iname "*.php" | xargs chmod 665
find $WORKTREE* -type d | xargs chmod 775
@abelcallejo
abelcallejo / README.md
Last active May 9, 2019 01:12
Sending an SMS message with PHP and Amazon SNS

Sending SMS message using PHP and Amazon SNS

php aws

Instructions

On the command-line, use composer to get the AWS SDK for PHP

composer require aws/aws-sdk-php

Then test it by using the sns.php file