Skip to content

Instantly share code, notes, and snippets.

View JustinTArthur's full-sized avatar

Justin Turner Arthur JustinTArthur

View GitHub Profile
@JustinTArthur
JustinTArthur / ember_model_serializer.py
Created March 20, 2013 22:37
A Django model serializer for Django REST Framework that will serialize lists in the format that Ember.js expects in its JSONs. This is not the best way to go about this, but is a very fast way to get your stuff working. The biggest caveat is that if you use one of these serializers nested inside another with many=True, the resulting format will…
class EmberModelSerializer(serializers.ModelSerializer):
"""
A serializer that formats list data in a way that will be readable by Ember.js.
"""
@classmethod
def get_class_ember_name(cls):
type_name = cls.__name__.replace('Serializer','')
return type_name.lower()
@JustinTArthur
JustinTArthur / reverse_proxy_view.py
Last active April 15, 2024 11:43
A Django 1.4+ view function that acts as a reverse proxy. Great for testing locally or for using as a starting point to code that needs to cache or manipulate the proxied response. If one needs to proxy in production without any response manipulation, performing this in the web container (like nginx or apache) would be recommended instead of thi…
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def reverse_proxy(request):
"""
Reverse proxy for a remote service.
"""
path = request.get_full_path()
#Optionally, rewrite the path to fit whatever service we're proxying to.
app.js:
var app = angular.module('app', ['appControllers', 'appServices']);
services.js:
var services = angular.module('appServices', ['djangoRESTResources']);
services.factory('Team', ['djResource',
...
]);
// Or if you still need $resource to communicate with a different backend:
indices[scope.call(root_node)] ||= 0
set_left_and_rights.call(root_node)
end
+
+ # Set depths based on left/right nesting:
+ if column_names.map(&:to_s).include?(depth_column_name.to_s)
+ get_depths_sql = "SELECT #{quoted_table_name}.#{primary_key}, COUNT(parent.#{primary_key}) -1 AS #{quoted_depth_column_name}
+ FROM #{quoted_table_name}, #{quoted_table_name} AS parent
+ WHERE #{quoted_table_name}.#{quoted_left_column_name} BETWEEN parent.#{quoted_left_column_name} AND parent.#{quoted_right_column_name}"
+
@JustinTArthur
JustinTArthur / DjangoPassword.java
Last active June 28, 2017 21:17
Java for checking the password of a user against a typical Django user table entry
// Assumes an encoded password entry that looks like:
// pbkdf2_sha256$13000$I2fysbVVZ$6WuU/biq8RveLuiTgpLeEJ7hcqoqpkqVlpUIHWUoi9I=
String[] encodedPassword = passedInPassword.split("\\$");
int encodedIterations = Integer.parseInt(encodedPassword[1]);
byte[] encodedSalt = encodedPassword[2].getBytes(Charset.forName("UTF-8"));
String encodedHash = encodedPassword[3];
SecretKeyFactory f = null;
try {

Keybase proof

I hereby claim:

  • I am justintarthur on github.
  • I am justintarthur (https://keybase.io/justintarthur) on keybase.
  • I have a public key whose fingerprint is 9E92 D2B9 2DBF 37AC 60BB 5027 DA45 B72D 195B 2168

To claim this, I am signing this object:

@JustinTArthur
JustinTArthur / electrum_s_test.py
Created October 16, 2015 20:58
High-S vs Low-S ECDSA Signatures in Electrum <2.5
"""
Uses the same ecdsa library and hashing as Electrum <2.5 and approximates how likely a high-s
signature is to be produced.
Needs same dependencies as electrum, so can be run in the same virtualenv as electrum.
"""
import ecdsa
from random import randint
from os import urandom
@JustinTArthur
JustinTArthur / run_eb_python_script.sh
Last active February 8, 2019 23:45
Script to run a Python script in EB context
#!/bin/bash
source /opt/python/run/venv/bin/activate
source /opt/python/current/env
if [ -f /etc/elasticbeanstalk/set-ulimit.sh ]; then
source /etc/elasticbeanstalk/set-ulimit.sh
fi
exec python "$@"
@JustinTArthur
JustinTArthur / 0 - signal_wait_kernel.hsail
Last active March 22, 2022 19:50
Radeon R600 GPU Code for Signal Waiting
module &signal:1:0:$full:$large:$default;
extension "amd:gcn";
extension "IMAGE";
// Sample Kernel From Michael Körber
prog kernel &__signal_test_kernel(
kernarg_u64 %val,
kernarg_sig64 %handle_in,
kernarg_sig64 %handle_out)
@JustinTArthur
JustinTArthur / make_mac_valheim_moddable.sh
Last active October 9, 2024 20:57
Script that re-entitles the macOS Valheim app to be moddable with runtime code-injection wrappers like BepInEx. For arm64, you'd probably need to still run the app with an x86_64 emulator like Apple Rosetta 2. You may need to run with sudo to re-sign the App Store version in /Applications.
#!/usr/bin/env sh
set -e
VALHEIM_APP_PATH=${1:-"${HOME}/Library/Application Support/Steam/SteamApps/common/Valheim/valheim.app"}
BEPINEX_FRIENDLY_ENTITLEMENTS='<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.cs.allow-jit</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.device.bluetooth</key><true/><key>com.apple.security.device.usb</key><true/><key>com.apple.security.network.client</key><true/><key>com.apple.security.network.server</key><true/><key>com.apple.security.cs.allow-dyld-environment-variables</key><true/></dict></plist>'
ENTITLEMENTS_PATH='/tmp/revised_valheim_entitlements.plist'
main() {
read -p "
Re-signing and re-entitling Valheim at