Skip to content

Instantly share code, notes, and snippets.

View ermand's full-sized avatar

Ermand Durro ermand

View GitHub Profile
@ermand
ermand / get_previus_next_record.php
Created April 25, 2013 07:02
Get Previus Next Record in Laravel
<?php
// Get the current user that will be the origin of our operations
$currentUser = User::find(10);
// Get ID of a User whose autoincremented ID is less than the current user, but because some entries might have been deleted we need to get the max available ID of all entries whose ID is less than current user's
$previousUserID = User::where('id', '<', $currentUser->id)->max('id');
// Same for the next user's id as previous user's but in the other direction
$nextUserID = User::where('id', '>', $currentUser->id)->min('id');
@ermand
ermand / laravel - Bootstrap 3 Table Macro.php
Created March 17, 2014 15:45
This macro creates a simple table with edit, view and delete actions.
HTML::macro('table', function($fields = array(), $table_fields = array(), $data = array(), $resource, $status = true, $showEdit = true, $showDelete = true, $showView = true)
{
$table = '<table id="sample-table-2" class="table table-striped table-bordered table-hover well datatables">';
$table .='<thead>';
$table .='<tr>';
foreach ($table_fields as $table_field)
{
$table .= '<th>' . Str::title($table_field) . '</th>';
}
@ermand
ermand / laravel - action buttons in a table.php
Created March 17, 2014 16:08
This macro creates a simple actions with edit, view, deactivate and activate actions.
HTML::macro('actions', function($data, $resource, $showEdit = true, $showDelete = true, $showView = true)
{
$table = '<td class="td-actions center">';
$table .= '<div class="hidden-phone visible-desktop action-buttons bigger-110">';
if ($showEdit)
{
$table .= '<a class="green" href="' . $resource . '/' . $data->id . '/edit" data-toggle="tooltip" data-original-title="Fshi"> <i class="icon-pencil bigger-130"></i> </a>';
}
if ($showView)
{
@ermand
ermand / convertXML2JSON.js
Last active August 29, 2015 14:00
Convert XML to JSON with JavaScript
/*
The JavaScript
It's important to point out that Titanium's Titanium.XML.DOMDocument object implements DOM2-level structures. Here's the magic XML to JSON code:
*/
// Changes XML to JSON
function xmlToJson(xml) {
// Create the return object
var obj = {};
@ermand
ermand / Vagrantfile
Created June 22, 2014 09:57
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "base"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
@ermand
ermand / install_ wkhtmltopdf.sh
Last active August 29, 2015 14:06
Installing wkhtmltopdf on Ubuntu Server 12.04
### Install guide
sudo apt-get update
sudo apt-get install wkhtmltopdf
sudo apt-get install xvfb
echo 'xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
wkhtmltopdf http://www.google.com output.pdf
########################################################
@ermand
ermand / aliases.sh
Last active June 7, 2017 12:57
Some useful cli aliases
# Common
alias ..="cd .."
alias ...="cd ../.."
alias h='cd ~'
alias c='clear'
alias ll='ls -lahG'
# Test
alias codecept='vendor/bin/codecept'
alias crf='codecept run functional'
@ermand
ermand / sublimetext3_packages
Created October 15, 2014 21:48
Sublime Text 3 List of Packages
{
"installed_packages":
[
"AdvancedNewFile",
"Alignment",
"All Autocomplete",
"AutoFileName",
"Autoprefixer",
"Blade Snippets",
"BracketHighlighter",
@ermand
ermand / UserSettings
Created October 15, 2014 21:49
Sublime Text 3 User Settings
{
"bold_folder_labels": true,
"caret_style": "phase",
"color_scheme": "Packages/User/base16-eighties.dark (SL).tmTheme",
"default_line_ending": "unix",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"fallback_encoding": "UTF-8",
"folder_exclude_patterns":
[
@ermand
ermand / functions.php
Created October 20, 2014 20:57
Gets the HTTP status code for the given URL
<?php
/**
* Gets the HTTP status code for the given URL.
*
* @param string $url The URL to check.
* @return int
*/
function url_http_status($url) {
$ch = curl_init($url);