Skip to content

Instantly share code, notes, and snippets.

View jpalala's full-sized avatar
🎯
Focusing

Joe Palala jpalala

🎯
Focusing
View GitHub Profile
@jpalala
jpalala / get_monotonic_time.php
Created June 29, 2024 00:18
clock monotonic time
<?php # idea from https://www.netmeister.org/blog/epoch.html
// so Mac apparently set their origin of time using to 2001-01-01 00:00:00 (clock monotonic) which is unix epoch (1971-01-01) aka -30 years ago.
# ((31556926) * 30) = (number of seconds per year according to epochconverter) * 30 years = 946707780
# per article, it is -978307200 (2001-01-01 00:00:00) so I wonder what explains the diff??
functions get_monotonic($timestamp) {
return time() - strtotime('2001-01-01 00:00:00'));
}
return get_monotonic();
@jpalala
jpalala / cron-every-minute.sh
Created June 23, 2024 23:30
starting a artisan cron scheduler
```sh
# Your cron
* * * * * root /usr/bin/php /var/app/current/artisan schedule:run >> /dev/null 2>&1 | logger
```
@jpalala
jpalala / uniqid2.js
Created June 21, 2024 03:08
uniqid2
// from my thinking this is much faster than uuuid as long as you do not same microsecond requests
function uniqId2() {
const hrTime = process.hrtime.bigint();
const microTime = hrTime / BigInt(1000);
const randomComponent = Math.floor(Math.random() * 16).toString(16); // generates a random hexadecimal digit
return microTime.toString(16) + randomComponent;
}
function idToTimestamp(id) {
const idWithoutRandomComponent = id.slice(0, -1); // remove the random component
@jpalala
jpalala / a_practical_approach_for_tech_career_shifter.md
Last active May 13, 2024 03:22
Practical Approach to Shifting to Tech

A practical approach to shifting into a tech career

This is basically a summary of how might one shift into a tech career from a different degree.

  1. PRACTICE! Just like learning any musical instrument, it takes a lot of practice! Practice after work. Practice on weekends. The key is being onsistent.
  2. What to practice?
    • Basic algorithms (for, if else, switch, while, etc..)
  3. It's not just about algorithms, you have to know:
    • How to setup a webserver or your local environment depending on your techstack
  • How to use Git to push to a repository such as Github, Bitbucket or Gitlab.
@jpalala
jpalala / reactsvelteacomparison.md
Created February 29, 2024 09:42
React vs Svelte a comparison

React vs. Svelte: A Comparison

Both React and Svelte are popular JavaScript frameworks used to build user interfaces, but they differ in their approach and have distinct strengths:

React:

  • Strengths:
    • Mature and well-established: With a larger community and extensive ecosystem of libraries and tools, React offers more resources and established practices.
    • Component-based architecture: Enables efficient organization and reusability of UI components.
  • Virtual DOM: Optimizes performance by efficiently updating only the parts of the DOM that have changed.
@jpalala
jpalala / csv.php
Created December 23, 2023 00:31
simple helper
<?php
function csv_write($filename, $data){
$fp = fopen($filename, 'w');
foreach ($data as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
@jpalala
jpalala / zat.js
Created November 15, 2023 01:00
zat
# some utility function to copy changed files to a backup folder
var shell = require('shelljs');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
if (shell.exec("git status porcelain | awk 'print $2' > tempfile").code !== 0) {
shell.echo("check tempfile");
@jpalala
jpalala / setting-up-captcha.md
Created November 1, 2023 10:54
laravel how to captcha

You can add a CAPTCHA to your Laravel application to protect against spam in your contact form by using Google's reCAPTCHA service. Here's a step-by-step guide on how to do this:

  1. Register Your Site with Google reCAPTCHA:

    Visit the Google reCAPTCHA website and sign in with your Google account. Then, register your website or app to get the necessary API keys.

    • Choose "reCAPTCHA v2" and "I'm not a robot" Checkbox.
    • Enter the domains where you want to use reCAPTCHA.
  2. Get Your API Keys:

@jpalala
jpalala / wordpress-linux-azure.sh
Created November 1, 2023 10:44 — forked from mikepfeiffer/wordpress-linux-azure.sh
Build a Standalone Wordpress LAMP Server on Azure
#!/bin/bash
# Tutorial: Install a LAMP stack on an Azure Linux VM
# https://docs.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-lamp-stack
# Create the VM Resource Group
az group create --name LAMP-STACK-RG --location westus2
# Create the VM
az vm create \
@jpalala
jpalala / setup_mac.sh
Created July 26, 2023 05:07 — forked from TheGU/setup_mac.sh
Setup mac (brew,git, zsh with prezto, iterm2 and default app)
#!/bin/bash
# Brew : The missing package manager for macOS
# https://brew.sh/
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Git
brew install git
git config --global core.autocrlf input