Skip to content

Instantly share code, notes, and snippets.

View tincho's full-sized avatar

Martin tincho

View GitHub Profile
@sobi3ch
sobi3ch / gist:5451004
Last active October 24, 2017 17:10
PHP Array pluck function
<?php
/**
* Pluck an array of values from an array. (Only for PHP 5.3+)
*
* @param $array - data
* @param $key - value you want to pluck from array
*
* @return plucked array only with key data
*/
function array_pluck($array, $key) {
swPrecache.write(path.resolve(__dirname, `../public/service-worker.js`), {
cacheId: `know-it-all`,
filename: `service-worker.js`,
stripPrefix: `public/`,
staticFileGlobs: [
`public/app.*.js`, // don't include the polyfills version
`public/*.{html,ico,json,png}`,
],
dontCacheBustUrlsMatching: [
/\.(js|json)$/, // I'm cache busting js and json files myself
@chronon
chronon / xps-13.md
Created September 3, 2018 22:19
Dell XPS 13 9370 Dual Boot Win 10 and Debian Linux

Dell XPS 13 9370 Dual Boot Win 10 and Debian Linux

Windows Preparation and Setup

  1. Download Win 10 installation ISO and create a bootable USB drive.
  2. Boot, F12 for system menu, select BIOS Setup.
    • System Configuration -> SATA Operation and change from "RAID On" to "AHCI".
    • Secure Boot -> Secure Boot Enable and change to "Disabled"
  3. Reboot, F12 for system menu, select the external USB drive and install Win 10.
@magicznyleszek
magicznyleszek / javascript-vs-jquery.md
Last active November 30, 2021 17:50
Vanilla JavaScript

Vanilla JavaScript

Some vanilla equivalents to jQuery methods.

DOM selectors

jQuery:

@efouts
efouts / elevatorSaga.js
Last active June 3, 2022 02:57
Passes All Challenges (some take a number of tries)
{
init: function(elevators, floors) {
elevators.forEach(function(e) {
e.isDestination = function(floorNum) {
return e.destinationQueue.indexOf(floorNum) != -1;
}
e.on("floor_button_pressed", function(floorNum) {
if (!e.isDestination(floorNum))
e.goToFloor(floorNum);
@tincho
tincho / date-utils.js
Last active July 13, 2022 04:17
some utils for JS Date handling
/*
why fixDate?
if we create a JS Date writing:
var d = new Date("2015-05-15")
we are not specifying any timezone
the browser/environment will asume it is UTC+000,
and always represent it in user's LOCAL TIMEZONE!
so, running in an environment located in a UTC-3 zone,
d would actually show 2015-05-14 at 21:00
and may lead to errors.
@CharlyJazz
CharlyJazz / XMLHttpRequest.js
Last active May 17, 2023 08:13
XMLHttpRequest injection load javascript script.
//Before </body> tag
<script>
var xhr = new XMLHttpRequest();
xhr.open("get", "cookbook.js", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = xhr.responseText;
@getify
getify / 1-CalendarItem.js
Last active March 21, 2024 09:11
an illustration (non-trivial example) of many newer JS class features
// abstract class, not intended to be instantiated directly
class CalendarItem {
static #UNSET = Symbol("unset")
static #isUnset(v) {
return v === this.#UNSET;
}
static {
for (let [idx,msg] of [
"ID is already set.",
"ID is unset.",
@addyosmani
addyosmani / headless.md
Last active May 17, 2024 03:38
So, you want to run Chrome headless.

Update May 2017

Eric Bidelman has documented some of the common workflows possible with headless Chrome over in https://developers.google.com/web/updates/2017/04/headless-chrome.

Update

If you're looking at this in 2016 and beyond, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

Windows and Mac users might find using Justin Ribeiro's Docker setup useful here while full support for these platforms is being worked out.

@Mon4ik
Mon4ik / useLocalStorage.ts
Last active May 26, 2024 06:23
Typescript useLocalStorage hook
/* `useLocalStorage`
*
* Features:
* - JSON Serializing
* - Also value will be updated everywhere, when value updated (via `storage` event)
*/
import { useEffect, useState } from "react";
export default function useLocalStorage<T>(key: string, defaultValue: T): [T, (value: T) => void] {