Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nico-martin's full-sized avatar
🤷‍♂️
I have no idea what I'm doing.. 90% of the time..

Nico Martin nico-martin

🤷‍♂️
I have no idea what I'm doing.. 90% of the time..
View GitHub Profile
@nico-martin
nico-martin / .htaccess
Last active June 13, 2019 11:43
Cache-Control headers
<ifModule mod_headers.c>
# One year for image and video files
<filesMatch ".(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
# One month for JavaScript and PDF files
<filesMatch ".(js|pdf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
@nico-martin
nico-martin / ServerSideRender.jsx
Last active June 26, 2019 08:23
ServerSideRender block
const {ServerSideRender} = wp.components;
wp.blocks.registerBlockType('test/ssr', {
title: 'Post Archiv',
icon: 'grid-view',
category: 'my-category',
edit(props) {
return <ServerSideRender block="test/ssr"/>
},
save() {
@nico-martin
nico-martin / block-ssr.js
Last active June 26, 2019 12:25
This is an example of a server side rendered block without any build step. It's all plain JS/PHP and it uses the helpers and components WordPress already offers in the block admin interface.
(function (blocks, components, element) {
blocks.registerBlockType('test/ssr', {
title: 'Server Side Rendered Block',
icon: 'admin-site-alt3',
category: 'test',
edit: function (props) {
return element.createElement(components.ServerSideRender, {block: 'test/ssr'});
},
save: function () {
return null;
@nico-martin
nico-martin / gtag-gdpr-ready.html
Last active February 24, 2020 15:28
This little snippet provides a simple way to a) implement Google Tag Manager with anonymized IP and b) provide a Opt-Out / Opt-In mechanism: gtagOptOutIn();
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.gtagTrackingID = 'UA-XXXXXXXX-X';
window.gtagDisableStr = 'gtag-disable-' + gtagTrackingID;
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
@nico-martin
nico-martin / Polylang.php
Last active April 15, 2020 07:10
A PHP-Class to make fields translatable
<?php
namespace SayHello\Theme\Package;
/**
* @author Nico Martin <nico@sayhello.ch>
*/
class Polylang
{
public $translatedNames = [];
@nico-martin
nico-martin / InnerBlock-renderAppender-block.jsx
Last active February 21, 2021 22:39
Gutenberg InnerBlock with renderAppender
const {TextControl, IconButton} = wp.components;
const {InnerBlocks} = wp.editor;
const {__} = wp.i18n;
const {dispatch} = wp.data;
const {createBlock, registerBlockType} = wp.blocks;
registerBlockType('prefix/container', {
title: 'Container',
icon: 'category',
category: 'category',
@nico-martin
nico-martin / App.jsx
Created April 6, 2021 19:04
A global state with React.Context and React Hooks
import React from 'react';
import { MyContextProvider, useMyContext } from './myContext';
const CompOne = () => {
const [myState, setMyState] = useMyContext();
return (
<div>
<p>
CompOne update:{' '}
<button onClick={() => setMyState({ ...myState, foo: 'baz' })}>
@nico-martin
nico-martin / App.tsx
Last active November 22, 2021 13:34
A React Context Provider to share State between reloads or even between tabs,
import React from 'react';
import ReactDOM from 'react-dom';
import {
SharedStorageProvider,
useSharedStorage,
} from './sharedStateContext.tsx';
const App = () => {
const [sharedState, setSharedState] = useSharedStorage();
@nico-martin
nico-martin / README.md
Last active March 31, 2022 21:26
The C++ code I'm using on the Arduino Nano RP2040 to control the two drv8871 and the Bluetooth LE server.

Arduino Nano Circuit

Speed Wheels Arduino Nano Circuit For the DRV8871 Motor Driver I'm using the Pins D2, D3, D5 und D6.

BLE Server

Furthermore I'm using the ArduinoBLE package to provide a BLE Server that let's you control the motor.

UUIDS:

  • motorControlService: c10e3e56-fdd3-11eb-9a03-0242ac130003
  • motorCharacteristic: 35a1022c-fdd3-11eb-9a03-0242ac130003
@nico-martin
nico-martin / PostList.jsx
Last active August 8, 2022 18:21
useApi.jsx - the correct way to fetch data with react hooks: extension of https://dev.to/nicomartin/the-right-way-to-fetch-data-with-react-hooks-48gc
// ./PostList.jsx
import React from 'react';
import {apiStates, useApi} from './useApi.jsx'
const PostList = () => {
const { state, error, data, reload } = useApi('https://api.mysite.com');
switch (state) {
case apiStates.ERROR:
return (