Skip to content

Instantly share code, notes, and snippets.

View banagale's full-sized avatar

Rob Banagale banagale

View GitHub Profile
@banagale
banagale / wordpress_auth_console.php
Last active March 18, 2021 18:01
Output WordPress user authentication status to console
<?php
function display_wordpress_user_auth()
{ ?>
<script>
<?php
$current_user = wp_get_current_user();
if (isset($current_user)) {
if ($current_user->ID === 0) {
echo 'console.log(\'User is anonymous\');';
} else {
const nodeRSA = require('node-rsa');
const fetch = require('node-fetch');
const publicKey = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbM2br48JS2JJy8Ajy0gy33Gu5RNAFgysUp4Mj9FqzXWg7AwdGaXc0vIAGG3vmyrP906qJpiEV1aW9GhsEGNQ9Mjmngfnu1VAKZjskVToqG1ktiXZJKSlVUfGTYj+r1lKDgd2iKt4azIzoeElk1gnLovn8zEaiCT7prHlzWWb7JgW3qp1e12e5WvSC5xX9P5iKOs6WM3qTSAX3e8qGeA9wtlHdQuDjSjWA0WlYQIFKgpoCBNZeldNxel79QgR7QKG6Oo/H4aImhDW9vXH00mGVy9QX11ngovVYPhCQWzsAo+v+Y2lAJUtFdjr2t9/mJisKxpYvpMeqVo2ZSydwBmb5'
const consumerId = 'change this to your consumer id'
const privateKey = "MIIEpAIBAAKCAQEAmzNm6+PCUtiScvAI8tIMt9xruUTQBYMrFKeDI/Ras11oOwMH\
Rml3NLyABht75sqz/dOqiaYhFdWlvRobBBjUPTI5p4H57tVQCmY7JFU6KhtZLYl2\
SSkpVVHxk2I/q9ZSg4HdoireGsyM6HhJZNYJy6L5/MxGogk+6ax5c1lm+yYFt6qd\
XtdnuVr0gucV/T+YijrOljN6k0gF93vKhngPcLZR3ULg40o1gNFpWECBSoKaAgTW\
XpXTcXpe/UIEe0ChujqPx+GiJoQ1vb1x9NJhlcvUF9dZ4KL1WD4QkFs7AKPr/mNp\
@banagale
banagale / walmart_grocery_inventory.py
Created March 16, 2021 02:21 — forked from philipjewell/walmart_grocery_inventory.py
Finding which Walmart locations nearby have inventory of a product
#!/usr/bin/python3
from datetime import datetime
import click
import requests
from py_imessage import imessage
def build_store_dict(zipcode, n):
url = f'https://www.walmart.com/grocery/v4/api/serviceAvailability?postalCode={zipcode}'
@banagale
banagale / useCustomHookDebugPattern.js
Created October 9, 2020 21:13
A pattern for outputting debug from a custom react hook
import { useEffect, useState } from "react";
export function useCustomHookDebugPattern(arg1, arg2, arg3, message, something, setSomething) {
// Watch for loop progress
const [count, setCount] = useState(1);
// Additional local state
const [prevMessageId, setPreviousMessageId] = useState(undefined);
useEffect(() => {
// Increment hook count
@banagale
banagale / zoom_utils.py
Last active August 31, 2021 22:24
Python 3.6+ Implementation of Zoom.us SDK Signature Generation
import time
import base64
import hashlib
import hmac
def generate_signature(sig_ingredients: dict) -> str:
"""Python 3.6+ implementation of Zoom Signature Generation
@banagale
banagale / postgres.log
Created August 8, 2020 18:06
Example Postgres Errors due to Nginx passive health check (random 502, intermittent 502)
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-08-07 21:04:53.734 UTC [1] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
db_1 | 2020-08-07 21:04:53.734 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-08-07 21:04:53.734 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-08-07 21:04:53.738 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-08-07 21:04:53.771 UTC [20] LOG: database system was shut down at 2020-08-07 21:04:52 UTC
db_1 | 2020-08-07 21:04:53.775 UTC [1] LOG: database system is ready to accept connections
db_1 | 2020-08-07 21:05:24.660 UTC [30] LOG: invalid length of startup packet
db_1 |
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
# When user is created, build user profile and create payinfo instance.
# See also accounts.forms.SignupForm.signup for other signup steps
if created:
profile = Profile.objects.create(user=instance)
profile.payment_info = PaymentInfo.objects.create()
try:
instance.profile.account_type = AccountType.objects.get(name='Basic')
except AccountType.DoesNotExist:
class Profile(TimeStampedModel):
user = models.OneToOneField(User, null=True, blank=True, related_name='profile', on_delete=models.CASCADE)
organization = models.ForeignKey('home.Organization', null=True, blank=True, on_delete=models.CASCADE)
personal_data = models.OneToOneField('PersonalData', null=True, blank=True, on_delete=models.CASCADE)
...
# Squash X commits with an opportunity to update the message headline and body:
git reset --soft HEAD~X &&
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
@banagale
banagale / gist:47a2163f4e9a55390bc6d5df4d8192b7
Created March 25, 2019 14:51
Registering Admin for User and profile model in one
@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
fieldsets = UserAdmin.fieldsets + (('Custom Info', {'fields': ('account_type', 'address1', 'address2', 'city', 'state', 'zip', 'phone', 'sms_consent', 'onesignal_id',)}),)
list_display = UserAdmin.list_display + ('account_type',)
list_filter = UserAdmin.list_filter + ('account_type',)
icon = '<i class="material-icons">person</i>'