Skip to content

Instantly share code, notes, and snippets.

View jpic's full-sized avatar
💾
Searching for my Monkey Island II floppy disks

Yacht Shaver jpic

💾
Searching for my Monkey Island II floppy disks
View GitHub Profile
# Save as proxy2.py on your LOCAL machine
import socket
import threading
from socketserver import ThreadingMixIn, TCPServer, StreamRequestHandler
class SOCKSProxyHandler(StreamRequestHandler):
def handle(self):
print("New connection")
# Read initial byte to determine SOCKS version
version = self.connection.recv(1)
import anyio
from anyio import Path
from tree_sitter_language_pack import get_language, get_parser
import os
from typing import Dict, Optional
async def scan_file(file_path: str, language_extensions: dict) -> tuple[str, Optional[dict]]:
"""Scan a single file and return its parsed data."""
ext = os.path.splitext(file_path)[1]
for lang, exts in language_extensions.items():
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter
def render_markdown_to_console(markdown_text):
lines = markdown_text.split('\n')
in_code_block = False
current_language = None
code_buffer = []
@jpic
jpic / apfbase.py
Created September 18, 2024 12:58
Base action plugin class for ansible
import fcntl
import hashlib
import os
import re
import subprocess
from ansible.plugins.action import ActionBase, display
from ansible.plugins.filter.core import to_nice_yaml
import copy
import math
def box(remaining, capacity):
if len(remaining) >= capacity:
weights = [b.item_weight for b in remaining[:capacity]]
return sum(weights)
@jpic
jpic / shlaxfile.py
Last active October 31, 2020 05:44
Parallel npm + pip container build + pod management
#!/usr/bin/env python
"""
Shlaxfile for shlax itself.
"""
from shlax.shortcuts import *
env = dict(
DJANGO_SETTINGS_MODULE='ylserver.settings',
UWSGI_MODULE='ylserver.wsgi:application',
@jpic
jpic / aoeu
Created July 20, 2019 01:36
aoeu
aoeu
@jpic
jpic / fearme.out
Created February 14, 2019 03:44
ansible-compose
14/02 2019 04:39:23 jpic@jpic ~/src/ansible-compose (master)
$ ansible-compose [email protected]/home/jpic/bar stop
Running ssh [email protected] bash -euxc 'cd /home/jpic/bar; docker-compose stop'
+ cd /home/jpic/bar
+ docker-compose stop
@jpic
jpic / ObsceneAnsible
Created September 29, 2018 04:16
Help displays without argument for the playlabs command
29/09 2018 06:13:36 jpic@jpic ~/src/playlabs/playlabs/inventory_template (master)
$ playlabs
Playlabs: the obscene ansible distribution.
Init your ssh user with your key and secure sshd and passwordless sudo:
playlabs init [email protected]
# all options are ansible options are proxied
playlabs init @somehost --ask-become-pass
@jpic
jpic / import_callback.py
Created August 28, 2018 16:54
Import any python callback
"""
Currently with django we can only import an attribute from a module, not a sub-attribute. For example
import_string('foo.models.YourModel') # works
import_string('foo.models.YourModel.objects.update_stats') # doesn't
This snippet fixes that, originally for django-call which has tests.