Skip to content

Instantly share code, notes, and snippets.

View hewerthomn's full-sized avatar
👨‍💻
Coding...

Éverton Inocêncio hewerthomn

👨‍💻
Coding...
View GitHub Profile
/*
* This decorates Handlebars.js with the ability to load
* templates from an external source, with light caching.
*
* To render a template, pass a closure that will receive the
* template as a function parameter, eg,
* T.render('templateName', function(t) {
* $('#somediv').html( t() );
* });
* Source: https://github.com/wycats/handlebars.js/issues/82
@hewerthomn
hewerthomn / Resource.class.php
Created May 8, 2012 10:34
Arquivo de exemplo de classe abstrata Resource
<?php
abstract class Resource
{
protected static $httpMethods = array("GET", "POST", "HEAD",
"PUT", "OPTIONS", "DELETE", "TRACE", "CONNECT");
protected $params;
public function __construct(array $params) {
$this->params = $params;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
@hewerthomn
hewerthomn / DuinoClient.ino
Last active December 16, 2015 11:38
Arduino com Ethernet Shield WizNet W5100 que acessa uma página na Internet e escreve os valores obtidos num display LCD de 16x2.
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
* ----------------------------------------------------------------------------
*/
/*
* DuinoClient
@hewerthomn
hewerthomn / routes.php
Created April 28, 2013 15:55
exemplo de routing do cakephp
// adicionar no arquivo routes.php
Router::connect('/noticia/:id/:title',
array('controller' => 'posts', 'action' => 'view'),
array('pass' => array('id'), 'title' => '[a-z0-9-#]+','id' => '[0-9]+')
);
@hewerthomn
hewerthomn / acl.php
Created May 9, 2013 20:24
exemplo de arquivo app/Config/acl.php
/**
* The role map defines how to resolve the user record from your application
* to the roles you defined in the roles configuration.
*/
$config['map'] = array(
'Pessoa' => 'Pessoa/cpf', // username login field
'Perfil' => 'Pessoa/perfil_id', // user role field
);
/**
@hewerthomn
hewerthomn / AppController.php
Created May 9, 2013 20:28
exemplo de chamada do plugin Acl + Auth
<?php
/**
* arquivo AppController.php
*/
public $components = array(
/* outros componentes chamados aqui */
'Acl',
'Auth' => array(
'authError' => 'O usuário não tem permissão para acessar essa ação',
$latlng = "-8.769926868691913 -63.88429307573199";
$radius = 5000;
$places = Place::where(DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({latlng})'))"), '<', $radius)
->select('offers.*', DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({$latlng})')) AS distance"))
->get();
@hewerthomn
hewerthomn / offers.php
Created February 21, 2016 13:58
Filter places by coordinates radius
<?php
$latlng = "-8.769926868691913 -63.88429307573199";
$radius = 5000;
$places = Place::where(DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({latlng})'))"), '<', $radius)
->select('offers.*', DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({$latlng})')) AS distance"))
->get();
@hewerthomn
hewerthomn / Model.php
Created January 16, 2017 20:11
Laravel Eloquent selectList
<?php
/*...*/
public function selectList()
{
$list = $this->select('name', 'id')
->orderBy('name')
->pluck('name', 'id');