Skip to content

Instantly share code, notes, and snippets.

View vincentorback's full-sized avatar
🌻

Vincent Orback vincentorback

🌻
View GitHub Profile
@vincentorback
vincentorback / remove_node_modules.sh
Last active July 10, 2020 15:10
delete all node_modules directories
# Test
find . -name "node_modules" -type d -prune -print | xargs du -chs
# Remove
find . -name "node_modules" -type d -prune -print -exec rm -rf "{}" \;
@vincentorback
vincentorback / undeletable-wordpress-pages.php
Last active August 31, 2020 14:45
Undeletable WordPress pages
<?php
function restrict_post_deletion ($post_ID) {
$restricted_pages = [
get_option('page_on_front'),
123,
666
];
if (!current_user_can('administrator') && in_array($post_ID, $restricted_pages)) {
@vincentorback
vincentorback / .deploy
Created September 7, 2020 08:50
Github Action - Deploying Bedrock WordPress website
name: Build and deploy
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
@vincentorback
vincentorback / README.md
Last active May 19, 2025 14:21
Swedish counties, municipalities, districts. Svenska län, kommuner och distrikt.

Sweden JSON / Sverige JSON

Swedish counties, municipalities and districts in JSON format.
Svenska län och kommuner och distrikt i JSON format.

Data

Downloaded from SCB 13 jan 2021.

@vincentorback
vincentorback / get-id.php
Last active November 29, 2021 09:53
Get ID from videos embedded from YouTube and Vimeo
<?php
function getElementAttribute ($attribute, $html) {
if (preg_match('/' . $attribute . '="([^"]+)"/', $html, $match)) {
return $match[1];
}
return false;
}
@vincentorback
vincentorback / get_attachment_id_from_url.php
Last active February 25, 2022 09:15
Get the attachment ID for a given file url in WordPress
<?php
if ( ! function_exists( 'get_attachment_id_from_url' ) ) {
/**
* Get the attachment ID for a given file url
*
* @link http://wordpress.stackexchange.com/a/7094
* @param string $url
* @return boolean|integer
*/
@vincentorback
vincentorback / acf-yoast-og.php
Last active April 23, 2021 10:14
Use ACF images combined with Yoast SEO default image
<?php
/**
* Remove default output of og:image from yoast
*/
add_filter('wpseo_frontend_presenter_classes', function ($filter) {
$presenter_to_remove = [
'Yoast\WP\SEO\Presenters\Open_Graph\Image_Presenter'
];
@vincentorback
vincentorback / snipcart.js
Last active May 2, 2025 16:54
Product stock with Snipcart Javascript API
const API_KEY = 'XXXXXXXXXXXXXXXXX'
export const fetchStock = async (productId = '') => {
try {
const response = await fetch(`https://app.snipcart.com/api/products/${productId}`, {
headers: {
'Authorization': 'Basic ' + Buffer.from(API_KEY + ':').toString('base64'),
'Accept': 'application/json',
},
}).then(res => res.json())
@vincentorback
vincentorback / regex-background-position.md
Last active December 29, 2022 14:44
Common regex patterns

Background position (50% 50%)

/(\d{1,2}\% \d{1,2}\%)/g

@vincentorback
vincentorback / react-native-transparent-image.js
Last active December 29, 2022 14:43
React native transparent image using canvas
import React from 'react'
import { Animated } from 'react-native'
import Canvas, { Image as CanvasImage } from 'react-native-canvas'
const TransparentImage = ({ source, width, height, backgroundColor }) => {
const fadeAnim = React.useRef(new Animated.Value(0)).current
return (
<Animated.View
style={{