V2EX mike163 的所有回复 第 1 页 / 共 4 页
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX    mike163    全部回复第 1 页 / 共 4 页
回复总数  74
1  2  3  4  
用 mlx 是不是比 ollama 性能更好?
345 天前
回复了 mike163 创建的主题 DNS 129.29.29.29 是个大坑货,千万别用
@winterbells 是的,119.29.29.29 ,写错了
一个具体的例子,用 ruby 写一个一个 自动生成 图片压缩的服务, 然后 转换成 go

require 'sinatra'
require 'open-uri'
require 'rmagick'
require 'time'


# Initialize cache
$image_cache = {}

# Cleanup task to remove stale cache entries
Thread.new do
loop do
sleep 8 * 60 * 60 # Sleep for 24 hours
current_time = Time.now
$image_cache.delete_if do |url, entry|
current_time - entry[:last_accessed] > 24 * 60 * 60
end
end
end

get '/' do
# Get the URL parameter
url = params['url']

# Ensure the URL is provided
halt 400, 'URL parameter is missing' if url.nil?

# Check cache for the image
if $image_cache.key?(url)
entry = $image_cache[url]
entry[:last_accessed] = Time.now
content_type 'image/jpeg'
return entry[:image_data]
end

# Fetch the image from the URL
begin
image_data = URI.open(url).read
rescue => e
halt 500, "Failed to fetch image: #{e.message}"
end

# Read the image data using RMagick
begin
image = Magick::Image.from_blob(image_data).first
rescue => e
halt 500, "Failed to read image: #{e.message}"
end

# Resize the image while maintaining the aspect ratio
begin
resized_image = image.change_geometry("360") do |cols, rows, img|
img.resize(cols, rows)
end
rescue => e
halt 500, "Failed to resize image: #{e.message}"
end

# Convert the resized image to a blob
resized_image_data = resized_image.to_blob

begin
# Convert the resized image to a blob
resized_image_data = resized_image.to_blob
rescue Magick::ImageMagickError => e
puts "Error: #{e.message}"
puts "Backtrace: #{e.backtrace.join("\n")}"
end

# Store the resized image in the cache
$image_cache[url] = {
image_data: resized_image_data,
last_accessed: Time.now
}

# Send the resized image data to the user
content_type 'image/jpeg'
resized_image_data
end%

转换后的代码,

package main

import (
"bytes"
"fmt"
"image"
"image/jpeg"
"log"
"net/http"
"sync"
"time"

"github.com/nfnt/resize"
)

const (
port = 8300
cacheCleanupInterval = 8 * time.Hour
cacheExpiratiOnTime= 24 * time.Hour
)

type CacheEntry struct {
ImageData []byte
LastAccessed time.Time
}

var (
imageCache = make(map[string]*CacheEntry)
cacheMutex sync.RWMutex
)

func main() {
go cleanupCache()

http.HandleFunc("/", handleRequest)
log.Printf("Server starting on port %d", port)
log.Fatal( http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}

func cleanupCache() {
for {
time.Sleep(cacheCleanupInterval)
currentTime := time.Now()
cacheMutex.Lock()
for url, entry := range imageCache {
if currentTime.Sub(entry.LastAccessed) > cacheExpirationTime {
delete(imageCache, url)
}
}
cacheMutex.Unlock()
}
}

func handleRequest(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
if url == "" {
http.Error(w, "URL parameter is missing", http.StatusBadRequest)
return
}

cacheMutex.RLock()
if entry, ok := imageCache[url]; ok {
entry.LastAccessed = time.Now()
cacheMutex.RUnlock()
w.Header().Set("Content-Type", "image/jpeg")
w.Write(entry.ImageData)
return
}
cacheMutex.RUnlock()


log.Printf("Fetching image: %v\n", url)

resp, err := http.Get(url)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to fetch image: %v", err), http.StatusInternalServerError)
return
}
defer resp.Body.Close()

img, _, err := image.Decode(resp.Body)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to decode image: %v", err), http.StatusInternalServerError)
return
}

resizedImg := resize.Resize(360, 0, img, resize.Lanczos3)

var buf bytes.Buffer
if err := jpeg.Encode(&buf, resizedImg, nil); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode resized image: %v", err), http.StatusInternalServerError)
return
}

cacheMutex.Lock()
imageCache[url] = &CacheEntry{
ImageData: buf.Bytes(),
LastAccessed: time.Now(),
}
cacheMutex.Unlock()

w.Header().Set("Content-Type", "image/jpeg")
w.Write(buf.Bytes())
}%
@alexhx 现代大语言模型可以自动 用目标语言合适的模块 替换。这是真正厉害的地方。
@nekoharuya 以前模型能力不行。新代码质量很差。现在大模型编程能力上来了,写的代码质量比较好。
@aizya 没看懂,我是直接把代码扔给大模型,让塔用目标语言写一份新的
@njylll 1 部署,性能,并发支持等。2 实现同样功能,ruby 代码量可以是 go 的一半还少。
@Mark24 我知道,就是不想用 asyncore ruby ,让大语言模型帮我转成 go 只花了 1 分钟。如果用 async ,至少折腾半天。 每个语言都有自己的优势。
@Hopetree 就是这个意思,用了就知道爽了。
@yellowsky 肯定可以。不过我不写低级语言很久了,习惯用高级语言,但有时候高级语言性能不行,这时候就必须用低级语言。上面的办法就很好用了。
@vcbal 工程上可以把一个大框架拆成多个模块,每个模块独立实现,模块之间通过 web json 交互,这样耦合性非常好。
@yellowsky 低级语言写代码,效率还是比高级语言低很多。

实际上,可以把高级语言,看成是给 llm 提需求的提示,但自然语言有太多细节很难描述,不如高级语言好用。
@sphawkcn 有些还是需要的,例如我用 ruby 写了一个 web 程序,但 ruby 很难支持并发,然后让语言模型翻译成 go ,并改成异步并发模型,很方便。

用感觉语言先实现业务逻辑,用低级语言提高性能。
据说 m3 air 发热很厉害,实际情况如何
2024-09-03 19:11:42 +08:00
回复了 mike163 创建的主题 分享创造 写了一个 rss 新闻聚合站点,欢迎大家来玩
@sutking 一键标记为全读功能已经做好了,在左下角,点击用户名,会弹出菜单,里面有个 Mark All Read.
2024-08-28 16:22:15 +08:00
回复了 zhoushuo 创建的主题 汽车 小鹏刚发布的 MONA M03 怎么样?
这个价位,这个续航, 这个颜值, 不错了. 别拿比它贵 几万 十万的车比较,要比和同价位的比. 不同价位的车没有可比性.
2024-08-28 16:18:15 +08:00
回复了 zxkxhnqwe123 创建的主题 深圳 国庆去深圳转转,能告诉哪里逛吃逛吃的地方吗?
吃的话,确实广州 佛山 顺德 东莞 珠海都比深圳强太多. 玩的话,可以去海边。海滩还行. 顺便吃个海鲜. 然后去 hk 比较方便/
2024-08-25 19:20:16 +08:00
回复了 mike163 创建的主题 分享创造 发布一下 rss new reader 手机版本更新.
@pianoer88 多谢鼓励。可以加 https://t.me/rssaggreg 反馈问题。
1  2  3  4  
关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     872 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 25ms UTC 21:48 PVG 05:48 LAX 14:48 JFK 17:48
Do have faith in what you're doing.
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86