Skip to content

Instantly share code, notes, and snippets.

View aashreys's full-sized avatar
zooming...

Aashrey Sharma aashreys

zooming...
View GitHub Profile
@aashreys
aashreys / Instant handler runnable execution with Mockito
Last active October 27, 2023 23:48
Use Mockito to instantly execute handler runnables in your tests.
// Creating a handler which executes runnables immediately
Mockito.when(uiHandler.post(Mockito.any(Runnable.class))).thenAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Runnable msg = invocation.getArgument(0);
msg.run();
return null;
}
}
@aashreys
aashreys / wait-for-webserver.sh
Created July 21, 2017 02:39
A bash script which checks the status of a web server before executing commands.
#!/bin/bash
# wait-for-nlu.sh
set -e
host="$1"
shift
cmd="$@"
http_status="$(curl -s -o /dev/null -I -w "%{http_code}" http://www.webserver.com:8080/)"
@aashreys
aashreys / config.h
Last active September 22, 2024 03:37
Adding RGB Timeout functionality to your QMK keyboard
/* In your config.h define a new variable RGBLIGHT_TIMEOUT and give it a value in milliseconds */
#define RGBLIGHT_SLEEP // allows us to use rgblight_suspend() and rgblight_wakeup() in keymap.c
#define RGBLIGHT_TIMEOUT 30000 // 30 seconds
@aashreys
aashreys / figma_gist.js
Created November 29, 2022 19:14
Get Figma Node ID from URL
export function getNodeIdFromUrl(url: string): string | null {
url = url.toLowerCase()
let startIndex: number = url.indexOf('node-id=') + 8
let endIndex: number = url.indexOf('&', startIndex)
if (startIndex) {
if (endIndex > 0) {
return url.substring(startIndex, endIndex).replace('%3a', ':')
} else {
return url.substring(startIndex).replace('%3a', ':')
}
@aashreys
aashreys / figma-gist.js
Created November 29, 2022 19:16
Check if a Figma URL is that of the current file
export function isThisFile(url: string): boolean {
let formattedFilename = figma.root.name.trim()
formattedFilename = encodeURIComponent(formattedFilename).replace(/%20/g, '-')
let isThisFile = url.includes('figma.com') && url.includes(formattedFilename)
return isThisFile
}
@aashreys
aashreys / gist:f35a938cb8ac93be6c1ea614c63fc481
Created March 31, 2025 16:08
Reusable components in Figma Widgets
// is it possible to package widget UI elements into discrete reusable react-style components?
// I'd like to reuse some UI elements across my widget and currently do not know how to achieve this.
interface Props {
name: string;
}
function HelloWorld({ name }: Props) {
return <figma.widget.Text>Hello, {name}!</figma.widget.Text>
}