FjordWarden
FjordWarden
DDeno
Created by FjordWarden on 9/21/2024 in #help
Import PyTorchJS
I wanted to try pytorch with js but I am running into some problems importing the NPM package. Maybe someone here know more.
> import * as pytorch from 'npm:pytorchjs'
Initialize ⣯ [00:02]
- pytorchjs@0.1.5


Warning npmlog@4.1.2 is deprecated: This package is no longer supported.
Warning npmlog@1.2.1 is deprecated: This package is no longer supported.
Warning are-we-there-yet@1.1.7 is deprecated: This package is no longer supported.
Warning gauge@2.7.4 is deprecated: This package is no longer supported.
Warning are-we-there-yet@1.0.6 is deprecated: This package is no longer supported.
Warning fstream@1.0.12 is deprecated: This package is no longer supported.
Initialize ⣟ [00:02] 216/220cated: This package is no longer supported.
- lcid@1.0.0
- is-fullwidth-code-point@1.0.0: Glob versions prior to v9 are no longer supported
- string_decoder@1.3.0.0 is deprecated:
Uncaught Error: Could not locate the bindings file. Tried:
→ /Users/me/Code/node_modules/.deno/@arition+torch-js@0.14.0/node_modules/@arition/torch-js/build/torch-js.node
> import * as pytorch from 'npm:pytorchjs'
Initialize ⣯ [00:02]
- pytorchjs@0.1.5


Warning npmlog@4.1.2 is deprecated: This package is no longer supported.
Warning npmlog@1.2.1 is deprecated: This package is no longer supported.
Warning are-we-there-yet@1.1.7 is deprecated: This package is no longer supported.
Warning gauge@2.7.4 is deprecated: This package is no longer supported.
Warning are-we-there-yet@1.0.6 is deprecated: This package is no longer supported.
Warning fstream@1.0.12 is deprecated: This package is no longer supported.
Initialize ⣟ [00:02] 216/220cated: This package is no longer supported.
- lcid@1.0.0
- is-fullwidth-code-point@1.0.0: Glob versions prior to v9 are no longer supported
- string_decoder@1.3.0.0 is deprecated:
Uncaught Error: Could not locate the bindings file. Tried:
→ /Users/me/Code/node_modules/.deno/@arition+torch-js@0.14.0/node_modules/@arition/torch-js/build/torch-js.node
1 replies
DDeno
Created by FjordWarden on 10/26/2023 in #help
Multiple subdomains
How can I listen for incoming http request on multiple subdomains?
3 replies
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
I want to use a websocket in one of my middlewares. But I keep getting an error saying I can't upgrade my connection:
[uncaught application error]: TypeError - Invalid Header: 'upgrade' header must contain 'websocket'
[uncaught application error]: TypeError - Invalid Header: 'upgrade' header must contain 'websocket'
I've googled this error but only find old results relating this error to the version of deno or oak lib where I run the latest deno (1.37.2) and oak (12.6.1).
import {Application,Router} from 'https://deno.land/x/oak@v12.6.1/mod.ts'

function RefreshMiddleware() {
return async (ctx,next) => {
console.log('url',ctx.request.url.href)
if (ctx.request.url.href.endsWith("/refresh")) {
console.log(ctx.isUpgradable);
console.log(ctx.request.headers.get("connection"));
const socket = ctx.upgrade()
} else next()
}
}

const app = new Application()
app.addEventListener("error", e => console.error(e.error))

// Logger
app.use(async (ctx, next) => {
const start = Date.now()
await next()
console.log(`${ctx.request.method} ${ctx.request.url} - ${Date.now() - start}ms`)
})
app.use(RefreshMiddleware())
app.use((ctx) => {ctx.response.body = "Hello World!"})

await app.listen({port: 8000})
import {Application,Router} from 'https://deno.land/x/oak@v12.6.1/mod.ts'

function RefreshMiddleware() {
return async (ctx,next) => {
console.log('url',ctx.request.url.href)
if (ctx.request.url.href.endsWith("/refresh")) {
console.log(ctx.isUpgradable);
console.log(ctx.request.headers.get("connection"));
const socket = ctx.upgrade()
} else next()
}
}

const app = new Application()
app.addEventListener("error", e => console.error(e.error))

// Logger
app.use(async (ctx, next) => {
const start = Date.now()
await next()
console.log(`${ctx.request.method} ${ctx.request.url} - ${Date.now() - start}ms`)
})
app.use(RefreshMiddleware())
app.use((ctx) => {ctx.response.body = "Hello World!"})

await app.listen({port: 8000})
11 replies
DDeno
Created by FjordWarden on 9/29/2023 in #help
BDD with async tests
I'd like to run some tests that all call the same helper function that wraps the bdd it function. Something like this:
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
It works with a non-async version but I'd like to know how to do this in a async way.
3 replies
DDeno
Created by FjordWarden on 9/17/2023 in #help
Can't import typescript module
Why can I only import the js file and not the ts file?
import * as zip from "https://deno.land/x/zipjs@v2.7.29/index.js"
import * as zipjs from "https://deno.land/x/zipjs@v2.7.29/index.d.ts";

zipjs.Writer //undefined
zip.ZipWriter //[class ZipWriter]
import * as zip from "https://deno.land/x/zipjs@v2.7.29/index.js"
import * as zipjs from "https://deno.land/x/zipjs@v2.7.29/index.d.ts";

zipjs.Writer //undefined
zip.ZipWriter //[class ZipWriter]
3 replies
DDeno
Created by FjordWarden on 9/6/2023 in #help
Read CSV files inside zip file using the web streams API
I need to read a number of csv files inside a zip file. The basic example I've got working so far is the following:
import {BlobReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/std@0.201.0/csv/mod.ts'

const srcFile = await Deno.open('/data.zip')
const zipReader = new ZipReader(srcFile)
for (let entry of (await zipReader.getEntries())) {
console.log('filename ', entry.filename)
let csvStream = new CsvParseStream({skipFirstRow:false,columns:undefined})
if (entry.filename.startsWith('code')) {
await entry.getData(csvStream.writable)
for await (const chunk of csvStream.readable) {
console.log(chunk)
}
}
}
import {BlobReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/std@0.201.0/csv/mod.ts'

const srcFile = await Deno.open('/data.zip')
const zipReader = new ZipReader(srcFile)
for (let entry of (await zipReader.getEntries())) {
console.log('filename ', entry.filename)
let csvStream = new CsvParseStream({skipFirstRow:false,columns:undefined})
if (entry.filename.startsWith('code')) {
await entry.getData(csvStream.writable)
for await (const chunk of csvStream.readable) {
console.log(chunk)
}
}
}
The problem is that the chunk is some weird array of strings of numbers and not the row I would expect.
[ "34", "67", "97", ...1356838 more items
[ "34", "67", "97", ...1356838 more items
Any help would be welcome.
2 replies
DDeno
Created by FjordWarden on 7/9/2023 in #help
Sanitize multiple test steps
Is it possible to sanitize multiple steps inside of one test. I want to test my DB with somthing like this:
test('db', {permissions:{net:true,env:true},sanitizeOps:false,sanitizeResources:false}, async t=>{
await testDB(async sql => {
assertOk(await ddl(sql))
await sql`insert into task values ${sql(task)}`
t.step('popTask', async ()=>assertEquals((await popTask(sql)).ok[0], task))
t.step('upsertFiling', async ()=>assertOk(async()=>await upsertFiling(sql, {id:1})))
})
})
test('db', {permissions:{net:true,env:true},sanitizeOps:false,sanitizeResources:false}, async t=>{
await testDB(async sql => {
assertOk(await ddl(sql))
await sql`insert into task values ${sql(task)}`
t.step('popTask', async ()=>assertEquals((await popTask(sql)).ok[0], task))
t.step('upsertFiling', async ()=>assertOk(async()=>await upsertFiling(sql, {id:1})))
})
})
But I get this error Started test step while another test step with sanitizers was running:
5 replies
DDeno
Created by FjordWarden on 6/15/2023 in #help
Deno hangs on error
Why does Deno hang when XML.parse throws an error?
let text = '<xml><xbrli:xbrl><hi>Hello</hi></xbrli:xbrl></xml>'
import * as XML from "https://deno.land/x/xml/mod.ts"

let parseXml = text => {
try{
return XML.parse(text)
}catch(e){
return null
}
};

parseXml(text)
console.log('ok')
try{
parseXml('fail')
}catch(e){
console.log(e)
}
let text = '<xml><xbrli:xbrl><hi>Hello</hi></xbrli:xbrl></xml>'
import * as XML from "https://deno.land/x/xml/mod.ts"

let parseXml = text => {
try{
return XML.parse(text)
}catch(e){
return null
}
};

parseXml(text)
console.log('ok')
try{
parseXml('fail')
}catch(e){
console.log(e)
}
2 replies