Skip to content

Instantly share code, notes, and snippets.

@matula
matula / psql-truncate.php
Created July 13, 2014 03:48
Truncate Table in Laravel for a table with foreign keys.
<?php
if (DB::getName() == 'pgsql') {
DB::statement('TRUNCATE users CASCADE');
DB::statement('ALTER SEQUENCE users_id_seq RESTART WITH 1');
}
@matula
matula / dev.md
Last active August 29, 2015 13:59
Things a "full stack" developer needs to know

##Things a "full stack" developer needs to know...

  • Backend Languages/ Scripting - specializing in (at least) one, but knowledgable of others: PHP, Python, Ruby, Java, Go, Perl. Bonus points for Erlang, C, C++
  • Unix Shell/Terminal/Console - sh, bash, zsh
  • Frontend Languages/ Scripting - HTML5, CSS3, Javascript
  • Frameworks - the most popular for each language: Symfony, Zend, Laravel, Django, Flask, Pylons, Rails, Sinatra, Play, Grails, Revel, Node, Angular, Backbone
  • Frontend Frameworks - Bootstrap, LESS, SASS
  • IDEs/Code Editors - PHPStorm, Sublime, Eclipse, NetBeans, xCode, Vim
  • OSes - OSX, Linux (Ubuntu 12+, CentOS, Arch), Unix, bonus points for Windows
  • Servers - Apache, Nginx
  • Databases - relational: MySQL, PostgreSQL, SQLite ... non-relational: Mongo, Couch, Cassandra, Redis
@matula
matula / sd.php
Last active August 29, 2015 13:57
Helper function to var_dump either Eloquent models or a regular object/array
<?php
function sd($obj) {
if ($obj instanceof Illuminate\Database\Eloquent\Collection) {
var_dump(json_decode((string)$obj, true));
} else {
var_dump((array)$obj);
}
}
<?php
$final_notification = [];
foreach ($admin_notification as $an) {
if (!empty($an)) {
$final_notification[] = $an;
}
}
@matula
matula / array.php
Created January 7, 2014 19:59
loop through an array
<?php
$social_data = [
[
'first' => 'John',
'middle' => 'Smith',
'last' => 'Doe',
'email' => '[email protected]'
],
[
@matula
matula / routes.php
Created November 27, 2013 23:01
I was trying to have URLs like "http://example.com/myusername" and "http://example.com/myusername/about". Using Laravel, you're able to throw a wildcard in the prefix. The route needs to go at the end of the routes.php file if you have other static routes. #laravel
<?php
// Routes for usernames
Route::group(['prefix' => '{username}', 'before' => 'valid-user'], function()
{
Route::get('/', 'UserController@index');
Route::get('about', 'UserController@about');
});
// Check to make sure the user is valid
Route::filter('valid-user', function($route, $request)
@matula
matula / parseGithub.php
Created November 25, 2013 21:42
Sir Trevor JS block to pull in GitHub data
<?php
public function parseGithub()
{
// Get the URI segments. Example: http://github.com/github/repo
$url = explode('/', trim(parse_url($_GET['url'], PHP_URL_PATH), '/'));
// Add segments to API endpoint. The 1st segment is the user, the second the repo
$api_url = 'https://api.github.com/repos/' . $url[0] . '/' . $url[1];
// Curl to get the json
@matula
matula / soundcloud.js
Created November 23, 2013 01:48
Custom Sir Trevor JS block for embedding Soundcloud
/**
* Block for a Soundcloud link
*/
SirTrevor.Blocks.Soundcloud = (function(){
return SirTrevor.Block.extend({
type: 'Soundcloud',
title: 'Soundcloud',
@matula
matula / main.blade.php
Created November 21, 2013 22:58
Adding in the Sir Trevor JS library into a PHP project using Laravel.
<!-- Not the FULL view -->
<link rel="stylesheet" href="{{ url('css/sir-trevor-icons.css')}}" type="text/css">
<link rel="stylesheet" href="{{ url('css/sir-trevor.css')}}" type="text/css">
<!-- Using some Bootstrap here -->
<div class="container">
<div class="row" id="post-form-container">
<h3>Create A Post</h3>
<form method="post" action="form" id="post-form" role="form">
<div class="form-group">