Skip to content

Instantly share code, notes, and snippets.

View calexandrepcjr's full-sized avatar
🎯
Focusing

Carlos Alexandre calexandrepcjr

🎯
Focusing
View GitHub Profile
@calexandrepcjr
calexandrepcjr / postgres_queries_and_commands.sql
Last active June 1, 2017 10:55 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@calexandrepcjr
calexandrepcjr / baseUrl.js
Created May 19, 2017 20:18
A different way to work urls into ajax calls
this.pathname = window.location.pathname.split('/');
//Normally in the dev environment the project will be inside a path into htdocs dir
if (window.location.host == 'localhost'){
this.subDirs = this.pathname.length - 3;
} else {
this.subDirs = this.pathname.length - 2;
}
this.baseUrl = '../';
this.baseUrl = this.baseUrl.repeat(this.subDirs);
self.path = this.baseUrl + 'path or source that you want';
@calexandrepcjr
calexandrepcjr / String_helper.php
Last active May 25, 2017 13:00
A helper to play with Strings, in the future maybe I improve into a library class or better stuff
<?php
/* Function to take all ocurrences between two characters in a string */
$string = '
@if(topLevel)
{{
<form method="post">
@if(mediumLevel)
{{
<input>
@calexandrepcjr
calexandrepcjr / Array_helper.php
Last active May 25, 2017 13:00
A helper to play with arrays
<?php
/*EXAMPLE
$array = array(
0 => array (
0 => 35,
1 => 30,
2 => 39
),
1 => array (
0 => 20,
@calexandrepcjr
calexandrepcjr / Date_helper.php
Created May 31, 2017 12:35
A helper to play with Dates
/*
$dateStart = "2016/12/14";
$dateFin = "2017/04/21"
[2016/12/14 - 2016/12/31] => 17 days
[2017/01/01 - 2017/01/31] => 31 days
[2017/02/01 - 2017/02/28] => 28 days
[2017/03/01 - 2017/03/30] => 31 days
[2017/04/01 - 2017/04/21] => 21 days
*/
@calexandrepcjr
calexandrepcjr / SQL_helper.php
Created June 2, 2017 12:11
A helper to play with SQL queries
<?php
//Good to use in PHP pure reports, can send some GET params and automatically filter query with them
function addWhere()
{
if (isset($_REQUEST) && count($_REQUEST) > 0){
$where = ' WHERE ';
foreach ($_REQUEST as $column => $value) {
if (is_numeric($value)){
$where .= " $column = $value ";
} else {
@calexandrepcjr
calexandrepcjr / noscript.html
Created June 8, 2017 18:02
The simplest way to validate if javascript's browser is enabled. Put into the head of your page.
<noscript>
<style type="text/css">
body {
display: none;
}
html:after {
text-align: center;
display: block;
font-size: 5rem;
@calexandrepcjr
calexandrepcjr / Object_helper.php
Created June 20, 2017 15:08
A helper to play with objects
<?php
function obj_multi_unique($obj, $key = false)
{
$totalObjs = count($obj);
if (is_array($obj) && $totalObjs > 0 && is_object($obj[0]) && ($key && !is_numeric($key))) {
for ($i = 0; $i < $totalObjs; $i++) {
if (isset($obj[$i])) {
for ($j = $i + 1; $j < $totalObjs; $j++) {
if (isset($obj[$j]) && $obj[$i]->{$key} === $obj[$j]->{$key}) {
unset($obj[$j]);
@calexandrepcjr
calexandrepcjr / stars.js
Created June 30, 2017 20:58
A piece of code to help to change class in an row of elements like survey stars
/*
Code to add stars in a satisfaction survey, using font-awesome to change the look of the stars
HTML structure below:
<label class='fa fa-user-md'>
<span>Overall Satisfaction</span>
<span>
<label class="fa fa-star-o">
<input type="radio" name="satisfaction" value='0'>
</label>
@calexandrepcjr
calexandrepcjr / MY_Controller.php
Created July 25, 2017 11:01
Quick idea of blocking external access with PHP
<?php
class MY_Controller
{
private function ipVersion($ip)
{
return strpos($ip, ':') === false ? 4 : 6;
}
public function isLocal()
{