Skip to content

Instantly share code, notes, and snippets.

View fernandosavio's full-sized avatar

Fernando Sávio fernandosavio

View GitHub Profile
notas = []
# registra todas as 10 notas
for i in range(1, 11):
nota = float(input("Insira a nota do {}º aluno: ".format(i)))
notas.append(nota)
# calcula a média
media = sum(notas)/len(notas)
def int_to_bin(numero, bit=1, string=''):
str_bit = '1' if bool(numero & bit) else '0'
string = str_bit + string
if bit > numero:
return string
else:
return int_to_bin(numero, bit << 1, string)
@fernandosavio
fernandosavio / convert_coord_to_dms.js
Last active January 15, 2018 20:58
Convert float coordinates to DMS (degree, minutes, seconds). Ex.: convert_coord_to_dms(e.g. 21.305728, -157.859647) -> 21° 18' 20.6208" N, 157° 51' 34.7292" E
function convert_coord_to_dms (lat, lon) {
/*
Se Lat é positivo é Norte, senão Sul
Se Long é positivo é Leste, senão Oeste
*/
var lat_orientation = lat < 0 ? "S" : "N",
lon_orientation = lat < 0 ? "W" : "E";
function get_dms(decimal) {
@fernandosavio
fernandosavio / convert_coord_to_dms.js
Created March 23, 2017 20:48
Convert float coordinates to DMS (degree, minutes, seconds).
function convert_coord_to_dms (lat, lon) {
/*
Se Lat é positivo é Norte, senão Sul
Se Long é positivo é Leste, senão Oeste
*/
var lat_orientation = lat < 0 ? "S" : "N",
lon_orientation = lat < 0 ? "W" : "E";
function get_dms(decimal) {
@fernandosavio
fernandosavio / date_validation.js
Created February 7, 2017 12:55
Validate a date (DD/MM/YYYY).
function valid_date(str_data) {
var regex = /^\d{2}\/\d{2}\/\d{4}$/,
d, m, y;
str_data = str_data.trim();
if (!regex.test(str_data)) {
return false
}
@fernandosavio
fernandosavio / hightlight-gist-line.jquery.js
Last active January 26, 2017 13:29
Line highlighting for embedded Gists.
// jQuery version
$(document).on('click', '.js-line-number', function(event){
var elem = $(this).next('.js-file-line'),
bg_color = elem.css('backgroundColor'),
color_active = 'rgb(248, 238, 199)';
elem.css('backgroundColor', bg_color === color_active ? 'rgba(0, 0, 0, 0)' : color_active);
});
var elem = $(document.location.hash).trigger('click');
@fernandosavio
fernandosavio / unserialize.php
Last active November 26, 2015 18:19 — forked from phred/unserialize.php
Simple reliable and non-regex method to unserialize PHP session data
<?
//
// This is the result of about an hour's delving into PHP's hairy-ass serialization internals.
// PHP provides a session_decode function, however, it's only useful for setting the contents of
// $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its
// session files -- session_decode gets you nowhere.
//
// There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular
// expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse
// through the string extracting all of the serialized bits along the way.
<?php
function teste_unicode_regex($value) {
$min = (preg_match("/\\p{Ll}/u", $value)) ? "Sim" : "Não" ;
$mai = (preg_match("/\\p{Lu}/u", $value)) ? "Sim" : "Não" ;
$num = (preg_match("/\\d/", $value)) ? "Sim" : "Não" ;
echo <<<TEXT
=== $value ===
@fernandosavio
fernandosavio / fibonacci_nth.js
Last active January 13, 2017 03:49
Find the N-th fibonacci number using Binet's Formula.
// http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html
function fibonacci_nth(i){
var v5 = Math.sqrt(5),
Phi = ( v5 + 1 ) / 2,
phi = Phi-1;
return Math.round( Math.pow(Phi, i) / v5 - Math.pow(-phi, i) / v5 );
}
@fernandosavio
fernandosavio / Gabarito Prova C.md
Last active October 21, 2021 20:51
Responde e explicando a prova do site http://www.cprogressivo.net/2013/03/Questoes-com-gabarito-sobre-Ponteiros-em-C.html (O que eu souber, é claro)