Skip to content

Instantly share code, notes, and snippets.

View nietzscheson's full-sized avatar

Cristian Angulo nietzscheson

View GitHub Profile
<?php
class VAT
{
private $value;
private $percent;
public function setValue($value)
{
@nietzscheson
nietzscheson / polymorphism.php
Last active July 1, 2016 16:17
Polimorfism example in PHP
<?php
interface IVehiculo
{
public function setName($name);
public function getName();
}
abstract class Vehiculo implements IVehiculo
{
@nietzscheson
nietzscheson / currency_symbols.php
Created July 5, 2016 22:33 — forked from gibbs/currency_symbols.php
An array of currency symbols as HTML entities
<?php
$currency_symbols = array(
'AED' => '&#1583;.&#1573;', // ?
'AFN' => '&#65;&#102;',
'ALL' => '&#76;&#101;&#107;',
'AMD' => '',
'ANG' => '&#402;',
'AOA' => '&#75;&#122;', // ?
'ARS' => '&#36;',
'AUD' => '&#36;',
@nietzscheson
nietzscheson / README.md
Created July 13, 2016 21:51 — forked from tjamps/README.md
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@nietzscheson
nietzscheson / Template Render
Last active July 15, 2016 21:29
[#Symfony] - MessengerFlash
{% for flashMessage in app.session.flashbag.get('type') %}
<div class="alert alert-{{ app.session.flashbag.get('type') }} alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>{{ flashMessage }}</strong>
</div>
{% endfor %}
@nietzscheson
nietzscheson / services.yml
Created July 20, 2016 17:38
Base Manager service
services:
base_manager:
class: ArtesanIO\ModelManagerBundle\Model\Manager.php
abstract: true
calls:
- [setEntityManager, ["@doctrine.orm.entity_manager"]]
- [setEventDispatcher, ["@event_dispatcher"]]
other_manager:
class: ArtesanIO\ModelManagerBundle\Model\OtherManager.php
@nietzscheson
nietzscheson / bs3-login-form.html
Created August 6, 2016 19:18 — forked from bMinaise/bs3-login-form.html
Bootstrap 3 - Login Form Example From: http://bootsnipp.com
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<h1 class="text-center login-title">Sign in to continue to Bootsnipp</h1>
<div class="account-wall">
<img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
alt="">
<form class="form-signin">
<input type="text" class="form-control" placeholder="Email" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<?php
class Logger
{
protected $file;
public function __construct($file) { $this->file = $file; }
public function log($message)
{
$message = date('H:i:s ') . $message . PHP_EOL;
@nietzscheson
nietzscheson / http_status_codes.php
Created July 5, 2016 22:34 — forked from gibbs/http_status_codes.php
HTTP status codes array
<?php
$code = array();
$code['0'] = 'Connection Failed. Please configure Varnish to accept HTTP purge requests.';
$code['100'] = 'Continue';
$code['101'] = 'Switching Protocols';
$code['102'] = 'Processing';
$code['200'] = 'OK';
$code['201'] = 'Created';
$code['202'] = 'Accepted';
@nietzscheson
nietzscheson / README.md
Created August 31, 2016 14:17 — forked from joyrexus/README.md
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing