Skip to content

Instantly share code, notes, and snippets.

View schlarpc's full-sized avatar

Chaz Schlarp schlarpc

View GitHub Profile
(Get-Host).UI.RawUI.WindowTitle = "Windows PowerShell"
function Get-DirAlias ([string]$loc) {
return $loc.Replace($env:homedrive + $env:homepath, "~")
}
function prompt {
Write-Host "$env:username@$env:computername" -NoNewLine -ForegroundColor Green
Write-Host ":" -NoNewLine
Write-Host "$(Get-DirAlias($(Get-Location)))" -NoNewLine -ForegroundColor Cyan
@schlarpc
schlarpc / powershell.reg
Last active August 29, 2015 14:02
Registry settings for PowerShell on right click
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
@="Open PowerShell here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -nologo -noexit"
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open PowerShell here"
if SERVER then
AddCSLuaFile("shared.lua")
require("cvar2")
cvar2.SetFlags("sv_cheats", FCVAR_REPLICATED)
end
if CLIENT then
SWEP.PrintName = "Totally Ordinary Deagle"
SWEP.Author = "schlarpc"
SWEP.Slot = 6
@schlarpc
schlarpc / gist:a327d4aa735f961555e02cbe45c11667
Last active September 7, 2021 12:46
USB Armory libcomposite init script (RNDIS and serial)
#!/bin/bash
set -euo pipefail
GADGET_NAME=usbarmory
LANGUAGE=0x409 # English
MANUFACTURER="Inverse Path"
PRODUCT="USB Armory"
HOST_ADDRESS="1a:55:89:a2:69:42"
@schlarpc
schlarpc / dumb.py
Created October 3, 2017 23:41
slice-based time
import datetime
class GetTime(type):
def __getitem__(cls, item):
if isinstance(item, slice):
hours = item.stop if item.start is None else item.start
minutes = item.stop if item.start is not None else 0
seconds = item.step or 0
elif isinstance(item, int):
hours = item
@schlarpc
schlarpc / ify.py
Created December 4, 2017 07:43
Bad ideas in Python: monkey patching decorators on to builtin types
import ctypes
class PyObject(ctypes.Structure):
pass
PyObject._fields_ = [
('ob_refcnt', hasattr(ctypes.pythonapi, 'Py_InitModule4_64') and ctypes.c_int64 or ctypes.c_int),
('ob_type', ctypes.POINTER(PyObject)),
]
@schlarpc
schlarpc / patternal.py
Created December 4, 2017 07:46
Bad ideas in Python: something like pattern matching by abusing context managers and stack frames
import contextlib
import ctypes
import inspect
import mock
import collections
import re
import attr
import six
class MatchError(Exception):
@schlarpc
schlarpc / attrsion.py
Created December 4, 2017 07:50
Mediocre ideas in Python: serialization of attrs objects using Amazon Ion
import collections
import datetime
import decimal
import importlib
import io
import amazon.ion.core
import amazon.ion.simple_types
import amazon.ion.simpleion
import attr
import requests
import requests.models
import lxml.html
import cached_property
class LxmlResponse(requests.models.Response):
@classmethod
def use_in_session(cls, session=None):
if not session:
session = requests.Session()
# A Python 3 meta path finder for importing GitHub gists by id.
# This is a terrible idea.
# Usage:
# from gist.schlarpc import _6e0119ab5804ace6a90204137541da8e as lxmlresponse
# underscores are stripped from the gist id, but if you don't want to use that or
# if the username doesn't meet the syntax requirements then i guess you can use __import__:
# lxmlresponse = __import__('gist.schlarpc.6e0119ab5804ace6a90204137541da8e')
import importlib.abc