Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kemiljk's full-sized avatar
👨‍💻

Karl kemiljk

👨‍💻
View GitHub Profile
@kemiljk
kemiljk / WorkoutSession.swift
Created March 16, 2024 16:58
Workout Session function
func saveWorkoutToHealthKit() async throws {
guard HKHealthStore.isHealthDataAvailable() else {
print("HealthKit is not available on this device.")
return
}
let healthStore = HealthKitManager.shared.healthStore
if HKHealthStore.isHealthDataAvailable() {
let energyBurnedType = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!
@kemiljk
kemiljk / Create Slides.ts
Created October 14, 2021 14:41
Scripter: Create slides, maintaining their aspect ratio, at any width.
function buildSlides() {
const frame = figma.createFrame()
const width = 1440
const height = width * 9/16
frame.name = "Slide"
frame.resize(width, height)
}
buildSlides()
@kemiljk
kemiljk / Remove Masks.ts
Created October 14, 2021 14:40
Scripter: Remove masks from anything in your selection
selection.forEach((node: any) => {
node.isMask && node.remove();
for (const child of node.children) {
child.isMask && child.remove();
}
});
@kemiljk
kemiljk / Auto layout For Entire Selection.ts
Last active October 14, 2021 14:41
Scripter: Add Auto Layout to all of your individually selected Frames
const { selection } = figma.currentPage;
const direction = "VERTICAL" // "HORIZONTAL"
const spacing = 24 // any number
const padding = 24 // any number
const vAlignment = "CENTER" // "MIN" (left) or "MAX" (right)
const hAlignment = "SPACE_BETWEEN" // "MIN" (top), "MAX" (bottom), "SPACE_BETWEEN" (stretch)
selection.forEach((node: FrameNode) => {
node.layoutMode = direction
node.itemSpacing = spacing
@kemiljk
kemiljk / find-instances-from-selection.ts
Last active March 31, 2021 07:21
A quick way to grab all instances that match your selection for easy switching
let iconName: String
let getInstances
const { selection } = figma.currentPage
function getInstanceByName(node) {
iconName = selection[0].name
}
getInstanceByName(selection)
@kemiljk
kemiljk / figma-append-title-and-set-export-settings.ts
Last active March 14, 2021 08:19
A way to add a title to all Frames and apply common export settings
// NOTE: This uses the Scripter API so won't work as a normal Figma plugin
// Download here: https://www.figma.com/community/plugin/757836922707087381/Scripter
const layers = figma.currentPage.findAll();
const frames = layers.filter(isFrame);
async function renameFrames() {
let items = frames;
if (items.length > 0) {
for (const node of items) {
@kemiljk
kemiljk / figma-crop-all.ts
Last active March 14, 2021 08:18
A way to crop all images to the same aspect
// Note: this uses the Scripter API so won't work via regular Figma plugin code
// Download here: https://www.figma.com/community/plugin/757836922707087381/Scripter
const layers = figma.currentPage.findAll(isImage);
figma.currentPage.selection = layers
for (let shape of await find(selection(), n => isImage(n) && n)) {
// Update image paints to use "FILL" scale mode
shape.fills = shape.fills.map(p =>
isImage(p) ? {...p, scaleMode: "FILL",} : p)
@kemiljk
kemiljk / figma-homehero-textlint.ts
Last active March 4, 2021 19:57
A way to lint common phrases we use in our design files that can be miswritten
const find = ["Move in", "move in", "Homehero", "wifi", "Wifi", "WiFi"];
const replace = ["Move-in", "move-in", "HomeHero", "Wi-Fi"];
const layers = figma.currentPage.findAll((node) => node.type === "TEXT");
figma.currentPage.selection = layers;
const { selection } = figma.currentPage;
async function lintTextNodes(): Promise<String> {
figma.root.children.flatMap((pageNode) =>
pageNode.selection.forEach(async (node) => {