Skip to content

Instantly share code, notes, and snippets.

View GuDiasOliveira's full-sized avatar

Gustavo Dias GuDiasOliveira

View GitHub Profile
@GuDiasOliveira
GuDiasOliveira / NumberPickerPreference.java
Created February 22, 2019 16:09
Android Number Picker Preference
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.preference.Preference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
@GuDiasOliveira
GuDiasOliveira / random.hpp
Last active September 25, 2018 16:21
Simple C++ code of float random functions
/**
* Generate a random number between 0 and 1, including 0 and excluding 1.
*/
double frandom()
{
static bool init = false;
if (!init)
{
// This will be done just once
srand(time(NULL));
@GuDiasOliveira
GuDiasOliveira / pdo-dbquery-csv-client.html
Created July 18, 2018 16:39
A piece of code that does a query in a database with PDO, then return the result set in CSV format. There also is an HTML form that calls the PHP code with MySQL database.
<form action="pdo-dbquery-csv.php">
<input type="hidden" name="dblib" value="mysql" />
User: <input type="text" name="user" /><br />
Password: <input type="password" name="password" /><br />
<br />
Host: <input type="text" name="host" /><br />
Database: <input type="dbname" name="dbname" /><br />
<br />
<b>Query: </b><textarea name="q"></textarea><br />
<b>Query params:</b><br />
@GuDiasOliveira
GuDiasOliveira / colored-text.cpp
Created June 21, 2018 13:24
This is an example of a C++ program that simply prints a colored text.
#include <iostream>
using namespace std;
int main(int argC, char** argv)
{
cout << "\033[102;93;4;1;3mBrasil\033[0m e \033[97;106mArgentina\033[0m" << endl;
return 0;
}
<?php
// Request login
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My restrict area"');
header('HTTP/1.0 401 Unauthorized');
// Echoes a message if user cancel the login
echo '<p style="font-weight:bold; color:red">You don\'t have permission to access this page without authentication!</p>';
die;
}
@GuDiasOliveira
GuDiasOliveira / simple-bash-webserver.sh
Created June 13, 2018 14:53
This is an example of a simple Web HTTP Server written in a simple shell script and running on port 8081. Run "./simple-bash-webserver.sh" on terminal to start the service and access http://localhost:8081 on you web browser
while true
do
(
echo 'HTTP/1.1 200 OK'
echo 'content-type: text/html; charset=utf-8'
echo
echo "Current Directory: <b>$(pwd)</b>"
echo '<br />'
echo '<p style="color: blue">Hello, <b>World</b>!!!</p>'
) | nc -l 8081 -q 0
@GuDiasOliveira
GuDiasOliveira / progress-print-lines.sh
Created May 29, 2018 11:09
An example of "progress bar" that prints each line of command "ls -l" in a progress-bar-like line each second.
echo Start
ls -l | while read line
do
# Execute these commands for each line read from command 'ls -l'
echo -en "\r\033[2KProgress: $line"
sleep 1
done
echo