Skip to content

Instantly share code, notes, and snippets.

View itzaks's full-sized avatar

Isak ✏ ⇝ itzaks

View GitHub Profile
@itzaks
itzaks / EditableTextCell.tsx
Last active August 25, 2023 17:24
Editable cells for Payload CMS
import React from "react";
import { useRef, useState, useEffect } from "react"
import { type Props } from "payload/components/views/Cell"
import { useConfig } from "payload/dist/admin/components/utilities/Config"
const DEBOUNCE_UPDATE_MS = 1500
const EditableTextCell: React.FC<Props> = (props) => {
const { field, collection, cellData, rowData } = props
@itzaks
itzaks / useAsyncState.ts
Created December 5, 2022 12:37
useAsyncState composable for fetching asyncdata in composables
import { Ref } from "vue"
interface AsyncStateOptions<T, O> {
transform?: (input: T) => O
}
interface AsyncStateReturnType<T> {
execute: () => Promise<void>,
refresh: () => Promise<void>,
pending: Ref<boolean>,
@itzaks
itzaks / config.txt
Created January 10, 2017 16:43
Raspberry /boot/config.txt details for GPU perf. RPI1 B+ 512MB
# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=1
hdmi_mode=4
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
hdmi_drive=2
#uncomment to overclock the arm. 700 MHz is the default.
@itzaks
itzaks / responsive-retina-image.styl
Created June 24, 2015 13:57
Render an image that scales nicely and keeps its proportions. Depends on nib's image-mixin for retina images.
img(src, width, height)
image(src)
background-size: contain
background-repeat: no-repeat
background-position: 50%
max-width: width
width: 100%
margin-left: auto
margin-right: auto
@itzaks
itzaks / debounce.coffee
Created December 11, 2014 13:14
tiny coffeescript debounce function
debounce = (timeout, fn, timer = null) -> ->
clearTimeout timer
timer = setTimeout fn, timeout
@itzaks
itzaks / readify.js
Last active August 29, 2015 14:06
Simple bookmarklet for injecting readability styles straight into the page.
(function() {
function loadScript(a,b){
var c=document.createElement('script');
c.type='text/javascript';c.src=a;
var d=document.getElementsByTagName('head')[0],done=false;
c.onload=c.onreadystatechange=function(){
if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){
done=true;
b()
}
@itzaks
itzaks / space-talk.coffee
Last active August 29, 2015 14:05
Add mediator style pub/sub to space-pen views using flesch/psst.js
psst = require 'psst'
module.exports = require 'space-pen'
module.exports.EventView =
class EventView extends module.exports.View
subscriptions: null
initialize: ->
return unless @subscriptions
for subscription, method of @subscriptions
@itzaks
itzaks / imghex.coffee
Created August 15, 2014 09:37
Html input(type=file) image to base64
module.exports = (file, cb) ->
valid = (/image\/(gif|jpg|jpeg|tiff|png)$/i).test file.type
return false if not valid
reader = new FileReader()
reader.onload = (e) ->
cb(e.target.result)
reader.readAsDataURL(file)
@itzaks
itzaks / _mixins.jade
Created May 12, 2014 12:23
IE8 polyfill for 'background-size: cover'
- var background = function(url) {
- return "background-size: cover; background-image: url('" + url + "'); -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale')\";";
- }
@itzaks
itzaks / pie-chart.coffee
Created April 23, 2014 15:55
Lightweight Pie Chart module
module.exports =
class Pie
pos: 0
colors: ['yellow', 'black']
constructor: (@canvas, {@yes, @no}) ->
@data = [@yes, @no]
@context = canvas.getContext("2d")
#uses underscore for reduce but just swap with vanilla js if needed
@total = _.reduce @data, (memo, num) -> memo + num
@draw()