Skip to content

Instantly share code, notes, and snippets.

@romannurik
romannurik / dev.nix
Created April 2, 2024 14:15
First attempt at postgres on IDX
# .idx/dev.nix
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.nodejs_18
# Packages for postgres.
# There may be an alternative approach using docker
@romannurik
romannurik / DrawInsetsFrameLayout.java
Created February 10, 2014 16:28
DrawInsetsFrameLayout — adding additional background protection for system UI chrome when using KitKat’s translucent decor flags.
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@romannurik
romannurik / AndroidManifest.xml
Last active March 7, 2024 11:13
Android example of how to programmatically instantiate a View with a custom style.
<manifest ...>
...
<!-- Make sure your app (or individual activity) uses the
theme with the custom attribute defined. -->
<application android:theme="@style/AppTheme" ...>
...
</application>
</manifest>
@romannurik
romannurik / button_bar_layout.xml
Created April 10, 2012 04:24
How to make a proper button bar on ICS
<!--
A button bar is a set of buttons at the bottom of an activity.
An example is an AlertDialog with OK/Cancel buttons.
Note that something similar can be accomplished using a
split action bar and text-only action buttons, but this is an
alternate presentation that's often preferred.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
@romannurik
romannurik / Expando.jsx
Last active September 18, 2023 01:04
A simple expand/collapse animation using React
import React, {useRef, useLayoutEffect} from 'react';
const [DURMIN, DURMAX] = [0.1, .8];
const dur = f => Math.min(DURMAX, (1 - f) * DURMIN + f * DURMAX);
export function Expando({className, children, open}) {
open = !!open;
let node = useRef();
let lastOpen = useRef(open);
let duration = useRef(.5);
@romannurik
romannurik / CheatSheet.java
Last active May 16, 2023 13:42
Android helper class for showing cheat sheets (tooltips) for icon-only UI elements on long-press. This is already default platform behavior for icon-only action bar items and tabs. This class provides this behavior for any other such UI element.
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@romannurik
romannurik / .gitconfig
Last active February 2, 2023 18:38
Cheap Sketch file version control with Git + Kaleidoscope
# Add this to your .git/config file
[diff]
tool = SketchKaleidoscope
[difftool "SketchKaleidoscope"]
cmd = ./util-sketch-kaleidoscope-diff.bash \"$MERGED\" \"$LOCAL\" \"$REMOTE\"
#
#
#
# MOVED TO http://code.google.com/p/romannurik-code/source/browse/misc/bash_completion/adb
#
#
#
function _adb()
@romannurik
romannurik / nunjucks-block-call-extension.js
Last active September 21, 2022 12:58
Nunjucks Block Call Extension (call a macro, pass content of sub-blocks as keyword args)
const TAG_NAME = 'blockcall';
const ARG_TAG_NAME = 'argblock';
class BlockCallExtension {
constructor(nunjucks) {
this.tags = [TAG_NAME];
this.nunjucks = nunjucks;
}
@romannurik
romannurik / duplicate-components.scripter.ts
Last active February 24, 2022 16:08
Figma + Scripter scripts
// Makes a copy of all selected components (how is this not built into Figma?)
let newSelection = [];
for (let component of figma.currentPage.selection.filter(node => node.type == 'COMPONENT')) {
let clone = component.clone()
clone.x += clone.width;
newSelection.push(clone);
}
figma.currentPage.selection = newSelection;