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 / conversation
Last active February 21, 2025 08:48
KITT conversation (Gemma2 2B)
This is en example conversation with Gemma2 2B.
The problem here is that after the first function call, the LLM should have all the necessary information to answer the initial quary.
But it still decides to call the function again. So its stuck in a function-call loop..
-----------------
SYSTEM PROMPT
-----------------
You are K.I.T.T. from Knight Rider, a speaking car that talks with Nico. So direct your answers directly to Nico in 2nd person. Keep your answers short.
@nico-martin
nico-martin / MyComponent.tsx
Last active October 16, 2024 13:51
Reactive Class values
class MyClass extends EventTarget {
private _value: number = 0;
set value(value: number) {
this._value = value;
this.dispatchEvent(new Event('valueChanged'));
}
get value(): number {
return this._value;
@nico-martin
nico-martin / VectorDB.ts
Last active January 31, 2025 02:07
An in-memory vectorDB for cosine similarity search in TypeScript that runs directly in the browser and uses TransformersJS for the embeddings.
// requires the experimental v3 of transformersJS:
// npm install xenova/transformers.js#v3
import { FeatureExtractionPipeline, pipeline } from "@xenova/transformers";
export interface Entry<T> {
str: string;
metadata: T;
}
export interface VectorizedEntry<T> extends Entry<T> {
@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 / 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 / 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 / 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 (
@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 <[email protected]>
*/
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 / 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;