Skip to content

Instantly share code, notes, and snippets.

View charterchap's full-sized avatar

Jeff Charter Chapman charterchap

View GitHub Profile
@sesgoe
sesgoe / 01_scripts_and_styles.js
Last active March 22, 2023 22:25
Retool Realtime WebSocket
const webSocket = new WebSocket('wss://echo.websocket.org');
//Event listeners are the pillars upon which WebSockets are built. This event fires when the WebSocket is considered 'OPEN',
//which means that it has connected successfully.
webSocket.addEventListener('open', function(event) {
console.log('websocket connected successfully') //log this into the browser console so we can check if the websocket connected
});
//This is a global reference to the websocket that we created. We need this because otherwise multiple JS
@wllmsash
wllmsash / assigning-static-ip-addresses-in-wsl2.md
Last active April 18, 2024 23:19
Assigning Static IP Addresses in WSL2

Assigning Static IP Addresses in WSL2

WSL2 uses Hyper-V for networking. The WSL2 network settings are ephemeral and configured on demand when any WSL2 instance is first started in a Windows session. The configuration is reset on each Windows restart and the IP addresses change each time. The Windows host creates a hidden switch named "WSL" and a network adapter named "WSL" (appears as "vEthernet (WSL)" in the "Network Connections" panel). The Ubuntu instance creates a corresponding network interface named "eth0".

Assigning static IP addresses to the network interfaces on the Windows host or the WSL2 Ubuntu instance enables support for the following scenarios:

@bbengfort
bbengfort / ani.py
Last active October 6, 2023 03:08
Experiments with live animation using asyncio and writing to a file. Works with two different processes, but only data generator works in asyncio, not the animation itself.
import json
import random
import asyncio
import argparse
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from functools import partial
@Orenoid
Orenoid / cache.py
Last active July 1, 2022 19:55
Python lru_cache with expiration
import datetime
import time
from _thread import RLock
from functools import update_wrapper, _make_key, _CacheInfo
# Check the example at the end of this script.
class Node:
"""node of the circular doubly linked list"""
@colophonemes
colophonemes / create_triggers
Last active February 17, 2024 15:15
Postgres TRIGGER to call NOTIFY with a JSON payload
CREATE TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
'email',
'username'
);
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
@tjanczuk
tjanczuk / xpub-xsub.js
Created August 24, 2015 23:59
How to connect 5 publishers with 5 subscribers over TCP using ZeroMQ's XPUB/XSUB proxy
// How to connect 5 publishers with 5 subscribers
// over TCP using ZeroMQ's XPUB/XSUB proxy.
// sub (connect)
// <-8701->
// (bind) xpub <---> xsub (bind)
// <-8700->
// (connect) pub
var zmq = require('zmq');
@obfusk
obfusk / break.py
Last active March 20, 2024 23:09
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use https://docs.python.org/3/library/pdb.html
import code; code.interact(local=dict(globals(), **locals()))
@tapanpandita
tapanpandita / django_task_queue.md
Created May 6, 2012 16:54
Task queuing in Django with ZeroMQ

Task queuing in Django with ZeroMQ

Introduction

Here at Glitterbug Tech, Django is the lifeline of everything we make and we are big fans! Django doesn't get in the way and lets us write the language we love, python, while providing an amazing set of tools that makes creating web applications fast and fun. But, as you know, code is executed synchronously before you can send back a response. Which means when you are generating that report from your database which has a million rows, your client has to wait for a response while your application huffs and puffs trying to get everything ready (Unless he times out, in which case you receive angry calls while you try to explain what "502 Bad Gateway" means). Sometimes you just want to make your site more responsive by pushing time consuming tasks in the background ("Your comment has been posted!" while a zmq process works in the backend adding it to your db/caching layer/pushing it to followers/creating rainbows). Wha