TIL search: max
...MAX_ATTACHED=10",
"MAX_COLUMN=2000",
"MAX_COMPOUND_SELECT=500",
"MAX_DEFAULT_PAGE_SIZE=8192",
"MAX_EXPR_DEPTH=1000",
"MAX_FUNCTION_ARG=127",
"MAX_LENGTH=1000000000",
"MAX_LIKE_PATTERN_LENGTH=50000",
"MAX_MMAP_SIZE=0x7fff0000",
"MAX_PAGE_COUNT=1073741823",
"MAX_PAGE_SIZE=65536",
"MAX_SQL_LENGTH=1000000000",
"MAX_TRIGGER_DEPTH=1000",
"MAX_VARIABLE_NUMBER=32766",
"MAX_VDBE_OP=250000000",
"MAX...
...MAX_ATTACHED=10
MAX_COLUMN=2000
MAX_COMPOUND_SELECT=500
MAX_DEFAULT_PAGE_SIZE=8192
MAX_EXPR_DEPTH=10000
MAX_FUNCTION_ARG=127
MAX_LENGTH=1000000000
MAX_LIKE_PATTERN_LENGTH=50000
MAX_MMAP_SIZE=0x7fff0000
MAX_PAGE_COUNT=1073741823
MAX_PAGE_SIZE=65536
MAX_SQL_LENGTH=1000000000
MAX_TRIGGER_DEPTH=1000
MAX_VARIABLE_NUMBER=250000
MAX_VDBE_OP=250000000
MAX...
...That query looked like this:
```sql
with today_points as (
select
datetime,
mllw_feet
from
tide_predictions
where
date("datetime") = :p0
and "station_id" = :p1
),
min_max as (
select
min(mllw_feet) as min_feet,
max(mllw_feet) as max_feet
from
today_points
),
points as (
select
RANK () OVER (
ORDER BY
datetime
) -1 as rank,
min_max.min_feet,
min...
...Here's what that looks like:
```sql
select
repos.full_name,
(
select
max(created_at)
from
releases
where
repo = repos.id
) as max_created_at,
(
select
count(*)
from
releases
where
repo = repos.id
) as releases_count,
(
select
json_group_array(
json_object(
'id',
id,
'name',
name,
'created_at',
created_at
)
)
from
(
select
*
from
releases
where
repo = repos.id
order by...
Today I noticed that [Datasette](https://datasette.io/) wasn't serving a `Access-Control-Max-Age` header.
This meant that any `OPTIONS` CORS pre-flight requests would be repeated for every request, which hurts performance - the browser should be able to cache the result of the pre-flight request for a period of time instead.
I fixed that in [issue...
...Accept, Accept-Encoding, Origin
Link: <https://fedi.simonwillison.net/api/v1/timelines/public?local=1&max_id=109277272598366124>; rel="next", <https://fedi.simonwillison.net/api/v1/timelines/public?local=1&min_id=109288139761544382>; rel="prev"
```
The rate limit stuff is cool, but the thing that instantly caught my eye was the `Link:` header. It looks like Mastodon implements cursor-based...
...bin => {
let sorted = [...Array.from(bin).map(t => t.created_at)].sort();
let min = sorted[0];
let max = sorted.slice(-1)[0];
let count = sorted.length;
return `${sorted.length} item${
sorted.length == 0 ? '' : 's'
}\nFrom: ${min}\nTo: ${max}`;
}
}
)
)
]
})
```
- `[...bin.map(t => t.created_at)].sort()` is a recipe for creating a sorted copy of an array of values
- `max = sorted...
...I used this:
```sql
duration_open_in_seconds < CAST(:max_duration_in_seconds AS INTEGER)
```
This is the full query - [try it out here](https://github-to-sqlite.dogsheep.net/github?sql=select%0D%0A++json_object%28%0D%0A++++%27label%27%2C+repos.full_name+%7C%7C+%27+%23%27+%7C%7C+issues.number%2C%0D%0A++++%27href%27...
...Here's the JavaScript I came up with, using [Window.matchMedia()](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia):
```javascript
window.hasBeenRearrangedForMobile = false;
function rearrangeForMobile() {
// Make changes to the DOM here
}
function conditionalRearrange(m) {
if (m.matches && !window.hasBeenRearrangedForMobile) {
rearrangeForMobile();
window.hasBeenRearrangedForMobile = true;
}
}
var mediaMatcher = window.matchMedia('(max-width: 800px)');
conditionalRearrange(mediaMatcher);
mediaMatcher.addListener(conditionalRearrange);
```
[Full code...
...The final step is to group by country and group number, and to use `min()` and `max()` to find the start and end dates for each group and to calculate the number of days in each group:
```sql
...
select
country,
date(min(created)) as start,
date(max(created)) as end,
cast(
julianday(date(max(created))) -
julianday(date(min(created))) as...
...195520 (max 195776) bytes
Number of Outstanding Allocations: 525 (max 526)
Number of Pcache Overflow Bytes: 5696 (max 5696) bytes
Largest Allocation: 122400 bytes
Largest Pcache Allocation: 4104 bytes
Lookaside Slots Used: 94 (max 122)
Successful lookaside attempts: 431
Lookaside failures due to size: 4
Lookaside failures due to OOM: 0
Pager Heap Usage: 23008 bytes
Page cache hits: 6...
...curl --output /dev/null --silent --insecure --head --fail --max-time 2 $test_url
It's avoiding any output at all with a combination of writing output to `/dev/null` and using `--silent` to turn off logging.
It uses `--insecure` because our server is running with a self-signed certificate, which will produce errors without this option - and here we just...
...inputs = processor(
text=[prompt],
padding=True,
return_tensors="pt",
)
audio_values = model.generate(**inputs, max_new_tokens=num_tokens)
sampling_rate = model.config.audio_encoder.sampling_rate
scipy.io.wavfile.write(filename, rate=sampling_rate, data=audio_values[0, 0].numpy())
```
Then you can use that `save()` function like this to generate and save an audio sample:
```python
save("trumpet...
...title = models.CharField(max_length=255)
body = models.TextField()
class Meta:
indexes = [
GinIndex(
name="idx_blog_entry_body_gin",
fields=["body"],
opclasses=["gin_trgm_ops"],
),
]
```
The `opclasses=["gin_trgm_ops"]` line is necessary to have the same efect as the `CREATE INDEX` statement shown above. The `name=` option is required if you specify `opclasses`.
Run `./manage.py makemigrations` and Django...
...returning the ten closest earthquakes to a point:
```sql
SELECT
knn.distance,
quakes.title,
quakes.mag,
quakes.time,
quakes.url,
y(quakes.geometry) as latitude,
x(quakes.geometry) as longitude
FROM
knn
join quakes on knn.fid = quakes.rowid
WHERE
f_table_name = 'quakes'
AND ref_geometry = MakePoint(cast(:longitude as real), cast(:latitude as real))
AND max_items = 10
```
...zeroblob', 'hex', 'iif', 'sqlite_source_id', 'format', 'datetime', 'cume_dist', 'ln', 'instr', 'json', 'dense_rank', 'log', 'log', 'ifnull', 'current_date', 'current_time', 'lag', 'lag', 'lag', 'mod', 'log2', 'like', 'like', 'max', 'max', 'min', 'min', 'lead', 'lead', 'lead', 'log10', 'lower', 'ltrim', 'ltrim', 'first_value', 'pi', 'length', 'likely', 'json_set', 'escape_fts', 'prepare_connection_args', 'convert_units', 'sleep', 'rtreedepth', 'match', 'snippet', 'fts5_source...
...https://play.clickhouse.com/play
Now execute the following SQL, replacing my username with yours in both places where it occurs:
```sql
with public_events as (
select
created_at as timestamp,
'Private repo made public' as action,
repo_name
from github_events
where lower(actor_login) = 'simonw'
and event_type in ('PublicEvent')
),
most_recent_public_push as (
select
max(created...
...N, --offset-n N [0 ] segment index offset
-d N, --duration N [0 ] duration of audio to process in milliseconds
-mc N, --max-context N [-1 ] maximum number of text context tokens to store
-ml N, --max-len N [0 ] maximum segment length in characters
-sow, --split-on-word [false ] split on word rather than on token
-bo N, --best...
...Intializing Metal device 0, name=Apple M2 Max
USER: Write a rap battle between a pelican and a cheesecake
ASSISTANT: (Verse 1)
I'm a pelican, I'm the king of the sea
I'm a big bird with a big appetite for cheesecake
I'll be taking that piece of cheesecake right off your plate
I'll be feasting...
...0, max zoom: 15, min lon, min lat, max lon, max lat: -122.593346, 37.3739769, -122.400055, 37.570977](https://github.com/simonw/til/assets/9599/f028f997-083c-4fa4-93a2-ecfe0dca9356)
## Serving the map using Vite and maplibre-gl
I decided to build a web page that would serve an interactive version of the map.
I ended up putting...
...0.00216092, max 0.999473
0.001 sec, 2000 times normalvariate
avg -0.00286956, stddev 0.996872, min -3.42333, max 4.2012
0.001 sec, 2000 times lognormvariate
avg 1.64228, stddev 2.13138, min 0.0386213, max 34.0379
0.001 sec, 2000 times vonmisesvariate
avg 3.18754, stddev 2.27556, min 0.00336177, max 6.28306
...
```
### nntplib...
...compute buffer total size = 75.47 MB
AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | SSSE3 = 0 | VSX = 0 |
```
Now we can prompt it, feeding in the grammar object as `grammer=` and setting `max_tokens=-1` for...
...swillison-gmail-com-26
# Presumably the flyctl CLI command set this up
totalCount
nodes {
name
network
peerip
pubkey
region
}
}
}
}
```
This one returns recent logs (only for the past hour / max of 50 values - those are the highest numbers that can be used for those parameters):
```graphql
{
apps {
nodes {
name
vms {
totalCount
nodes {
recentLogs(limit: 50, range: 3600) {
id
region
message...
...Those numbers would seem to indicate that the Ethernet that is built into the walls is Cat5, which maxes out at about 100Mbps. If we had Cat5e or Cat6 those cables would likely go up to 1000Mbps instead.
After some poking around I convinced myself that this was the problem - that the cables in the walls were Cat5.
I didn...
...cache-control: no-cache, must-revalidate
openai-model: gpt-3.5-turbo-0613
openai-organization: user-r3e61fpak04cbaokp5buoae4
openai-processing-ms: 391
openai-version: 2020-10-01
strict-transport-security: max-age=15724800; includeSubDomains
x-ratelimit-limit-requests: 5000
x-ratelimit-limit-tokens: 160000
x-ratelimit-remaining-requests: 4999
x-ratelimit-remaining-tokens: 159980
x-ratelimit-reset-requests: 12ms
x-ratelimit...
...The capital of France is Paris
""".strip()
action_re = re.compile('^Action: (\w+): (.*)$')
def query(question, max_turns=5):
i = 0
bot = ChatBot(prompt)
next_prompt = question
while i < max_turns:
i += 1
result = bot(next_prompt)
print(result)
actions = [action_re.match(a) for a in result.split('\n') if action_re.match(a)]
if actions:
# There is an...
...X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
'access-control-allow-origin': '*',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'x-frame-options': 'deny',
'x-content-type-options': 'nosniff',
'x-xss-protection': '1; mode=block',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin...
...It will end up producing something like this:
```
Type Name # reqs # fails | Avg Min Max Med | req/s failures/s
--------|----------------------------------------------------------------------------|-------|-------------|-------|-------|-------|-------|--------|-----------
GET /fixtures/sortable 475 0(0.00%) | 169 110 483 170 | 23.58 0.00
--------|----------------------------------------------------------------------------|-------|-------------|-------|-------|-------|-------|--------|-----------
Aggregated 475 0(0.00%) | 169 110 483 170 | 23.58 0.00
Response time percentiles (approximated)
Type Name 50% 66% 75% 80% 90% 95...
...sans-serif;
max-width: 40em;
margin: 1em auto;
}
</style>
</head>
<body>
<h1>Redirecting to https://example.com</h1>
<p>This document has moved!</p>
<p>Redirecting to <a href="https://example.com">https://example.com</a> in 0 seconds.</p>
</body>
</html>
```
I figured this out from [codepo8/github-redirection-demo/](https://github.com/codepo8/github-redirection-demo/) (which uses...
...name = models.CharField(max_length=50)
slug = models.SlugField()
def __str__(self):
return self.name
class Entry(models.Model):
title = models.CharField(max_length=200)
created = models.DateTimeField(default=timezone.now)
slug = models.SlugField()
summary = models.TextField()
body = models.TextField()
card_image = models.URLField(
blank=True, null=True, help_text="URL to image for social media cards"
)
authors = models.ManyToManyField...
...entry["created"]} for entry in entries
]
rag.index(
collection=entry_texts,
document_ids=entry_ids,
document_metadatas=entry_metadatas,
index_name="blog",
max_document_length=180,
split_documents=True
)
if __name__ == "__main__":
go()
```
I downloaded the 81.7MB `simonwillisonblog.db` file [from the bottom of this page](https://datasette.simonwillison.net/simonwillisonblog).
The above code is lightly adapted from an...
...timeouts and memory limits
I haven't implemented this yet, but for memory limits I plan to use the following:
```bash
deno run --v8-flags='--max-heap-size=20' ...
```
This should set the maximum heap size to 20MB. The Deno process will crash if that is exceeded, which is why my Python code restarts the process if it is not...
...https://www.niche-museums.com/browse/museums.json?_facet_size=max&country=United+States&_facet=osm_city&_facet=updated&_facet=osm_suburb&_facet=osm_footway&osm_city=Santa+Cruz
responseSize: '6403'
serverIp: 142.250.125.121
status: 200
userAgent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
insertId: 611171fe000a38a469d59595
labels:
instanceId: 00bf4bf02dab164592dbbb9220b56c3ce64cb0f1c1f37812d1d61e851a931e9964ba539c2ede42886773c82662cc28aa858749d2697f537ff7a61e7b
service: niche-museums...
...json
import re
fp = open("input.nl-json", "w")
tag_re = re.compile('<.*?>')
url = "https://datasette.simonwillison.net/simonwillisonblog/blog_entry.json?_col=title&_col=body&_shape=objects&_size=max"
while url:
data = httpx.get(url).json()
for item in data["rows"]:
title = item["title"]
body = tag_re.sub('', item["body"])
fp.write(json.dumps([title, body]) + "\n")
url = data...
...url = "https://datasette.simonwillison.net/simonwillisonblog/blog_blogmark.json?_size=max&_shape=objects"
while url:
data = httpx.get(url, timeout=10).json()
yield from data["rows"]
url = data.get("next_url")
print(url)
blogmarks = list(get_blogmarks())
```
For each one I need some text - I decided to concatenate the `link_title` and `commentary` fields together:
```python
texts = [
bm["link_title...
...url │ size │
│ type │ varchar │ BYTE_ARRAY │ … │ INT64 │ BYTE_ARRAY │ INT64 │
│ stats_min │ varchar │ │ … │ 256 │ │ 312 │
│ stats_max │ varchar │ │ … │ 9408 │ │ 17937790 │
│ stats_null_count │ int64 │ 0 │ … │ 0 │ 0 │ 0 │
│ stats_distinct_count │ int64 │ │ … │ │ │ │
│ stats_min_value │ varchar │ 1089054097631629352 │ … │ 256 │ https://cdn.discor… │ 312 │
│ stats_max_value │ varchar │ 1144508197969854484 │ … │ 9408 │ https://cdn.discor… │ 17937790 │
│ compression │ varchar │ SNAPPY │ … │ SNAPPY │ SNAPPY │ SNAPPY │
│ encodings │ varchar...