Skip to content

Instantly share code, notes, and snippets.

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

Xander xtrasmal

🟢
--- 200 OK
View GitHub Profile
@xtrasmal
xtrasmal / CreateDateDimensionTable.php
Created September 1, 2023 13:59
// Store dates and time into separate database tables and reference them // whenever you need to add a time or date field // Easy lookups
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Artisan;
class CreateDateDimensionTable extends Migration
{
/**
{
"preset": "laravel",
"rules": {
"array_indentation": true,
"array_syntax": true,
"assign_null_coalescing_to_coalesce_equal": true,
"binary_operator_spaces": true,
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": true,
"blank_line_before_statement": true,
@xtrasmal
xtrasmal / Chromium Mobile Device List
Created March 6, 2020 20:54 — forked from devinmancuso/Chromium Mobile Device List
Mobile Device Emulation List from Chromium
#Pulled from Chromium at: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/devtools/front_end/toolbox/OverridesUI.js&q=WebInspector.OverridesUI._phones%20file:OverridesUI.js&sq=package:chromium&type=cs&l=310
#Phones
Define_phones = [
{deviceName: "Apple iPhone 3GS", width: 320, height: 480, deviceScaleFactor: 1, userAgent: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", touch: true, mobile: true},
{deviceName: "Apple iPhone 4", width: 320, height: 480, deviceScaleFactor: 2, userAgent: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", touch: true, mobile: true},
{deviceName: "Apple iPhone 5", width: 320, height: 568, deviceScaleFactor: 2, userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Versi
@xtrasmal
xtrasmal / AppLayout.js
Created April 13, 2019 21:23 — forked from unr/AppLayout.js
Bare Minimum Laravel Echo in Nuxt.JS example.
// In my global app layout, once my app is mounted and ready to listen...
import { mapActions, mapGetters } from 'vuex';
const Layout = {
mounted() {
// set up pusher listeners
this.connectToPublicChannel();
this.$watch('authenticated', (auth) => {
if (auth) this.connectToUserChannel();
@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';