Skip to content

Instantly share code, notes, and snippets.

@gradetwo
gradetwo / test_needle.py
Last active January 30, 2024 14:27
needle test
import json
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
story = ""
question = ""
model_id = "namespace-Pt/activation-beacon-llama2-7b-chat"
# long context
with open("data/book/dinosaurs.txt", encoding="utf-8") as f:
story_all = f.read()
story_all = story_all[:108448] #32k
@gradetwo
gradetwo / __init__.py
Last active February 19, 2023 06:56
Connection Pool in redis python client redis-py
import redis
class RedisStorage(object):
_redis_pool = {}
@classmethod
def setup_redis_pool(cls, redis_pool):
for k, v in redis_pool.iteritems():
cls._redis_pool[k] = redis.Redis(v[0], v[1])
@gradetwo
gradetwo / kmem_reader.c
Last active December 19, 2015 06:09
kernel mem reader
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach_traps.h>
#include <mach/mach_init.h>
#include <mach/mach_error.h>
void hexToBytes(const char* hex, uint8_t** buffer, size_t* bytes) {
*bytes = strlen(hex) / 2;
*buffer = (uint8_t*) malloc(*bytes);
@gradetwo
gradetwo / GFWDetector.py
Created January 23, 2013 07:00
Use special domains (eg. twitter.com) to trigger GFW DNS Poisoning, detecting it's deployment by incr TTL
#!/usr/bin/env python
import logging
from scapy.all import *
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
fakeip = ["4.36.66.178", "8.7.198.45", "37.61.54.158", "46.82.174.68", "59.24.3.173", "64.33.88.161", "64.33.99.47", "64.66.163.251", "65.104.202.252", "65.160.219.113", "66.45.252.237", "72.14.205.104", "72.14.205.99", "78.16.49.15", "93.46.8.89", "128.121.126.139", "159.106.121.75", "169.132.13.103", "192.67.198.6", "202.106.1.2", "202.181.7.85", "203.161.230.171", "207.12.88.98", "208.56.31.43", "209.145.54.50", "209.220.30.174", "209.36.73.33", "211.94.66.147", "213.169.251.35", "216.221.188.182", "216.234.179.13"]
testdomain = ["twitter.com", "facebook.com", "youtube.com"]
dnshost = "8.8.8.8"
for h in testdomain:
'''
Copyright 2010 Josiah Carlson
Released into the public domain
copy_redis.py
A convenient utility function for copying data from one redis server to
another.
Requires http://github.com/andymccurdy/redis-py .