Skip to content

Instantly share code, notes, and snippets.

View xtrasmal's full-sized avatar
🟢
--- 200 OK

Xander xtrasmal

🟢
--- 200 OK
  • Cyberspace
View GitHub Profile
@xtrasmal
xtrasmal / Countdown.vue
Last active March 20, 2019 08:58
VueJS Flip countdown flip clock using momentjs
<script>
import * as moment from 'moment-timezone'
export default {
props: {
date: {
required: true,
default: moment().format()
},
locale: {
@xtrasmal
xtrasmal / 1.Usage.php
Last active December 11, 2018 16:34
Redis HashTable Open Addressing, probing. Hashing, create an index based on the value of the item that needs to be stored.
<?php
// Add stuff to redis
foreach ($userIds as $uuid) {
$this->indexer->addAtIndex("users", $uuid);
}
// later... retrieve from redis
$userID = "fa5352f9-fa1b-48c9-862d-1cb614cc7ed8";
$user = $this->indexer->getAtIndex("users", $userID);
@xtrasmal
xtrasmal / 1.test.php
Created December 3, 2018 13:10
php hash functions metrics results(see comment at: http://php.net/manual/en/function.hash.php)
<?php
echo "Building data...";
$data = "";
for($i = 0; $i < 1500; $i++)
$data .= sha1("H:k - $i - k:H");
echo "OK! (".strlen($data)." bytes)".PHP_EOL;
$res = [];
@xtrasmal
xtrasmal / cs-fix.sh
Created August 2, 2018 10:51
PHP CS Fixer CLI
#!/bin/bash
PHP=`which php`
$PHP php-cs-fixer fix app --rules='{"@PSR2":true,"array_indentation": true,"array_syntax": {"syntax":"short"},"no_unused_imports": true,"object_operator_without_whitespace": true,"ordered_class_elements": {"sortAlgorithm": "none"},"ordered_imports": {"sortAlgorithm": "length"}}'
<?php
class Repository
{
public function findAll(): array
{
return $this->connection->project(
sprintf('SELECT * FROM %s', self::TABLE_NAME),
[],
function(array $row): Domain\MyObject {
return Domain\MyObject::fromArray($row);
@xtrasmal
xtrasmal / alter_all_tables_collation.mysql
Created June 25, 2018 00:37
Alter all tables collation
SELECT CONCAT("ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ",
"ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ")
AS alter_sql
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mist';
@xtrasmal
xtrasmal / Guarded.php
Created April 2, 2018 01:38
Guarded FormRequest
<?php
/**
* Trait Guarded
* use in a Laravel FormRequest class
*/
trait Guarded
{
/**
* Get all input parameter that are guarded by and
* match the rules array of the form request
@xtrasmal
xtrasmal / user.service.ts
Created October 10, 2017 12:51
Angular user service
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { User } from '../_models/index';
@Injectable()
export class UserService {
constructor(private http: Http) { }
getAll() {
@xtrasmal
xtrasmal / RouteRBAC.php
Created August 27, 2017 21:17
Laravel command to show all routes that do not have a ROLE middleware.
<?php namespace App\Console\Commands;
use Illuminate\Routing\Route;
use Illuminate\Foundation\Console\RouteListCommand;
class RouteRBAC extends RouteListCommand
{
/**
* {@inheritdoc}
@xtrasmal
xtrasmal / RouteTable.php
Created August 25, 2017 10:46
RouteTable command for a nice list of laravel routes.
<?php namespace App\Console\Commands;
use Illuminate\Routing\Route;
use Illuminate\Foundation\Console\RouteListCommand;
class RouteTable extends RouteListCommand
{
/**
* {@inheritdoc}