Skip to content

Instantly share code, notes, and snippets.

View LukeberryPi's full-sized avatar

LukeberryPi LukeberryPi

View GitHub Profile
@LukeberryPi
LukeberryPi / index.js
Created March 9, 2024 22:01
enable copy and past on any website
javascript:(function(){
allowCopyAndPaste = function(e){
e.stopImmediatePropagation();
return true;
};
document.addEventListener('copy', allowCopyAndPaste, true);
document.addEventListener('paste', allowCopyAndPaste, true);
document.addEventListener('onpaste', allowCopyAndPaste, true);
})();
@LukeberryPi
LukeberryPi / utils.js
Last active March 5, 2024 01:32
isMobile utils
export const isTouchable = () => {
const userAgent = window.navigator.userAgent;
return (
!!userAgent && userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i)
);
};
export const isIphone = () => {
return (
!!navigator.platform &&
@LukeberryPi
LukeberryPi / settings.json
Last active March 4, 2024 20:50
my zed settings
// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
"features": {
@LukeberryPi
LukeberryPi / settings.json
Created March 3, 2024 06:37
vscode-settings
{
"files.autoSave": "onFocusChange",
"editor.formatOnSave": true,
"workbench.colorTheme": "Gruvbox Dark Medium",
"workbench.iconTheme": "gruvbox-material-icon-theme",
"editor.fontSize": 16,
"terminal.integrated.fontSize": 16,
"explorer.confirmDragAndDrop": false,
"editor.minimap.enabled": false,
"breadcrumbs.enabled": false,
@LukeberryPi
LukeberryPi / solution.js
Last active April 15, 2024 10:50
Do not access Object.prototype method 'hasOwnProperty' from target object. It is a 'no-prototype-builtins' error.
// if you have a javascript object and want to check if it has a key (property)
const obj = {
"a": 1,
"b": 2,
"c": 3,
}
// checking directly from the object might piss off ESLint
obj.hasOwnProperty("c"); // 'no-prototype-builtins' error.
@LukeberryPi
LukeberryPi / areAdjacent.js
Last active December 19, 2023 01:04
function that returns if two coordinates are adjacent in javascript
function areAdjacent(coord1, coord2) {
const [x1, y1] = coord1;
const [x2, y2] = coord2;
const isHorizontallyAdjacent = Math.abs(x1 - x2) === 1 && y1 === y2;
const isVerticallyAdjacent = x1 === x2 && Math.abs(y1 - y2) === 1;
const isDiagonallyAdjacent =
Math.abs(x1 - x2) === 1 && Math.abs(y1 - y2) === 1;
return isHorizontallyAdjacent || isVerticallyAdjacent || isDiagonallyAdjacent;
@LukeberryPi
LukeberryPi / shuffle.js
Created November 26, 2023 18:41
fisher-yates/knuth shuffle in javascript
function shuffle(arr) {
for (let i = 0; i < arr.length - 1; i++) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
@LukeberryPi
LukeberryPi / setup.md
Created November 23, 2023 22:04
get borderless arc
@LukeberryPi
LukeberryPi / loops.js
Last active November 21, 2023 21:16
comparing loops in javascript
function benchmark(testName, callback) {
const startTime = performance.now();
callback();
const endTime = performance.now();
console.log(testName, `time: ${endTime - startTime}`);
}
const nums = Array(1000).fill(1);
function iterateWithMap(nums) {
@LukeberryPi
LukeberryPi / benchmark.js
Created November 20, 2023 16:19
benchmark function for comparing performances in javascript
function benchmark(testName, callback) {
const startTime = performance.now();
callback();
const endTime = performance.now();
console.log(testName, `time: ${endTime - startTime}`);
}
// usage
function addNums(a, b) {