Skip to content

Instantly share code, notes, and snippets.

View andresgcarmona's full-sized avatar
🎯
Focusing

Andrés G. Carmona andresgcarmona

🎯
Focusing
View GitHub Profile
@andresgcarmona
andresgcarmona / canvas.js
Last active December 30, 2022 18:52
HTML5 Game Development Canvas
const setup = function() {
var body = document.getElementById('body');
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
body.appendChild(canvas);
@andresgcarmona
andresgcarmona / timezone.js
Created December 28, 2022 19:50
Get user's timezone in Javascript
Intl.DateTimeFormat().resolvedOptions().timeZone
@andresgcarmona
andresgcarmona / index.blade.php
Last active February 17, 2023 00:39
App view blade template
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Page description" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#242424">
<!-- Allow installing the app to the homescreen -->
@andresgcarmona
andresgcarmona / watchMedia.js
Created October 29, 2022 14:43
Watch media changes
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change',({ matches }) => {
if (matches) {
console.log("change to dark mode!")
} else {
console.log("change to light mode!")
}
})
@andresgcarmona
andresgcarmona / useWindowSize.js
Created October 24, 2022 15:05
React hook that returns the window size
unction useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: undefined,
height: undefined,
});
useEffect(() => {
// only execute all the code below in client side
if (typeof window !== 'undefined') {
// Handler to call on window resize
@andresgcarmona
andresgcarmona / duplicateIds.js
Last active October 19, 2022 20:38
Bookmarlets
// find duplicate Id's in DOM
const allElements = document.getElementsByTagName("*");
const allIds = {};
let found = false;
for (let i = 0, n = allElements.length; i < n; ++i) {
const id = allElements[i].id;
if (id) {
if (allIds[id] === undefined) {
@andresgcarmona
andresgcarmona / showHeaders.js
Created October 19, 2022 20:05
Show page headers.
// showheaders.js
// https://github.com/bgrins/devtools-snippets
// Print out response headers for current URL.
(function() {
var request=new XMLHttpRequest();
request.open('HEAD',window.location,true);
request.onload = request.onerror = function () {
@andresgcarmona
andresgcarmona / mandelbrot.coffee
Created October 13, 2022 11:21
Mandelbrot coffee
m=(x,y)->
a=x
b=y
z=0
for i in [0..99]
(return if i>60 then '*' else if i>10 then '-' else if i>5 then '.' else ' ') if z>4
l=y*y
z=x*x+l
y=2*x*y+b
x=x*x-l+a
<template id="html5ElementTemplate">
<style>
.outerDiv {
border:0.1em solid blue;
display:inline-block;
padding: 0.4em;
}
.devText {
font-weight: bold;
@andresgcarmona
andresgcarmona / mandelbrot.c
Created October 9, 2022 14:39
Mandelbrot in C
int main(int argc, char** argv)
{
int k = 2;
float i,j,r,x,y=-16;
while (puts(""), y++<15)
for (x=0; x++<84; putchar(" .:-;!/>)|&IH%*#"[k&15]))
for (i=k=r=0;
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;
r=j);
return 0;