Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<title>Home</title>
<script>
function checkStatus() {
var queryString = parseQueryString();
if (queryString['name']) {
var result = document.getElementById('result');
result.innerHTML = 'Form submitted';
}
irb(main):002> h = {}.compare_by_identity
=> {}
irb(main):003> h['a'] =3
=> 3
irb(main):004> h['a'] =5
=> 5
irb(main):005> h
=> {"a"=>3, "a"=>5}
irb(main):006> h[:a] = 1
=> 1
(async (secret, body) => {
let enc = new TextEncoder("utf-8");
let algorithm = { name: "HMAC", hash: "SHA-256" };
let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, ["sign", "verify"]);
let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(body));
let hexString = Array.from(new Uint8Array(signature)).map(byte => byte.toString(16).padStart(2, '0')).join('');
console.log(hexString);
@ewalk153
ewalk153 / extract_notes.py
Created May 30, 2024 23:07
Small script to extract apple notes files from the source sqlite3 file. Files extracted to their compressed files. Output is a protobuf doc. For simple notes the text is typically usable.
import sqlite3
import zipfile
con = sqlite3.connect("NoteStore.sqlite")
res = con.execute("select Z_PK, ZDATA from ZICNOTEDATA")
for row in res.fetchall():
print(f"ID: {row[0]}")
# this is a protobuf doc but the text is usually readable
temp_file_name = f"doc{row[0]}.txt.zip"
f = open(temp_file_name, "wb")
@ewalk153
ewalk153 / 0. Rails app GQL README.md
Last active June 27, 2024 01:30
fast create rails graphql API

Setup instructions

rails new demo-rails-gql --api
bundle add graphql
rails generate graphql:install
rails g model product title description options
rails g model variant title option1 option2 option3 sku product:references
rails db:migrate
rails g graphql:object product
rails g graphql:object variant
@ewalk153
ewalk153 / remix_upload.tsx
Created April 18, 2024 02:36
Remix demo of a CSV file upload
import type { ActionFunctionArgs, UploadHandler } from "@remix-run/node";
import {
json,
unstable_createMemoryUploadHandler as createMemoryUploadHandler,
unstable_parseMultipartFormData as parseMultipartFormData,
} from "@remix-run/node";
import { useFetcher } from "@remix-run/react";
type ActionData = {
errorMsg?: string;
@ewalk153
ewalk153 / Dockerfile
Last active February 13, 2024 14:01
piku docker image
FROM debian:bullseye
ENV DEBIAN_FRONTEND=noninteractive
# Install the minimum amount of packages required for testing, which currently means:
# - minimal set of packages required to run Python 3
# - shipping versions of uWSGI and nginx (so that config files are put in the right places)
# Also, make sure we have a sane default locale inside the container
RUN apt-get update \
@ewalk153
ewalk153 / gist:2c6f89fa988c3916cad28b3d4564e723
Created December 20, 2023 02:54
Puma install on latest mac Sonoma 14.2
bundle config build.puma --with-pkg-config=$(brew --prefix [email protected])/lib/pkgconfig
bundle install --redownload
@ewalk153
ewalk153 / nginx-rails.conf
Created January 30, 2023 02:47
Nginx conf for reverse proxying a rails app
upstream app {
# Path to Puma SOCK file, as defined previously
# server unix:/home/deploy/appname/shared/sockets/puma.sock fail_timeout=0;
server unix:/Users/ericwalker/src/github.com/ewalk153/sample-rails-app/shared/sockets/puma.sock fail_timeout=0;
}
server {
listen 4000;
server_name localhost;
@ewalk153
ewalk153 / _nginx_protect_static_assets.conf
Last active February 2, 2023 02:56
Protect static assets with a rails app
upstream backend {
server localhost:3000;
}
server {
listen 9000;
server_name localhost;
root /path_of_rails_app/public;
try_files $uri/index.html $uri @app;