Skip to content

Instantly share code, notes, and snippets.

View ermand's full-sized avatar

Ermand Durro ermand

View GitHub Profile
@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 / 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 / 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 / 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');