Skip to content

Instantly share code, notes, and snippets.

View jardelsantana's full-sized avatar

Jardel Santana jardelsantana

View GitHub Profile
@marasergio
marasergio / HibernateUtil.java
Created November 9, 2011 18:39
HibernateUtil - Configuração
package configuracao;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
/**
*
* @author Mara
*/
public class HibernateUtil {
@jonatanfroes
jonatanfroes / gist:1935123
Created February 28, 2012 21:06
Buscar CEP CodeIgniter
//helper cep
if ( ! function_exists('buscar_endereco'))
{
function buscar_endereco($cep)
{
$cep = str_replace('.', '', $cep);
$cep = str_replace('-', '', $cep);
$url = 'http://republicavirtual.com.br/web_cep.php?cep='.urlencode($cep).'&formato=query_string';
@revolunet
revolunet / geolocate.php
Created April 26, 2012 11:19
sql based geolocation query
#
# geolocate points 50km around a defined latitude/longitude
#
$latitude = 42.45679;
$longitude = 8.345678;
$sql = "SELECT ID, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . $latitude . " - LAT) * 0.0174532925 / 2), 2) + ";
$sql .= "COS(" . $latitude . " * 0.0174532925) * COS(LAT * 0.0174532925) * POWER(SIN((" . $longitude . " - LON) * 0.0174532925 / 2), 2) ";
$sql .= ")) as DISTANCE from houses having DISTANCE < 50 ORDER BY DISTANCE ASC ";
@azrulharis
azrulharis / Validate.php
Created August 6, 2012 17:24
Php validation using array and display error on each form fields
<?php
class Validate {
public $message = array();
public $validate;
public function rules($data) {
foreach($data as $key => $value) {
@clnmcgrw
clnmcgrw / gist:9086505
Last active November 25, 2021 11:16
Google Maps API Geocode Example - PHP/JSON
<?php
// address to map
$map_address = "";
$url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=".urlencode($map_address);
$lat_long = get_object_vars(json_decode(file_get_contents($url)));
// pick out what we need (lat,lng)
$lat_long = $lat_long['results'][0]->geometry->location->lat . "," . $lat_long['results'][0]->geometry->location->lng;
@kaspereden
kaspereden / geoFinder.js
Last active July 29, 2022 05:28
Store geolocation in cookie
/*
In order to store the object we 'flatten' the object. This has strange results in the latest version of Safari (8)
*/
navigator.geolocation.getCurrentPosition(function (geolocation) {
// in order to store the location in a cookie we 'flatten' the object to json
var cookieValue = JSON.stringify(geolocation);
});
@chrislavender
chrislavender / gist:cad26500c9655627544f
Last active April 19, 2024 15:28
HTTP Live Streaming Tutorial

Note: This is an older post that I did back when I thought I might have time to be a blogger. Oh I was oh so wrong. However, it has proven useful for some folks on stackoverflow. Thus I'm keeping it alive here on Gist.

One of my past projects dealt heavily with an open source Apple technology called HTTP Live Streaming. It’s an HTTP based streaming protocol that at its most fundamental level provides a way to stream video and audio from just about any server with nothing but a few free software tools provided by Apple**. However, it has a few additional features that I think make it a really exciting tool. Yet, I haven’t seen HTTP Live Streaming used very much. This is probably mainly due to the combination of a lack of good/clear documentation, and Apple’s Live Streaming Developer Tools being command line based also make the barrier to entry higher than many developers want to deal with.

The hope is to share my understanding of how to use this technology to:

@boliveirasilva
boliveirasilva / phoneValidate_BR.php
Created October 14, 2015 16:11
Regex para validação de telefones (celular ou fixo) no Brasil. A expressão leva em conta o formato internacional/nacional, com ou sem o DDD, de telefones fixos e celulares.
<?php
// A função abaixo demonstra o uso de uma expressão regular que identifica, de forma simples, telefones válidos no Brasil.
// Nenhum DDD iniciado por 0 é aceito, e nenhum número de telefone pode iniciar com 0 ou 1.
// Exemplos válidos: +55 (11) 98888-8888 / 9999-9999 / 21 98888-8888 / 5511988888888
function phoneValidate($phone)
{
$regex = '/^(?:(?:\+|00)?(55)\s?)?(?:\(?([1-9][0-9])\)?\s?)?(?:((?:9\d|[2-9])\d{3})\-?(\d{4}))$/';
if (preg_match($regex, $phone) == false) {
@rafaelstz
rafaelstz / get.js
Last active October 6, 2023 14:35
AJAX GET and POST with pure Javascript
// Exemplo de requisição GET
var ajax = new XMLHttpRequest();
// Seta tipo de requisição e URL com os parâmetros
ajax.open("GET", "minha-url-api.com/?name=Henry&lastname=Ford", true);
// Envia a requisição
ajax.send();
// Cria um evento para receber o retorno.
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active July 25, 2024 19:20
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32: