Skip to content

Instantly share code, notes, and snippets.

View cwfoo's full-sized avatar

Foo Chuan Wei cwfoo

View GitHub Profile
@cwfoo
cwfoo / haiku
Created March 6, 2018 23:44 — forked from friggeri/haiku
random heroku-like name generator
haiku = ->
adjs = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",
@cwfoo
cwfoo / watermark.py
Created March 18, 2018 15:57 — forked from snay2/watermark.py
How to apply a semi-transparent watermark to an image using Python
from PIL import Image, ImageDraw
def main():
# Open the original image
main = Image.open("12voltm.jpg")
# Create a new image for the watermark with an alpha layer (RGBA)
# the same size as the original image
watermark = Image.new("RGBA", main.size)
# Get an ImageDraw object so we can draw on the image

How do I do this thing?

I'm not aware of how to use Google, how do I do this basic thing in Language X?

tagged coding, question

edited by Grammar Nazi (2.5M), asked by 1337z0r (2)

Answer 1 (12)

@cwfoo
cwfoo / TB_Chat_auth.md
Created February 20, 2020 01:12 — forked from moisseev/TB_Chat_auth.md
Using Thunderbird's Chat to connect to IRC servers requiring authentication

There are two ways to authenticate on IRC server:

  1. Identify nick with NickServ;
  2. Using the PASS command in the IRC protocol (not supported in the Thunderbird UI).

If your server or bouncer requires [2], set the following preferences as string values:

messenger.account.accountN.options.serverPassword
messenger.account.accountN.options.username
@cwfoo
cwfoo / EntityManagerProducer.java
Created February 25, 2020 06:42 — forked from daniel-shuy/EntityManagerProducer.java
JPA + CDI : @Inject EntityManager as a @RequestScoped bean
import javax.enterprise.context.Dependent;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Dependent
public class EntityManagerProducer {
@PersistenceContext(name = "persistence-unit") // name is Persistence Unit Name configured in persistence.xml
private EntityManager entityManager;
@cwfoo
cwfoo / brainfuck.lisp
Created January 14, 2021 22:56 — forked from koji-kojiro/brainfuck.lisp
brainfuck compiler written in Common Lisp (SBCL)
#!/usr/bin/sbcl --script
;;; brainfuck compiler written in Common Lisp (SBCL)
;;; author: TANI Kojiro
;;; usage: `sbcl --script brainfuck.lisp` or `chmod +x brainfuck.lisp; ./brainfuck.lisp`
(declaim ((simple-array (unsigned-byte 8) (*)) *memory*))
(defvar *memory* (make-array 30000 :element-type '(unsigned-byte 8)))
(defvar *pointer* 0)
(defvar *bf-readtable* (make-instance 'readtable))
@cwfoo
cwfoo / ex-vi-makefile.patch
Created April 3, 2021 14:47
Patch for installing ex-vi in Debian and Ubuntu
Patch for ex-vi (Release 050325, "Version 4.0 (gritter) 3/25/05").
Changes:
* Use the correct path for 'install'.
* Use ncurses instead of termlib in order to prevent the following error when
starting vi:
xterm-256color: Unknown terminal type
Visual needs addressible cursor or upline capability
To apply this patch:
$ cd ex-050325/
@cwfoo
cwfoo / unification.rkt
Last active September 22, 2021 03:05
Unification algorithm in Racket
#lang racket
;;;; Unification algorithm.
;;;; Racket implementation based on Chapter 11 of "Paradigms of Artificial
;;;; Intelligence Programming" by Peter Norvig.
;;;;
;;;; Example usage:
;;;;
;;;; (unify '(1 ?x ?y)
;;;; '(?y 2 ?y))
;;;; ;; Returns: '((?x . 2) (?y . 1))
@cwfoo
cwfoo / intersperse-intercalate.ml
Created April 23, 2021 16:09
OCaml implementation of Haskell's Data.List intersperse and intercalate.
(* OCaml implementation of Haskell's Data.List intersperse and intercalate. *)
let rec intersperse sep ls =
match ls with
| [] | [_] -> ls
| x::xs -> x :: sep :: intersperse sep xs
let intercalate = String.concat
@cwfoo
cwfoo / s-expression-comments.lisp
Last active April 15, 2022 20:30
Reader macro that implements Scheme's SRFI 62 S-expression comments in Common Lisp
;;;; Reader macro that implements Scheme's SRFI 62 S-expression comments in Common Lisp.
;;;; SRFI 62: https://srfi.schemers.org/srfi-62/srfi-62.html
;;;; Adapted from: https://stackoverflow.com/questions/69248229/reads-recursive-p-argument-when-used-inside-a-reader-macro
(eval-when (:compile-toplevel :load-toplevel :execute)
(set-dispatch-macro-character #\# #\;
(lambda (stream char n)
(declare (ignore char))
(when n
(error "No number allowed between # and ;"))