Skip to content

Instantly share code, notes, and snippets.

View pedro-vasconcelos's full-sized avatar
💭
Coding...

Pedro Vasconcelos pedro-vasconcelos

💭
Coding...
View GitHub Profile
@pedro-vasconcelos
pedro-vasconcelos / gist:9102823
Created February 19, 2014 22:15
Testar o swiftmail
<?php
require_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.host.com', 25, 'tls')
->setUsername('')
->setPassword('');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Informação')
@pedro-vasconcelos
pedro-vasconcelos / gist:9179546
Last active August 29, 2015 13:56
PHP md5 hash trick
This md5("test\n") is diferent this one md5('test\n')
md5("test\n") = 'd8e8fca2dc0f896fd7cb4cb0031ba249'
md5('test\n') = 'e55a2a99dcc719bb178a5e6daf3d4f98'
Single quoted - strings will display things almost completely "as is." Variables and most escape sequences will not be interpreted. The exception is that to display a literal single quote, you can escape it with a back slash \', and to display a back slash, you can escape it with another backslash \\ (So yes, even single quoted strings are parsed).
Double quote - strings will display a host of escaped characters (including some regexes), and variables in the strings will be evaluated. An important point here is that you can use curly braces to isolate the name of the variable you want evaluated. For example let's say you have the variable $type and you what to echo "The $types are" That will look for the variable $types. To get around this use echo "The {$type}s are" You can put the left brace before or after the dollar sign. Take a look at string parsi
@pedro-vasconcelos
pedro-vasconcelos / gist:9187511
Last active August 29, 2015 13:56
Migrate users from MD5 Hash system to Laravel without ask the users to change the password
<?php
// Try to log the user in.
if (Auth::attempt($userdata))
{
// Redirect to homepage
return Redirect::to('')->with('success', 'You have logged in successfully');
}
else
{
$user = User::where('username','=',$userdata['username'])->first();
#! /bin/bash
# Run this as sudo!
# I move this file to /usr/local/bin/vhost and run command 'vhost' from anywhere, using sudo.
#
# Show Usage, Output to STDERR
#
function show_usage {
cat <<- _EOF_
[alias]
#Basic
st = status -sb
co = checkout
#Flow
fs = flow feature start
ff = flow feature finish
#Infoz
@pedro-vasconcelos
pedro-vasconcelos / gist:93dc77a89287ee848406
Created August 23, 2014 14:35
Debug XCode PHPStorm CLI
php -dxdebug.remote_enable=1 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_port=9000 -dxdebug.remote_mode=req script.php
@pedro-vasconcelos
pedro-vasconcelos / shortcut-1
Created August 21, 2012 09:30
Test if a variable exists
winners[buyer] ||= [] is a shortcut to:
winners[buyer] = winners[buyer] || [] is a shortcut to:
Set winners[buyer] equal to winners[buyer] or, if winners[buyer] is nil, set it to [].
You’re just making sure a variable is set before using it.
@pedro-vasconcelos
pedro-vasconcelos / abstract-factory-pattern-1.rb
Created December 8, 2012 19:07
Abstract Factory Pattern
class Report
def output
formatter_class =
begin
@format.to_s.classify.constantize
rescue NameError
# ...handle 'invalid formatter type'
end
formatter = formatter_class.send(:new, self)
# etc
@pedro-vasconcelos
pedro-vasconcelos / gist:5325812
Created April 6, 2013 11:34
Get data from EZ Publish content tree
$attributeFilter = array( array( 'user/sync_time', '=', '' ),
// array( 'user/guid', '=', '' ),
//array( 'user/user_settings/is_enabled', '=', 1 ),
array( 'modified', '>', $last_modified)
);
$params = array(
/*
<?php
use \eZ\Publish\API\Repository\Values\Content\Query;
$locationService = $this->getRepository()->getLocationService();
$searchService = $this->getRepository()->getSearchService();
$urlAliasService = $this->getRepository()->getUrlAliasService();
$typeService = $this->getRepository()->getContentTypeService();
$identifiers = array( 'folder', 'page', 'contact' );
$ids = array();