Skip to content

Instantly share code, notes, and snippets.

@jonknapp
jonknapp / README.md
Last active July 29, 2023 16:05
React Native with Nix

This was based on content found at https://programsareproofs.com/articles/react_native_nix.html. It was a great starting point, but didn't work for me. I run PopOS with Nix managed by home-manager. Sometimes, things that work great out of the box for NixOS users don't always work for me, but this is what did. (I'm not sure if the original author uses NixOS)

I am using devenv as well.

I needed to bump the inotify values on my machine to make watchman run without bailing with an error immediately.

@jonknapp
jonknapp / README.md
Last active July 29, 2023 15:35
Turbo modals using template variants

You can use different html for a modal version of a view with Turbo by taking advantage of view variants and the Turbo-Frame header. This allows a page (like http://localhost:3000/widgets/1) to show as a normal page OR to be loaded using Turbo on another page into a modal window.

The turbo_action: 'advance' on the link ensures the url updates to the new page.

The turbo_frame: 'modal' on the link will slot the resulting page's turbo frame content inside the #modal frame. However, since we also use the Turbo-Frame header to set our response variant, we will call the template app/views/widgets/show.html+modal.erb if it exists, otherwise falling back to app/views/widgets/show.html.erb.

@jonknapp
jonknapp / rails.nix
Created January 22, 2022 21:44
nix shell script that provides the env needed to "rails new" a project
# https://ghedam.at/15978/an-introduction-to-nix-shell
with (import <nixpkgs> {});
mkShell {
buildInputs = [
gcc
gnumake
libiconv
libxml2
libxslt
nodejs
@jonknapp
jonknapp / react.jsx
Created April 6, 2019 13:04
Dynamic React Component Finder in Rails with Webpacker
// app/javascript/packs/react.jsx
import React from "react";
import ReactDOM from "react-dom";
interface ComponentLookupTable {
[s: string]: Function;
}
function componentAlias(componentPath: string) {
@jonknapp
jonknapp / generator.rb
Last active September 16, 2018 17:49
JS Generator in Ruby
class EnhancedYielder < Enumerator::Yielder
attr_writer :yielder
def initialize
@error = nil
@yielder = nil
end
def throw(error)
@error = error
@jonknapp
jonknapp / index.js
Created September 19, 2017 16:14
Show screenshot from Chrome headless in iTerm terminal (on Mac)
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.coffeeandcode.com');
const screenshot = await page.screenshot();
process.stdout.write('\033]1337;File=name=image;inline=1:');
process.stdout.write(screenshot.toString('base64'));
### Keybase proof
I hereby claim:
* I am jonknapp on github.
* I am jonknapp (https://keybase.io/jonknapp) on keybase.
* I have a public key whose fingerprint is C39E D0F5 AF7C 81FD 8B35 4EBA 5133 0F9D 3F9D 368E
To claim this, I am signing this object:
@jonknapp
jonknapp / slack.md
Last active January 16, 2017 18:52
Collection of regional Slack tech communities

Slipcast: A static website generator

This project simplifies the creation of static websites by using convention over configuration to create an enjoyable front-end development experience.

Behind the scenes, it relies on Metalsmith, RollupJS, PostCSS, Handlebars, and Browsersync to build a directory of static css, html, and javascript files as well as a development mode that reloads your changes as files are saved. However, you

@jonknapp
jonknapp / .bashrc
Created September 3, 2016 14:49
Bash Aliases
alias docker-gc='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc'
alias gh='hub browse' # open Github project url from terminal
alias s='"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" .'
alias sublime='"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"'
alias server='python -m SimpleHTTPServer 8000' # quick static file server; use `http.server` in python 3
alias show-hidden-files='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hide-hidden-files='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
alias timestamp='ts "[%Y-%m-%d %H:%M:%.S]"'