Skip to content

Instantly share code, notes, and snippets.

Avatar
❤️

Nico Martin nico-martin

❤️
View GitHub Profile
@nico-martin
nico-martin / README.md
Last active Mar 31, 2022
The C++ code I'm using on the Arduino Nano RP2040 to control the two drv8871 and the Bluetooth LE server.
View README.md

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 / App.tsx
Last active Nov 22, 2021
A React Context Provider to share State between reloads or even between tabs,
View App.tsx
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 / App.jsx
Created Apr 6, 2021
A global state with React.Context and React Hooks
View App.jsx
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 / PostList.jsx
Last active Aug 8, 2022
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
View PostList.jsx
// ./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 (
@nico-martin
nico-martin / Polylang.php
Last active Apr 15, 2020
A PHP-Class to make fields translatable
View Polylang.php
<?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 Feb 21, 2021
Gutenberg InnerBlock with renderAppender
View InnerBlock-renderAppender-block.jsx
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 / block-ssr.js
Last active Jun 26, 2019
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.
View block-ssr.js
(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 / ServerSideRender.jsx
Last active Jun 26, 2019
ServerSideRender block
View ServerSideRender.jsx
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 / .htaccess
Last active Jun 13, 2019
Cache-Control headers
View .htaccess
<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>
View loadfonts.js
function loadFont(t, e, n) {
return new Promise(resolve => {
const a = navigator.userAgent;
if (window.addEventListener && (!a.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) || a.match(/Chrome/))) {
let o = {};
try {
o = localStorage || {}
} catch (t) {}
const r = t, i = r + "url", s = r + "css", d = o[i], c = o[s], l = document.createElement("style");
if (l.rel = "stylesheet", document.head.appendChild(l), !c || d !== e && d !== n) {