Skip to content

Instantly share code, notes, and snippets.

@jcarley
jcarley / json.py
Created September 16, 2022 18:10 — forked from ergoithz/json.py
python json datetime encoder
import json
import datetime
import dateutil.parser
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
'type': 'datetime',
'data': obj.isoformat()
@jcarley
jcarley / install_python.sh
Last active September 11, 2022 02:19
Install python on Raspberry Pi 4
#!/usr/bin/env bash
# Execute with the following command
# /bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/jcarley/3d46571591dc9b1cabfe2859d926dbc8/raw/3f19acd19f03e48e7b688537709c442b75dde354/install_python.sh)"
sudo apt-get update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim
mkdir -p ~/downloads/python
@jcarley
jcarley / install_tmux.sh
Created April 22, 2022 17:14 — forked from tknhs/install_tmux.sh
for Amazon Linux 2
LIBEVENT_VERSION="2.1.12-stable"
TMUX_VERSION="3.2a"
sudo yum install -y gcc kernel-devel make ncurses-devel openssl-devel
curl -LOk https://github.com/libevent/libevent/releases/download/release-${LIBEVENT_VERSION}/libevent-${LIBEVENT_VERSION}.tar.gz
tar -xf libevent-${LIBEVENT_VERSION}.tar.gz
cd libevent-${LIBEVENT_VERSION}
./configure --prefix=/usr/local
make -j4
@jcarley
jcarley / LiTagHelper.cs
Created March 3, 2022 13:51
Custom TagHelper for returning active class for menu items
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace MyApplication.Web.TagHelpers
{
/// <summary>
/// Reference: https://stackoverflow.com/questions/20410623/how-to-add-active-class-to-html-actionlink-in-asp-net-mvc
/// Item: Easy ASP.NET 3.0 and TagHelpers
/// </summary>
# install rbenv on Amazon Linux
# first we need some prerequisites
sudo yum install -y git gcc make readline-devel openssl-devel
# now install rbenv
git clone git://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
@jcarley
jcarley / .ideavimrc
Created January 6, 2022 20:34
JetBrains IDE IdeaVim .ideavimrc.
set gdefault
set hlsearch
set ignorecase
set iskeyword
set incsearch
set number
set clipboard+=unnamed
set relativenumber
set showmode
set smartcase
@jcarley
jcarley / s3_heroku_rails_01_direct_upload_controller.rb
Created November 30, 2021 17:14 — forked from elliott-king/s3_heroku_rails_01_direct_upload_controller.rb
Creates a URL for an Active Storage direct upload
class DirectUploadController < ApplicationController
def create
response = generate_direct_upload(blob_params)
render json: response
end
private
def blob_params
params.require(:file).permit(:filename, :byte_size, :checksum, :content_type, metadata: {})
@jcarley
jcarley / rails http status codes
Created October 22, 2021 18:10 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@jcarley
jcarley / docker-compose.yml
Created October 12, 2021 20:30
Put this in ~/ops/application_name
version: '3.8'
services:
db:
ipc: host
image: postgres:11.9-alpine
ports:
- "5432:5432"
environment:
- TERM=xterm
- POSTGRES_PASSWORD=password
@jcarley
jcarley / rpi-setup.sh
Last active October 12, 2021 16:34
This is the general raspberry pi setup and configuration
#!/bin/bash
# initial OS updates and configuration
sudo apt-get update
sudo apt-get upgrade -y
sudo raspi-config
sudo reboot
passwd
sudo apt-get update && sudo apt-get install ufw vim curl wget git -y