Skip to content

Instantly share code, notes, and snippets.

View Haraldson's full-sized avatar

Hein Haraldson Berg Haraldson

View GitHub Profile
@Haraldson
Haraldson / usage.js
Last active March 11, 2023 13:53
Lodash useDebounce React Hook
import React, { useState, useEffect } from 'react'
import { useDebounce } from './use-debounce'
const MySearchComponent = props => {
const [search, setSearch, {
signal,
debouncing
}] = useDebounce('')
const [results, setResults] = useState([])
const People = () => {
const peopleContext = useContext(PeopleContext)
const [people, sort, setSortField] = useSort({
items: peopleContext.people ?? [],
fields: {
name: {
method: 'compare',
getValue: ({ firstName, lastName }) => `${lastName} ${firstName}`,
order: 'asc'
@Haraldson
Haraldson / svg-icon.js
Created September 20, 2018 08:43
SVG Icon
import React from 'react'
import Svg, { Path } from 'react-native-svg'
const icons = {
'confirm': 'm503 127l-46-45c-12-12-32-12-45 0l-217 226l-82-82c-12-13-33-13-45 0l-45 45c-13 12-13 33 0 45l150 150c12 13 32 13 45 0l68-68l217-225c6-7 9-15 9-23l0 0c0-8-3-16-9-23z',
'dismiss': 'm439 363l-102-102l102-102c12-12 12-33 0-45l-46-45c-12-13-32-13-45 0l-102 102l-102-102c-12-13-32-13-45 0l-45 45c-12 12-12 33 0 45l102 102l-102 102c-12 12-12 33 0 45l45 45c13 13 33 13 46 0l101-101l102 101c13 13 33 13 45 0l46-45c12-12 12-33 0-45z',
'notifications-on': 'm384 288c0-58 0-169-97-189c0-1 1-2 1-3c0-18-14-32-32-32c-18 0-32 14-32 32c0 1 1 2 1 3c-97 20-97 131-97 189c0 64-64 96-64 96l0 32l384 0l0-32c0 0-64-32-64-96z m-160 192l64 0c18 0 32-14 32-32l-128 0c0 18 14 32 32 32z',
'notifications-off': 'm352 107c-15-19-35-34-65-40c0-1 1-2 1-3c0-18-14-32-32-32c-18 0-32 14-32 32c0 1 1 2 1 3c-97 20-97 131-97 189c0 64-64 96-64 96l0 32l11 0z m32 149l-128 128l192 0l0-32c0 0-64-32-64-96z m-185 185c6 8 15 13 25 13l64 0c18 0 32-14 3
@Haraldson
Haraldson / emoji-text.js
Last active August 22, 2018 12:16
Emojis in React Native text
import React from 'react'
import { Text } from 'react-native'
import emojiRegex from 'emoji-regex'
import { map, split, reduce, get, last } from 'lodash'
export default ({ text, textStyle = {}, emojiStyle = {}, keySalt = Date.now() }) => {
const taggedSymbols = map(split(text, ''), symbol => ({ symbol, emoji: emojiRegex().test(symbol) }))
const sectionedSymbols = reduce(taggedSymbols, (sections, taggedSymbol, index) => {
if(taggedSymbol.emoji !== get(taggedSymbols, `${index - 1}.emoji`)) {
@Haraldson
Haraldson / Component.js
Last active February 1, 2018 12:55
SVG Icons
import React, { Component } from 'react'
import Icon from './icon'
export default class Sp00x extends Component {
componentDidMount() {
// I got the spooks
}
render() {
return <Icon name="sp00x" />
@Haraldson
Haraldson / user.js
Last active March 10, 2017 13:20
Couchsurfing: Show week days in Dashboard overview
// ==UserScript==
// @name Couchsurfing: Show week days in Dashboard overview
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Less cognitive load!
// @author Hein Haraldson Berg
// @match https://www.couchsurfing.com/dashboard
// @grant none
// ==/UserScript==
@Haraldson
Haraldson / user.js
Created March 10, 2017 13:05
Couchsurfing: Just a reply!
// ==UserScript==
// @name Couchsurfing: Just a reply!
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sometimes, even saying ’Maybe’ is too much of a commitment. There might be too little information, or you just don’t want to get their hopes up.
// @author Hein Haraldson Berg
// @match https://www.couchsurfing.com/messages/*
// @grant none
// ==/UserScript==
import api from 'utilities/api'
// Actions
const fetchingEvents = () => {
return {
type: 'events:fetching'
}
}
const fetchEventsFailure = (error) => {
@Haraldson
Haraldson / README.md
Created December 9, 2015 12:49
Handlebars ‘in’ block helper

Explanation

Some APIs only return a certain property if it’s supported in that context. This makes using the traditional {{#if}} block helper difficult, even when passing in the little known includeZero=true; the property value might be null, and in some edge cases even undefined.

@Haraldson
Haraldson / regions.js
Last active October 22, 2015 08:09 — forked from belackriv/gist:008087f6f005aee1167f
Marrionette Table without composite view
var NoWrapRegion = Backbone.Marionette.Region.extend({
attachHtml: function (view) {
this.el.innerHTML="";
var children = view.el.childNodes;
while (children.length > 0) {
this.el.appendChild(children[0]);
}
view.setElement(this.el, true)
}
});