Skip to content

Instantly share code, notes, and snippets.

View manuelhe's full-sized avatar
🏕️
6 years quarantined

Manuel Herrera manuelhe

🏕️
6 years quarantined
View GitHub Profile
<?php
class SleepImmersion
{
protected $sheeps = 0;
protected $timestamp = 0;
protected $userStatus = FALSE;
public function __construct(){
$this->timestamp = time();
$this->isUserAsleep();
}
@manuelhe
manuelhe / Tools.php
Created May 2, 2013 19:32
URL-safe strings encryption/decryption
<?php
class Tools{
/**
* URL safe string encryption method
*
* @param string $string
* @param string $key
* @return string Returns an url safe encrypted string
* @throws \InvalidArgumentException
*/
private setExpiresAt() {
const endDate = this.event.endDate * 1000;
const now = Date.now();
const expirationLimit = 72; // time in hours
// Event already expired
this.expiresAt = this.translate.instant('expired_event');
console.log(now - endDate);
if (now - endDate <= 47 * 3600 * 1000) {
// If the event ended {{expirationLimit}} or less ago
const expDays = (expirationLimit / 24) - Math.ceil((now - endDate) / (24 * 3600000));
@manuelhe
manuelhe / spa-routing.js
Created March 9, 2021 23:06
Ultra Slim SPA Router 2021 by @_developit
// Based on source: https://twitter.com/_developit/status/1369397356098097154/photo/1
// links listener
addEventListener('click', e => {
let a = e.target;
// Loop avoids having to jump to `http://event.target.parentNode`
// when the target is a Text or other non-Element node.
// It's also a bit faster than closest() and supports IE11.
while (a.localName !== 'a' && (a = a.parentNode));
if (a && a.origin == location.origin && !a.target) {
@manuelhe
manuelhe / number_base_transform.js
Created April 5, 2021 20:49
Numbers base transformation in JavaScript
// Numeric base transformations in JavaScript
@manuelhe
manuelhe / web-dev-ideas-tools.md
Last active August 3, 2022 14:17
Ideas, tools and technical documents for Web Development
@manuelhe
manuelhe / randomparagraphgen.js
Created March 12, 2023 17:56
Random paragraph generator
const words = [
[
'bird',
'clock',
'boy',
'plastic',
'duck',
'teacher',
'old lady',
'professor',
@manuelhe
manuelhe / downloadFile.ts
Created March 30, 2023 00:30
Helper function for Download file from memory
function downloadFile(content: BlobPart, mimeType: string, filename: string) {
const a = document.createElement('a'); // Create "a" element
const blob = new Blob([content], { type: mimeType }); // Create a blob (file-like object)
const url = URL.createObjectURL(blob); // Create an object URL from blob
a.setAttribute('href', url); // Set "a" element link
a.setAttribute('download', filename); // Set download filename
a.click(); // Start downloading
}