Skip to content

Instantly share code, notes, and snippets.

@waelio
waelio / pwa.ts
Created June 20, 2021 17:00
Push Notifications
/* eslint-disable import/no-duplicates */
/* eslint-disable no-console */
const publicVapidKey = import.meta.env.VITE_VID_PUBLIC
const isClient = (): boolean => Boolean(typeof window !== 'undefined' && 'serviceWorker' in navigator)
const unSubscribe = async() => {
if (isClient) {
const reg = await navigator.serviceWorker.register('worker.js', { scope: '/' })
const subscription = await reg.pushManager.getSubscription()
@waelio
waelio / images.class.js
Created June 1, 2021 20:30
Get Image content from aws s3 bucket. **very expensive: cpu/ram/response time**
/* eslint-disable no-unused-vars */
const AWS = require('aws-sdk');
const client = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
apiVersion: '2006-03-01',
});
exports.Images = class Images {
constructor(options, app) {
this.options = options || {};
@waelio
waelio / magic-maker.js
Created March 24, 2021 22:44
Generate REST Vue - Vuex model
const { snakeToCamel, camelToSnake } = require ("waelio-utils");
function regModule (mod ) {
if(!mod) return null
const modelName = mod.name
const UPPER = modelName.toUpperCase()
const SNAKE = camelToSnake(modelName)
const UPPER_SNAKE = SNAKE.toUpperCase()
const CAMEL = modelName.charAt(0).toUpperCase() + modelName.slice(1)
const isNameSpaced = mod.namespaced || false
try {
@waelio
waelio / Entity.php
Last active August 13, 2021 08:31
autonymous object
<?php
/**
* Created by PhpStorm.
* User: wahbehw
* Date: 2/1/2016
* Time: 9:26 AM
*/
//namespace entity_object;
@waelio
waelio / clean_wp.php
Last active December 29, 2015 13:06
Remove unreal images from wp
<?php
$imgs = get_posts("post_type=attachment&numberposts=-1");
$x=0;
foreach($imgs as $img){
$file = get_attached_file($img->ID);
$Image_size = getimagesize($file);
if(!is_array($Image_size)){
wp_delete_post( $img->ID, false );
echo $x .'- Deleting attachment #'.$img->ID;
@waelio
waelio / Limit_string.php
Last active December 29, 2015 13:10
limiting string length by number of charachters while preserving whole words
<?php
/**
* replace array Values (string) with length values
* @param array $string
*/
function get_string_length(&$string){
if ((is_string($string)) || (is_integer($string)))
$string = strlen($string);
}
@waelio
waelio / Random_Password.php
Last active December 29, 2015 13:11
Random Password from predefined dictionary
<?php
function generate_password($length = 64){
$box_array = array( 'jhg','RTJ','ZCG','{;G','KRA','!','@','$','%','^','&','*','(',')','_','=','+' );
$password='';
for($x=0; $x < $length; $x++){
$password .= $box_array[intval(array_rand($box_array))];
}
@waelio
waelio / HTML_Tables_from_MySQL_Database.php
Last active December 29, 2015 13:12
Create HTML Table (header/body/footer) from MySQL Database using PDO
<?php
function getConnection1(){
$dbhost = "localhost";
$dbuser = "test";
$dbpass = "test";
$dbname = "schema name";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
@waelio
waelio / get_avatar_link.php
Last active December 29, 2015 13:12
Get the HREF(src) on an <img />
@waelio
waelio / Class_Element.php
Last active December 29, 2015 13:13
PHP - Create html elements
<?php
/**
* Create an element
*/
class Element
{
private $type;
private $unaryTagArray = array('area','base','br','col','command','embed','hr','img','input','keygen','link','meta','param','source','track','wbr');
private $attributes;
private $innerHtml;