Skip to content

Instantly share code, notes, and snippets.

Avatar
✔️
Available for Consulting

Dan Alvidrez bayareawebpro

✔️
Available for Consulting
View GitHub Profile
View Multiselect.vue
<template>
<div>
<label id="listbox-label" class="block text-sm font-medium text-gray-700" v-text="label"/>
<input type="hidden" :value="selectedValues" :name="name">
<div class="mt-1 relative">
<button @click="selected = !selected" type="button" aria-haspopup="listbox" aria-expanded="true"
aria-labelledby="listbox-label"
class="bg-white relative w-full border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
<span class="block truncate" v-text="selectedText"/>
View multiselect.vue
<template>
<div>
<label id="listbox-label" class="block text-sm font-medium text-gray-700">
Assigned to
</label>
<input type="hidden" :value="selectedValues" name="name">
<div class="mt-1 relative">
<button @click="selected = !selected" type="button" aria-haspopup="listbox" aria-expanded="true"
aria-labelledby="listbox-label"
class="bg-white relative w-full border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
@elawad
elawad / format-size.js
Last active Mar 4, 2020
Format file size like macOS
View format-size.js
function formatSize(size) {
const base = 1000; // 1000 or 1024
const kb = base ** 1;
const mb = base ** 2;
const gb = base ** 3;
let num;
num = (size / 1).toFixed(0);
if (num < base) return Number(num) + ' B';
@paragonie-scott
paragonie-scott / js-php-encrypt.md
Last active Oct 22, 2019
String Encryption in JavaScript and PHP
View js-php-encrypt.md

Just for fun, let's encrypt some stuff in client-side JavaScript and have a PHP server decrypt it. Note that this will never replace TLS (HTTPS).

JavaScript Encryption with Sodium-Plus

You'll want the latest release of sodium-plus for this. (As of this writing, it's version 0.4.0.)

<script
  src="/static/js/sodium-plus.min.js"
  integrity="sha384-lv7SVE0eb0bXA3fgK6PwlhViiUwG6tBuMAhS8XX7RvBvyRcdEdJ8HKtFgs4vHTUh"
@krakjoe
krakjoe / crawler.php
Last active Dec 2, 2020
parallel Futures, Channels (buffered, unbuffered, synchros), Events using parallel producer/consumer pattern
View crawler.php
<?php
use \parallel\{Runtime, Future, Channel, Events};
/* usage php crawler.php [http://example.com] [workers=8] [limit=500] */
$page = $argv[1] ?: "https://blog.krakjoe.ninja"; # start crawling this page
$workers = $argv[2] ?: 8; # start this number of threads
$limit = $argv[3] ?: 500; # stop at this number of unique pages
$timeout = $argv[4] ?: 3; # socket timeout for producers
@jhm-ciberman
jhm-ciberman / NovaResourcesTest.php
Created Apr 28, 2019
Simple Automatic Test for Laravel Nova Resources
View NovaResourcesTest.php
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Laravel\Nova\Nova;
use Laravel\Nova\Resource;
@tigusigalpa
tigusigalpa / database.php
Last active Oct 26, 2020
Laravel PostgreSQL SSL encryption connection config
View database.php
<?php
/**
* 1. You have to store your client SSL certificates on your Laravel server, in my case this is /var/certs/mydomain.com/...
* 2. You have to right select SSL mode for PostgreSQL (see https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS), verify-full means your server CA is signed for real domain name for the PostgreSQL server (recommended)
* 3. Go to Laravel config/database.php to the section 'pgsql' and extend it to the following:
*/
return [
/*...*/
'connections' => [
/*'mysql' etc*/
@mysiar
mysiar / ideolog-monolog.md
Created Feb 22, 2019
Monolog template for Ideolog
View ideolog-monolog.md
Message pattern: `^\[(.*)\] (.+?)\.([A-Z]+): (.*)`
Message start pattern: `^\[`
Time format: `yyyy-MM-dd HH:mm:ss`
Time capture group: `1`
Severity capture group: `3`
Category capture group: `2`
@connerbw
connerbw / EventEmitter.php
Last active Jan 28, 2021
Refactor Your Slow Form Using PHP Generators and Event Streams
View EventEmitter.php
<?php
/**
* @license GPLv3 (or any later version)
* @see http://kizu514.com/blog/refactor-your-slow-form-using-php-generators-and-event-streams/
*/
namespace KIZU514;
class EventEmitter
{
View larg_tables.sql
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC