Skip to content

Instantly share code, notes, and snippets.

@lfbittencourt
lfbittencourt / SomeController.php
Created July 12, 2013 20:25
Snippet to disable layouts and/or views in a Zend Framework application.
<?php
// Disable layouts.
$this->_helper->layout->disableLayout();
// Disable view.
$this->_helper->viewRenderer->setNoRender(true);
@lfbittencourt
lfbittencourt / json2csv.php
Created August 24, 2013 18:25
JSON to CSV converter.
<?php
if ($argc < 2) {
echo 'Usage: json2csv.php [input.json] output.csv', PHP_EOL;
exit(1);
}
$input = fopen($argc === 3 ? $argv[1] : 'php://stdin', 'r');
@lfbittencourt
lfbittencourt / WpHostChange.sql
Created September 5, 2013 18:38
Use this query to change a WordPress host hardcoded in options table.
UPDATE
wp_options
SET
option_value = REPLACE(option_value, 'oldhost/somedirectory', 'newhost')
WHERE
option_value LIKE '%oldhost/somedirectory%';
@lfbittencourt
lfbittencourt / SimplePaginator.php
Created April 23, 2014 16:57
SimplePaginator class.
<?php
class SimplePaginator
{
protected $pageCount;
protected $pageRangeLength = 5;
public function __construct($pageCount, $pageRangeLength)
{
@lfbittencourt
lfbittencourt / clear_tags.rb
Last active March 21, 2017 11:03
This Ruby script removes all local and remote tags in a single-line way, so you don't need supply your credentials several times. Optionally, you can remove only tags greater than a specific version.
#!/usr/bin/env ruby
# Only tags >= min_tag will be removed.
min_tag = '0.0.0'
tags = `git tag`.split(/\s+/).select do |t|
Gem::Version.new(t) >= Gem::Version.new(min_tag)
end
`git tag -d #{tags.join ' '}`
`git push origin #{tags.map { |t| ':' + t }.join ' '}`
@lfbittencourt
lfbittencourt / laravel-log-queries.php
Last active December 29, 2016 12:33
How to log queries in Laravel 5
<?php
\DB::enableQueryLog();
$foo = Foo::find(1);
dd(\DB::getQueryLog());
@lfbittencourt
lfbittencourt / mb_ucfirst.php
Last active November 27, 2016 21:04
mb_ucfirst
<?php
function mb_ucfirst($value)
{
return mb_strtoupper(mb_substr($value, 0, 1)) . mb_substr($value, 1);
}
@lfbittencourt
lfbittencourt / redis.sh
Created July 21, 2015 18:35
Install Redis and Redis PHP extension on Ubuntu
# Installs extra packages
sudo apt-get update
sudo apt-get -y install build-essential tcl8.5
# Installs Redis
# http://redis.io/topics/quickstart
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
# https://realguess.net/2014/07/19/non-interactive-redis-install/
PORT=6379
CONFIG_FILE=/etc/redis/6379.conf
@lfbittencourt
lfbittencourt / time-range-clashes.php
Last active July 7, 2016 13:59
Time range clashing scenarios
<?php
// Assumes that the lower and upper bounds are exclusive
$scenarios = [
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB]
['14:00', '15:00', '14:00', '15:00', true],
@lfbittencourt
lfbittencourt / bootstrap4.html
Last active June 21, 2016 02:26
Bootstrap 4 media query test
<div class="hidden-sm-up">XS</div>
<div class="hidden-md-up hidden-xs-down">SM</div>
<div class="hidden-lg-up hidden-sm-down">MD</div>
<div class="hidden-xl-up hidden-md-down">LG</div>
<div class="hidden-lg-down">XL</div>