Skip to content

Instantly share code, notes, and snippets.

View guiassemany's full-sized avatar
:octocat:
Always creating something new

Guilherme Assemany guiassemany

:octocat:
Always creating something new
View GitHub Profile
@guiassemany
guiassemany / exemplo.html
Created June 5, 2018 23:23
CDN Fallback
<html>
<head>
<!-- Bootstrap CSS CDN -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
</head>
<body>
<!-- APP CONTENT -->
<!-- jQuery CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
@guiassemany
guiassemany / query.sql
Created August 23, 2017 22:55
SQL Key Value to Row
SELECT
l.status,
l.date_created,
ca1.value AS Email,
ca2.value AS Name,
ca3.value AS Phone
FROM tablename l
LEFT JOIN lead_data AS ca1 ON l.id = ca1.id_lead AND ca1.key='email'
LEFT JOIN lead_data AS ca2 ON l.id = ca2.id_lead AND ca2.key='name'
LEFT JOIN lead_data AS ca3 ON l.id = ca3.id_lead AND ca3.key='phone'
@guiassemany
guiassemany / laravel-relations.md
Created December 28, 2016 12:11
Laravel model relations

One-to-one relationship:

You, as a User, can have one (hasOne) Profile. And of course the inverse also applies. Profile (belongsTo) a User. A user can't have more than one profile and a profile can't belong to multiple users.

One-to-many relationship:

You as a User, can have many (hasMany) Task(s). The inverse would be Task(s) (belongsTo) a User. So that means that a user can have/create many tasks, but each task only belongs to one user.

Many-to-many relationship:

You as a User can belong to many (belongsToMany) (i.e. forum) Group(s). The inverse would be that a Group can also belong to many (belongsToMany) User(s). That means that a user can join as many groups as he wants, and of course a single group can have unlimited users inside.

One other thing that is pretty good to know is that when you use belongsTo and belongsToMany you're telling Laravel that this table holds the foreign key that connects it to the other table.

@guiassemany
guiassemany / binding.php
Created December 28, 2016 12:07
Pass constructor parameters when you're binding an interface to a class
<?php
$this->app->bind('MasterUploader', function($app) use($your_parameter)
{
// Make dependencies ... $any_dependancy_instance = $app->make('AnyDependancy'); etc...
return new EloquentUploader($any_dependancy_instance, $your_parameter);
});
@guiassemany
guiassemany / sortArrayKeys.php
Created November 29, 2016 18:38
Sort array keys based on another array.
<?php
$unsorted = [
['d'=> 'teste', 'c' => 'teste2', 'e' => 'teste3'],
['d'=> 'teste', 'c' => 'teste2', 'e' => 'teste3'],
['d'=> 'teste', 'e' => 'teste3', 'c' => 'teste2', 'f' => 'valor']
];
$keys = ['c','e','d', 'f'];
@guiassemany
guiassemany / index.html
Created January 6, 2016 18:44
Calculate Distance Between two points on a map
<!DOCTYPE html>
<html>
<head>
<title>Calculate Distance Between two points on a map</title>
</head>
<body>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript">
var p1 = new google.maps.LatLng(-12.928646, -38.509659);
var p2 = new google.maps.LatLng(-12.929426, -38.517798);
@guiassemany
guiassemany / git-discard-all-and-pull.md
Created December 20, 2015 19:17
GIT - Discard all local changes and pull

git discard all local changes/commits and pull from upstream

  • git reset --hard origin/master
  • git pull origin master
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant