General Programming Discussion

8011 readers
1 users here now

A general programming discussion community.

Rules:

  1. Be civil.
  2. Please start discussions that spark conversation

Other communities

Systems

Functional Programming

Also related

founded 5 years ago
MODERATORS
1
 
 

cross-posted from: https://lemmy.ml/post/25903184

I wrote a CLI tool that generates basic scaffolding for all sorts of coding projects, from Zig applications to NPM packages.

Feel free to ask questions or contribute!

2
3
8
the sudoku affair (explaining.software)
submitted 1 week ago by [email protected] to c/[email protected]
4
5
6
 
 

The GNU C Library version 2.41 is now available.

The GNU C Library is used as the C library in the GNU system and in GNU/Linux systems, as well as many other systems that use Linux as the kernel.

The GNU C Library is primarily designed to be a portable and high performance C library. It follows all relevant standards including ISO C23 and POSIX.1-2024. It is also internationalized and has one of the most complete internationalization interfaces known.

7
8
9
10
11
12
 
 

cross-posted from: https://lemmy.ml/post/25043892

I wrote a program that turns the feed it receives from your webcam in ASCII art. It's open source: you can find the code on Github.

13
14
15
21
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/[email protected]
 
 

Forgejo is a self-hosted lightweight software forge. In version 10.0: TOTP secrets were made more secure. The UI was made more accessible and reworked to improve the UX. Searching users, repositories, releases and issues was improved. Low German (Plattdüütsch) translation was completed. This is the last version to allow a transparent upgrade from Gitea v1.22 or lower.

16
17
18
19
20
21
22
23
24
25
 
 

the code

(ns index)

(defn prep-canvas []
  (let [can (js/document.createElement "canvas")
        ctx (.getContext can "2d")
        width js/window.innerWidth
        height js/window.innerHeight]
    (set! can.style "position: absolute; top: 0px; left: 0px;")
    (set! can.width width)
    (set! can.height height)
    (js/document.body.appendChild can)
    {:canvas can
     :context ctx
     :width width
     :height height}))

(defn rand [n]
  (js/Math.floor (* (js/Math.random) n)))

(defn render-snowflake [{:keys [context]} {:keys [x y size]}]
  (set! context.fillStyle "#fff")
  (set! context.font (str size "px serif"))
  (.fillText context "*" x y))

(defn snowflake-step [{:keys [height]} {:keys [x y dy] :as snowflake}]
  (set! snowflake.y (if (> y height) (- 20) (+ y dy)))
  (set! snowflake.x (+ x (- (js/Math.random) 0.5))))

(defn gen-snowflakes [n {:keys [width height]}]
  (->>
   (range n)
   (map
    (fn [_]
      (let [size (+ (rand 10) 2)
            x (rand width)
            y (rand height)]
        {:size size
         :x x
         :y y
         :dy (inc (js/Math.random 10))})))
   (doall)))

(defn animation-loop [step-fn]   
   (step-fn)
   (js/window.requestAnimationFrame (partial animation-loop step-fn)))

(defn draw-text [{:keys [context width height]} text]
  (set! context.fillStyle "#fff")
  (set! context.font "100px serif")
  (context.fillText text (* width 0.3) (* height 2/6) (* width 7/8)))

(defn draw-terrain [{:keys [context width height]} fill growing?]
  (set! context.fillStyle fill)
  (context.beginPath)
  (context.moveTo -500 (if growing? height height))
  (loop [x 0
         y (if growing?
             (- height 100)
             (- height 400))]
    (if (< x width)
      (let [x (+ x (+ 10 (rand 20)))
            y (if growing?
                (- y (rand 10))
                (+ y (rand 10)))]
        (context.lineTo x y)
        (recur x y))
      (context.lineTo (+ x 100) height)))
  (context.fill))

(let [background (prep-canvas)
      text-layer (prep-canvas)
      {:keys [context width height] :as snow} (prep-canvas)
      terrain (prep-canvas)
      snowflakes (gen-snowflakes 800 snow)]
  (background.context.fillRect 0 0 width height)
  (draw-text text-layer "Happy Holidays!")
  (draw-terrain terrain "#fff" true)
  (draw-terrain terrain "#ddd" false)
  (animation-loop
   (fn []
     (set! context.fillStyle "#000")
     (context.clearRect 0 0 width height)
     (doseq [sf snowflakes]
       (render-snowflake snow sf)
       (snowflake-step snow sf)))))
view more: next ›