Skip to content

Instantly share code, notes, and snippets.

View jongacnik's full-sized avatar

Jon jongacnik

View GitHub Profile

Digital Ocean - New LAMP Instance To-Dos

  • Make a droplet using LAMP Instance

  • Add a new user (i.e. deployer)

    adduser deployer
    
  • Add the new user to sudo group

var striptags = require('striptags')
function smartExcerpt (string) {
var re = /(^.*?[a-zA-Z0-9\)\”\"]{2,}[.!?])[\s\”\"]+\W*[A-Z]/
var matches = striptags(string).match(re)
return matches && matches[1] ? matches[1] : string
}
@jongacnik
jongacnik / elebyclass.php
Last active March 23, 2023 16:16
Get element by classname #php @classnic
<?php
function getElementByClassname ($html, $classname) {
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$nodes = $xpath->query('//div[@class="' . $classname . '"]');
$tmp_dom = new DOMDocument();
@jongacnik
jongacnik / FadeInImage.js
Created August 26, 2022 23:08
Next/Image Fade In
import { useState } from "react";
import Image from "next/image";
export default function FadeInImage({ ...props }) {
const [isLoaded, setIsLoaded] = useState(false);
const { className, src, alt, priority, layout, objectFit, width, height } =
props;
function onLoadingComplete() {
setIsLoaded(true);
@jongacnik
jongacnik / router.php
Last active August 7, 2022 16:10
Built-in PHP server router
<?php
/**
* Built-in PHP server router:
*
* - If file exists, serve file
* - Access php files without .php extension
* - Unknown routes throw 404
* - Optionally fallback to index.php
*
@jongacnik
jongacnik / state.js
Created October 24, 2021 18:12
Querystate w/ history
import querystate from 'querystate'
import nanobus from 'nanobus'
const state = querystate()
const bus = nanobus()
// emit state on history change
;(function(history){
var pushState = history.pushState
var popState = history.popState
@jongacnik
jongacnik / Ultralazy.js
Created December 30, 2020 05:49
Ultralazy: Lazy load wicked component
import { define } from 'wicked-elements'
import onIntersect from '../lib/on-intersect.js'
define('[data-component~="ultralazy"]', {
init () {
this.state = {}
this.onEnter = this.onEnter.bind(this)
this.onLoad = this.onLoad.bind(this)
},
connected () {
import { define } from 'wicked-elements'
define('[data-component~="overscroll-none"]', {
init () {
},
connected () {
if (!CSS.supports('overscroll-behavior', 'none')) {
this.wheelingTimeout = false
this.lock = this.lock.bind(this)
@jongacnik
jongacnik / simple-dom.js
Created August 18, 2020 05:31
simple dom, jquery esque
const $ = (selector, parent = document) => parent.querySelector(selector)
const $$ = (selector, parent = document) => [...parent.querySelectorAll(selector)]
const createNode = html => {
return new DOMParser().parseFromString(html, 'text/html').body.firstChild
}
@jongacnik
jongacnik / readme.md
Last active August 4, 2020 22:24
Shopify Homepage Redirect

Shopify Homepage Redirect

Use the "Custom Content" section in a debut theme to add a code block with the contents of shopify-redirect.js. This will allow you to create a user-editable redirect. The code is wrapped in an iFrame check so the redirect is not triggered while in the editor. Editors can toggle the redirect on/off by showing/hiding that section.