Skip to content

Instantly share code, notes, and snippets.

View itdaniher's full-sized avatar

itdaniher itdaniher

  • mosslandia
View GitHub Profile
@itdaniher
itdaniher / compile.py
Last active October 28, 2023 20:33
compile python script to ELF on Linux via cython and gcc
import subprocess
import sys
import tempfile
from Cython.Compiler import Main, CmdLine, Options
in_file_name = sys.argv[1]
source = open(in_file_name).read()
out_file_name = in_file_name.replace('.py', '.out')
temp_py_file = tempfile.NamedTemporaryFile(suffix='.py', delete=False)
@itdaniher
itdaniher / imfux.py
Created January 6, 2018 04:14
imfux.py
import matplotlib
import numpy as np
import phase1
from scipy import misc
im_raw = misc.imread('image2.png')
nearest = lambda array, value: array[(np.abs(array-value)).argmin()]
im_flat = im_raw.reshape(im_raw.shape[0]*im_raw.shape[1], im_raw.shape[2])
colours_top = [x[1] for x in sorted(phase1.rle(sorted([tuple(x) for x in im_flat], reverse=True)), reverse=True)][:4]
colours_list = [tuple(x) for x in colours_top]
im_top_flat = np.array([nearest(colours_top, colour) if tuple(colour) not in colours_list else colour for colour in im_flat])
@itdaniher
itdaniher / dump_mem.py
Created January 3, 2018 15:11
find and print all strings in mapped memory for a given pid
import ctypes
import re
import sys
import glob
import os
c_ptrace = ctypes.CDLL(None).ptrace
c_pid_t = ctypes.c_int32
c_ptrace.argtypes = [ctypes.c_int, c_pid_t, ctypes.c_void_p, ctypes.c_void_p]
@itdaniher
itdaniher / elfid.py
Created January 3, 2018 15:08
archid via elftools
try:
from elftools.elf.elffile import ELFFile
except:
ELFFile = None
if ELFFile is not None:
import sys
elf_file=open(sys.argv[1], 'rb')
machine = ELFFile(elf_file).get_machine_arch().lower()
print(machine)
@itdaniher
itdaniher / nuitka compilation fail
Last active January 3, 2018 04:47
nuitka compilation fail
Nuitka:DEBUG:print.py:1 : new_expression : Using original '__file__' value.
Nuitka:DEBUG:print.py:5 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:6 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:7 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:8 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:9 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:10 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:12 : new_constant : Replaced read-only module attribute '__name__' with constant value.
Nuitka:DEBUG:print.py:12 : new_constant : Comparison of constant arguments. Predicted constant result.
Nuitka:DEBUG:print.py:13 : new_builtin_ref : Module variable 'range' found to be built-in reference.
@itdaniher
itdaniher / netutils.py
Last active December 18, 2017 04:39
netutils.py
from time import time
import socket
import fcntl
import struct
import urllib.request, urllib.error, urllib.parse
import re
import json
ip_sources = ['https://wtfismyip.com/json', 'https://canhazip.com/', 'https://icanhazip.com', 'https://vyncke.org/ip.php', 'https://www.dan.me.uk/ipinfo', 'https://ipinfo.me/', 'https://my-ip.herokuapp.com/', 'https://httpbin.org/ip', 'https://onlinebanking.tdbank.com/']
@itdaniher
itdaniher / async_wrapper.py
Created November 30, 2017 21:17
async_wrapper.py
import concurrent.futures
async def async_wrapper(loop, functional, args=(None)):
with concurrent.futures.ThreadPoolExecutor() as executor:
return await loop.run_in_executor(executor, functional, args)
@itdaniher
itdaniher / zwj
Created November 21, 2017 23:50
zero width test file - 1MB
This file has been truncated, but you can view the full file.
​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
@itdaniher
itdaniher / min-char-rnn.py
Created November 20, 2017 20:16
min-char-rnn.py for python3
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
## add comments by weixsong
## reference page [The Unreasonable Effectiveness of Recurrent Neural Networks](http://karpathy.github.io/2015/05/21/rnn-effectiveness/)
## this is a 3 layers neuron network.
## input layer: one hot vector, dim: vocab * 1
@itdaniher
itdaniher / py2-sweep-check.py
Created November 17, 2017 04:59
multithreaded python2.7 proxy checker
import sockschain
import urllib2
import time
import random
import re
import json
import requests
import pyping
import multiprocessing
import atexit