Skip to content

Instantly share code, notes, and snippets.

View jpalala's full-sized avatar
🎯
Focusing

Jose Palala jpalala

🎯
Focusing
View GitHub Profile
@jpalala
jpalala / meetups.json
Created September 11, 2024 06:38
JSON example meetups api from friendsofphp.org
{
"generated_at": "2024-09-11 00:27:52",
"meetups": [
{
"name": "Why you should consider Drupal for your next project",
"user_group_name": "#pugMi: PHP User Group Milano",
"local_date": "2024-09-11",
"local_time": "17:00",
"utc_start_date_time": "1726074000",
"city": "Milano",
@jpalala
jpalala / README.md
Created August 26, 2024 01:47
Docker run jekyll

Setting up a Jekyll environment with Docker can streamline your development process, especially if you're looking to maintain consistency across different environments. Below, I'll guide you through creating a working Jekyll Docker environment using the official Jekyll Docker image.

Step-by-Step Guide

1. Create a Dockerfile

First, create a Dockerfile to define your Jekyll environment. Create a file named Dockerfile in your project directory with the following content:

# Use the official Jekyll image
@jpalala
jpalala / ducks.md
Created August 26, 2024 01:37
du -cks
du -cks * | sort -rn | head -11
alias ducks='while read -r line;do du -sh "$line";done < <(ls -1A) | sort -rh | head -n11'
@jpalala
jpalala / artisan_stuff.sh
Created August 14, 2024 06:21
artisan shortened command
# Add this function to your ~/.zshrc file
art() {
# Define a function with a case statement
case $1 in
"cc")
php artisan config:clear && php artisan config:cache
# Add your code for option 1 here
;;
"oc")
php artisan optimize:clear
@jpalala
jpalala / laravel-api-resources.md
Created August 12, 2024 23:51 — forked from deepak-cotocus/laravel-api-resources.md
How to Create Laravel Eloquent API Resources to convert model collections into JSON(Part 1).

Introduction:

What is API Resources in Laravel

LARAVEL's resource classes allow you to expressively and easily transform your models and model collections into JSON.Basically you can generate a nice json formatted data right from Eloquent. Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON. Let’s learn how to generate api resources.Consider you have a user table in your database and you want to generate api resources for your User model.Run following command on your terminal window while being on laravel project root directory:

STEP 1: Generating Resources

  • Run this Command to generate a resource class.
  • By default, resources will be placed in the app/Http/Resources directory of your application. Resources extend the Illuminate\Http\Resources\Json\JsonResource class:
@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.