Skip to content

Instantly share code, notes, and snippets.

View grim-reapper's full-sized avatar

Imran Ali grim-reapper

View GitHub Profile
@grim-reapper
grim-reapper / flash_messages.php
Created August 11, 2019 05:24 — forked from BaylorRae/flash_messages.php
Flash Messages for PHP
<?php
class FlashMessages {
private $messages = array();
private $now = false;
private static $instance = null;
private function __construct() {
// Save all messages
$this->messages = $_SESSION['flash_messages'];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MediaCapture and Streams API</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
@grim-reapper
grim-reapper / jquery.advanced-plugin.js
Created September 26, 2019 19:06 — forked from cmarkle27/jquery.advanced-plugin.js
Advanced jQuery Plugin
// plug it in, plug it in
(function($) {
var paraCount = function() {
return {
options: {
itemClass: 'awesome',
baseUrl: "/",
@grim-reapper
grim-reapper / copy-element-text-bookmarklet.js
Created October 14, 2019 08:05 — forked from foobear/copy-element-text-bookmarklet.js
JavaScript bookmarklet to click an element and copy its text contents. See https://makandracards.com/makandra/46962
(function() {
var overlay = document.createElement('div');
Object.assign(overlay.style, {
position: 'fixed',
top: 0,
left: 0,
width: '100vw',
height: '100vh',
zIndex: 99999999,
background: 'transparent',
@grim-reapper
grim-reapper / strong-passwords.php
Created October 14, 2019 12:24 — forked from tylerhall/strong-passwords.php
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
<?php
function time2str($ts) {
if(!ctype_digit($ts)) {
$ts = strtotime($ts);
}
$diff = time() - $ts;
if($diff == 0) {
return 'now';
} elseif($diff > 0) {
$day_diff = floor($diff / 86400);
@grim-reapper
grim-reapper / commands.sh
Created October 21, 2019 09:33 — forked from phplaw/commands.sh
All about docker
# List all containers (only IDs)
docker ps -aq
# Stop all running containers
docker stop $(docker ps -aq)
# Remove all containers, maybe we need -f| --force option for force delete running container
docker rm $(docker ps -aq)
# Remove all images
@grim-reapper
grim-reapper / short-number-format.php
Created January 28, 2020 08:01 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@grim-reapper
grim-reapper / swaparrayelements.js
Created April 26, 2020 10:55 — forked from eerohele/swaparrayelements.js
Swap two array elements (JavaScript)
/**
* Swap the elements in an array at indexes x and y.
*
* @param (a) The array.
* @param (x) The index of the first element to swap.
* @param (y) The index of the second element to swap.
* @return {Array} The input array with the elements swapped.
*/
var swapArrayElements = function (a, x, y) {
if (a.length === 1) return a;
@grim-reapper
grim-reapper / SaveQuietly.php
Created May 15, 2020 17:29 — forked from janzikmund/SaveQuietly.php
Laravel eloquent trait to add method for save model without triggering observers
<?php
namespace App\Traits;
/**
* Allows saving models without triggering observers
*/
trait SaveQuietly
{
/**
* Save model without triggering observers on model