Skip to content

Instantly share code, notes, and snippets.

View helios-ag's full-sized avatar
🐈
On the internet nobody knows you're a cat

Al Ganiev helios-ag

🐈
On the internet nobody knows you're a cat
View GitHub Profile
@cletusw
cletusw / .eslintrc
Last active February 29, 2024 20:24
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@lologhi
lologhi / 1.How to easily implement a REST API with oAuth2 presentation.md
Last active April 4, 2024 22:13
Symfony2 : How to easily implement a REST API with oAuth2 (for normal guys)

It's still a work in progress...

Intro

As William Durand was recently explaining in his SOS, he "didn't see any other interesting blog post about REST with Symfony recently unfortunately". After spending some long hours to implement an API strongly secured with oAuth, I thought it was time for me to purpose my simple explanation of how to do it.

Ok, you know the bundles

You might have already seen some good explanation of how to easily create a REST API with Symfony2. There are famous really good bundles a.k.a. :

<?php
namespace Elnur\Listener;
use DateTime;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\DiExtraBundle\Annotation\Observe;
@jmather
jmather / SSLManagementListener.php
Created November 9, 2012 21:22
Redirect to SSL only on given
<?php
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
class SSLManagementListener
{
private $domain;
@jmather
jmather / deploy.rb
Created August 30, 2012 05:51
Remove dev only files in production via capifony
set :dev_only_files, [web_path + "/app_dev.php", web_path + "/check.php", web_path + "/config.php"]
set :production, true
after 'symfony:cache:warmup', 'pff:productify'
namespace :pff do
desc "Remove app_dev.php, check.php and config.php from production deployment"
task :productify, :except => { :production => false } do
if dev_only_files
pretty_print "--> Removing app_dev.php, config.php, and check.php from web"
@nikic
nikic / guestbook.markdown
Created July 29, 2012 14:21
Quick doesn't have to mean dirty: Also applies to PHP!

Quick doesn't have to mean dirty: Also applies to PHP!

This is just a quick response to http://me.veekun.com/blog/2012/07/28/quick-doesnt-mean-dirty/. I won't bother to write a proper blog post for this, so a Gist will have to do ;)

When I read that article, one thing really striked me: If you want to quickly create a web app in PHP, you do exactly the same. I mean, exactly.

I never used the Silex microframework before, so I took this as a chance to see how it works. I'll just do the same as eevee did, only with a bit less commentary (this is a Gist after all!)

I hope that this will show you that PHP and Python are really similar to work with. Also this should show that just because you're using PHP, doesn't mean that you write dirty code. The similarity in the process and code is really incredible :)

@pitch-gist
pitch-gist / gist:2999707
Created June 26, 2012 22:21
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
<?php
$filter->add('editor', 'doctrine_orm_callback', array(
'field_type'=> 'text',
'callback' => function($queryBuilder, $alias, $field, $value) {
$val = $value['value'];
if(!$value || strlen($val) <= 0){
return;
@merk
merk / blocks.html.twig
Created November 12, 2011 09:48
A way to deal with collections
{% block address_form %}
{% spaceless %}
<div class="address">
<a href="#" class="remove_item btn danger right">Remove</a>
{{ form_row(address.unitNumber, { "label": "Unit Number" }) }}
{{ form_row(address.streetNumber, { "label": "Street Number" }) }}
{{ form_row(address.street, { "label": "Street" }) }}
{{ form_row(address.city, { "label": "City" }) }}
{{ form_row(address.postcode, { "label": "Postcode" }) }}
@Ocramius
Ocramius / User.php
Created October 23, 2011 14:22
Doctrine 2 @onetomany @manytoone example
<?php
namespace HelloWorld;
use InvalidArgumentException;
/**
* This class is somewhere in your library
* @Entity
* @Table(name="users")
*/