Skip to content

Instantly share code, notes, and snippets.

View peterdresslar's full-sized avatar
🌊

Peter Dresslar peterdresslar

🌊
View GitHub Profile
@peterdresslar
peterdresslar / get_attn_head_entropy.py
Created April 15, 2026 19:45
Quick example of attention head entropy
import torch
attentions = [
# ========================== LAYER 0 ==========================
torch.tensor([
[ # <--- Start of Batch Item 0
# ---------------------------------------------------
# HEAD 0
# A "focused" head: The last token looks mostly at "cat"
@peterdresslar
peterdresslar / float-flatteners.py
Last active February 25, 2025 22:06
Tired of out-of-control floating point expansion wrecking your model telemetry?
# float-flattener.py
"""
Float rounding utilities for agent-based model telemetry. The slightly tricky part is that
different outputs require different solutions.
Simple utility functions to maintain consistent precision in model outputs:
- round4(): Rounds floats to 4 decimal places (for CSV)
- format4(): Formats floats to 4 decimal places with trailing zeros (for JSON)
@peterdresslar
peterdresslar / example.lib.js
Created December 14, 2021 05:36
example fix #16 angband-webclient
var data= ["pos","angband","frog","alex"];
var angband = 'angband';
data.sort();
if (data.some(e => e === angband)) {
/* data contains angband */
data.sort(function(x,y){ return x == angband ? -1 : y == angband ? 1 : 0; });
}
console.log(data);
@peterdresslar
peterdresslar / lodashtest.js
Last active October 6, 2020 03:00
Quick personal lodash tester
//Credit: https://stackoverflow.com/questions/25047463/group-by-and-sum-using-underscore-lodash/45287338
var _ = require('lodash');
const data = [
{
shape: 'foo',
sides: 15,
len: 4
},
@peterdresslar
peterdresslar / listing_tools.js
Created June 3, 2020 08:02
Kreezalid API Nodejs Axios Example
const dotenv = require("dotenv");
dotenv.config();
const apiUser = process.env["KREEZALID_USER_ID"];
const apiSecret = process.env["KREEZALID_USER_SECRET"];
const axios = require("axios");
var options = {
order_type_url_token: "8drhwt0y3f",
category_id: 21842,
user_id: 35682,
  1. Getting Started
  2. Really Getting Started
  3. Wait did we start?
  4. It Appears So.
  5. Also in this timeline we are started
  6. Foo.
  7. And finally Bar.
@peterdresslar
peterdresslar / getAgoString
Last active December 4, 2016 17:08
Java readable time ago
public static String getAgoString(Date occurrence) {
try {
Date now = new Date();
long duration = now.getTime() - occurrence.getTime();
long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
long hours = TimeUnit.MILLISECONDS.toHours(duration);
long days = TimeUnit.MILLISECONDS.toDays(duration);
if (days > 180) {
return " billions and billions of years ago";
}
package com.gwtplatform.samples.tab.client.application.dialog;
import javax.inject.Inject;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.Tab;
import com.gwtplatform.mvp.client.TabData;
var senatedataset= [{ age: 38, value: 0.00},
{ age: 39, value: 0.00},
{ age: 40, value: 0.01},
{ age: 41, value: 0.01},
{ age: 42, value: 0.03},
{ age: 43, value: 0.01},
{ age: 44, value: 0.00},
{ age: 45, value: 0.02},
{ age: 46, value: 0.00},
{ age: 47, value: 0.01},