Skip to content

Instantly share code, notes, and snippets.

@ashwinrs
ashwinrs / IterateOverJSONUsingGson.java
Last active January 9, 2023 23:54
Iterate over elements in a JSON using GSON in Java
final JsonObject jsonObject = GSON.toJsonTree(<Object>).getAsJsonObject();
for(Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
System.out.println("Key = " + entry.getKey() + " Value = " + entry.getValue() );
}
@philmander
philmander / nav.jsx
Last active August 1, 2020 15:49
Simple Preact Unit Testing with Jest (with shallow rendering)
import { h, Component } from 'preact';
import { Link } from 'preact-router/match';
class Nav extends Component {
constructor() {
super();
this.state.title = 'Navigation'
}
<alignment jcr:primaryType="nt:unstructured"
name="./alignChildren"
fieldLabel="Alignment of components"
required="{Boolean}true"
selectionMode="single"
sling:resourceType="granite/ui/components/coral/foundation/form/buttongroup">
<items jcr:primaryType="nt:unstructured">
<default jcr:primaryType="nt:unstructured"
name="./default"
@beaucharman
beaucharman / throttle.js
Last active November 12, 2022 15:39
An ES6 implementation of the throttle function. "Throttling enforces a maximum number of times a function can be called over time. As in 'execute this function at most once every 100 milliseconds.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debouncing/)
function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return function() {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, arguments)
timeout = null
}