Skip to content

Instantly share code, notes, and snippets.

@lubien
lubien / ecto_sqlite.livemd
Created April 5, 2024 12:18
ecto_sqlite livebook

Untitled notebook

Mix.install([
  {:liveview_playground, "~> 0.1.8"},
  {:phoenix_ecto, "~> 4.5"},
  {:ecto, "~> 3.11"},
  {:ecto_sqlite3, "~> 0.13"}
])
@adtac
adtac / Dockerfile
Last active July 24, 2024 14:11
#!/usr/bin/env docker run
#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"
# syntax = docker/dockerfile:1.4.0
FROM node:20
WORKDIR /root
RUN npm install sqlite3
@cywang117
cywang117 / delete-device-config-var-overrides.js
Last active May 2, 2024 18:41
For large balena fleets, it may be necessary to run this from the Chrome dev console.
// This script may be run in a Chrome dev console, and will delete all the device config variables for each device in a fleet,
// which the exception of *_SUPERVISOR_DELTA or *_SUPERVISOR_DELTA_VERSION.
await (async () => {
// Make sure FLEET_ID is the ID of your fleet.
const FLEET_ID = 12345;
// Get devices in fleet
const devices = await sdk.models.device.getAllByApplication(FLEET_ID, {
$select: 'id',
});
@mcrumm
mcrumm / phx_sqlite_fly_launch.md
Last active May 3, 2024 09:38
Phoenix + SQLite Deployment tips

Deploying to Fly.io with SQLite

Deploying a Phoenix app to Fly.io is a breeze...is what everyone kept telling me. In fairness, I imagine the process would have been breezier had I just used postgres, but all the sqlite and litestream talk has been far too intriguing to ignore. "Wait", you say. "It is just a flat file. How much harder can it be?"

It is easy to make something harder than it should be. It is hard to take something complex and make it truly simple. flyctl launch does an amazing job at providing a simple interface to the utterly complex task of generating deployment resources, especially now that we are living in a containerd (erm, firecracker) world.

This gist is for anyone who, like me, thinks they know better than to read all of the documentation and therefore necessari

@cywang117
cywang117 / preload-any-supervisor-version-onto-balena-os.md
Last active April 19, 2024 14:41
Preload any Supervisor onto balenaOS image

Replace loopN with loop number listed with partx command

Download & mount .img

balena os download raspberrypi4-64 -o rpi4.img
losetup -fP --show rpi4.img
mount /dev/loopNp6 $MOUNTPOINT 

If the mount fails with wrong fs type or similar, this is most likely because the image is a flasher image (i.e. for Intel NUC, for example), and you will need to do the following:

@keatz55
keatz55 / index.ex
Last active April 12, 2021 17:49
LiveView Query Helper Module
defmodule ExampleWeb.ArticleLive.Index do
alias Example.{Articles, Tags}
alias ExampleWeb.{ArticleLive, ComponentLive, Query}
use ExampleWeb, :live_view
@impl true
def render(assigns) do
~L"""
<div class="container max-w-screen-md mx-auto pt-6">
@vinicius73
vinicius73 / Dockerfile
Last active August 15, 2019 22:21
Node project with PM2 and Docker
FROM node:10.15-alpine as base
RUN apk --no-cache --virtual build-dependencies add \
python \
make \
g++ \
&& rm -f /var/cache/apk/* \
&& npm config set unsafe-perm true \
&& npm install --quiet node-gyp -g --cache /tmp/empty-cache
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active July 23, 2024 00:25
set -e, -u, -o, -x pipefail explanation
@bvaughn
bvaughn / eager-prefetching-async-data-example.js
Last active June 16, 2024 21:56
Advanced example for eagerly prefetching async data in a React component.
// This is an advanced example! It is not intended for use in application code.
// Libraries like Relay may make use of this technique to save some time on low-end mobile devices.
// Most components should just initiate async requests in componentDidMount.
class ExampleComponent extends React.Component {
_hasUnmounted = false;
state = {
externalData: null,
};
@DimitryDushkin
DimitryDushkin / react-router-queyry-utils.js
Last active March 5, 2021 13:38
React router utility functions to add and remove queries
import { browserHistory } from 'react-router';
/**
* @param {Object} query
*/
export const addQuery = (query) => {
const location = Object.assign({}, browserHistory.getCurrentLocation());
Object.assign(location.query, query);
browserHistory.push(location);
};