V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  mike163  ›  全部回复第 1 页 / 共 4 页
回复总数  74
1  2  3  4  
用 mlx 是不是比 ollama 性能更好?
364 天前
回复了 mike163 创建的主题 DNS 129.29.29.29 是个大坑货,千万别用
@winterbells 是的,119.29.29.29 ,写错了
2024-10-20 09:06:59 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
一个具体的例子,用 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())
}%
2024-10-19 18:55:23 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@alexhx 现代大语言模型可以自动 用目标语言合适的模块 替换。这是真正厉害的地方。
2024-10-18 18:19:40 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@nekoharuya 以前模型能力不行。新代码质量很差。现在大模型编程能力上来了,写的代码质量比较好。
2024-10-18 18:18:36 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@aizya 没看懂,我是直接把代码扔给大模型,让塔用目标语言写一份新的
2024-10-18 17:40:44 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@njylll 1 部署,性能,并发支持等。2 实现同样功能,ruby 代码量可以是 go 的一半还少。
2024-10-18 17:04:30 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@Mark24 我知道,就是不想用 asyncore ruby ,让大语言模型帮我转成 go 只花了 1 分钟。如果用 async ,至少折腾半天。 每个语言都有自己的优势。
2024-10-18 17:02:35 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@Hopetree 就是这个意思,用了就知道爽了。
2024-10-18 15:53:39 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@yellowsky 肯定可以。不过我不写低级语言很久了,习惯用高级语言,但有时候高级语言性能不行,这时候就必须用低级语言。上面的办法就很好用了。
2024-10-18 15:46:14 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@vcbal 工程上可以把一个大框架拆成多个模块,每个模块独立实现,模块之间通过 web json 交互,这样耦合性非常好。
2024-10-18 15:44:23 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@yellowsky 低级语言写代码,效率还是比高级语言低很多。

实际上,可以把高级语言,看成是给 llm 提需求的提示,但自然语言有太多细节很难描述,不如高级语言好用。
2024-10-18 15:41:37 +08:00
回复了 mike163 创建的主题 程序员 一种快速编程的方法,推荐给大伙。
@sphawkcn 有些还是需要的,例如我用 ruby 写了一个 web 程序,但 ruby 很难支持并发,然后让语言模型翻译成 go ,并改成异步并发模型,很方便。

用感觉语言先实现业务逻辑,用低级语言提高性能。
2024-09-09 16:12:27 +08:00
回复了 zlife116 创建的主题 Apple 打破信息差 政府补贴后 东哥的 Macbook Air M3 16+256 只要 7K 出头
据说 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   ·   5251 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms · UTC 05:47 · PVG 13:47 · LAX 22:47 · JFK 01:47
♥ Do have faith in what you're doing.