Skip to content

Instantly share code, notes, and snippets.

View tzkmx's full-sized avatar
🎉
estrenando repositorios privados

Jesus Franco tzkmx

🎉
estrenando repositorios privados
View GitHub Profile
@tzkmx
tzkmx / pivot_example.php
Created October 16, 2019 11:38 — forked from fractefactos/pivot_example.php
Laravel Custom Pivot Model definition example
<?php
//https://github.com/laravel/framework/issues/2093#issuecomment-39154456
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\Relations\Pivot;
class User extends Eloquent {
public function groups() {
return $this->belongsToMany('Group');
@tzkmx
tzkmx / git-pushing-multiple.rst
Last active October 15, 2019 23:12 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just

@tzkmx
tzkmx / lava.js
Created October 15, 2019 20:54 — forked from jgrahamc/lava.js
Code behind https://jgc.org/lava
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const response = await fetch("https://csprng.xyz/v1/api?length=10")
if (response.status != 200) {
return response
}
@tzkmx
tzkmx / index.php
Created October 15, 2019 20:38 — forked from jgrahamc/index.php
Demonstrating how to use Link headers to make CloudFlare push assets
<?php
function ccbysa($imagehtml, $sourceuri, $owneruri, $ownername) {
return <<<HTML
{$imagehtml}
<br/>
<small><a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>
<a href="{$sourceuri}">image</a> by <a href="{$owneruri}">{$ownername}</a>
<br/>
HTML;
@tzkmx
tzkmx / PushNotifications.php
Created August 27, 2019 18:26 — forked from joashp/PushNotifications.php
Simple PHP script to send Android Push Notification, iOS Push Notification and Windows Phone 8 Push Notification
<?php
// Server file
class PushNotifications {
// (Android)API access key from Google API's Console.
private static $API_ACCESS_KEY = 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI';
// (iOS) Private key's passphrase.
private static $passphrase = 'joashp';
// (Windows Phone 8) The name of our push channel.
private static $channelName = "joashp";
@tzkmx
tzkmx / functional.php
Created August 22, 2019 05:00 — forked from webbower/functional.php
Functional utilities a la PHP
<?php
function pipe(...$fns) {
return function($x) use ($fns) {
return array_reduce(
$fns,
function($acc, $fn) { return $fn($acc); },
$x
);
};
@tzkmx
tzkmx / registry.php
Created July 22, 2019 20:39 — forked from xeoncross/registry.php
A simple singleton registry store inside an function that provides public read/write access to it's datastore
<?php
function o($key = null, $value = null) {
static $registry;
if( ! $key) {
return $registry;
}
@tzkmx
tzkmx / .php_cs.dist
Created July 17, 2019 18:44 — forked from codfish/.php_cs.dist
PHP-CS-Fixer configuration file. PSR-2 plus some opinionated options to make code cleaner.
<?php
/**
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide.
*
* - https://github.com/FriendsOfPHP/PHP-CS-Fixer
* - https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
* - https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/PSR-2-R-coding-style-guide-additions.md
*
* If something isn't addressed in either of those, some other common community rules are
<?php
class Item
{
private $cost = 100;
public function getTotal($discount = 7) {
return $this->cost *(100+$discount)/100;
}
}
@tzkmx
tzkmx / laravel-multiple-env-setup.php
Created June 18, 2019 17:06 — forked from msankhala/laravel-multiple-env-setup.php
Setup Multiple Environment for Laravel 5 Developers Way
<?php
/*
|--------------------------------------------------------------------------
| Follow this instructions:
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.