Skip to content

Instantly share code, notes, and snippets.

@gopeter
gopeter / useVirtualList.tsx
Created September 17, 2021 16:23
useVirtualList.tsx
import { RefObject, UIEvent, useCallback, useEffect, useRef, useState } from 'react'
type GetItemSize = (index: number) => number
type UseVirtualList = (
count: number,
height: number,
getItemSize: GetItemSize,
) => {
outerProps: {
@gopeter
gopeter / custom.google.maps.markers.js
Created February 27, 2017 20:19 — forked from filipbech/custom.google.maps.markers.js
Custom markers (div-element) on google maps
Usage:
var myLatLng = new google.maps.LatLng(point.lat, point.lng);
var myMarker = new CustomMarker(myLatLng,map);
Implementation (mostly from googles example):
function CustomMarker(latlng, map) {
this.latlng_ = latlng;
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@gopeter
gopeter / redirect.php
Last active February 8, 2017 16:25
A simple snippet to remove trailing numbers at the end of wordpress urls. For example: redirect http://example.com/foobar/2024/ to http://example.com/foobar/. Don't use it if your permalink structure ends with "%post_id%"! This will return an infinite redirect-loop!
<?php
// get the url
$url = 'http://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
// check if there are any slashes inside the url string
if (strpos($url, '/')) {
// split the string in pieces
// use "/" as separator