Skip to content

Instantly share code, notes, and snippets.

View poshboytl's full-sized avatar
🦄
You may say I'm a dreamer, but I'm not the only one...

Terry Tai poshboytl

🦄
You may say I'm a dreamer, but I'm not the only one...
View GitHub Profile
@poshboytl
poshboytl / linux-setup.sh
Created May 19, 2024 05:32 — forked from dhh/linux-setup.sh
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl btop \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
@poshboytl
poshboytl / linux-setup.sh
Created May 19, 2024 05:32 — forked from dhh/linux-setup.sh
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl btop \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
# 这个函数在做什么? 你觉得它为什么要这么做?
def compare(a, b)
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
@poshboytl
poshboytl / flatten.rb
Created February 23, 2016 09:57
Implement the ruby's flatten method.
# In Ruby we can easily use flatten method: [[1,2,[3]],4].flatten #=> [1,2,3,4] to do this work.
# I guess it requires me to implement it myself.
module Enumerable
def my_flatten
Enumerator.new do |yielder|
each do |ele|
if ele.is_a?(Enumerable)
ele.my_flatten.each do |sub|
yielder.yield(sub)
end

Setting Up Clojure on OS X

I spent a lot of time trying to find a pretty optimal (for me) setup for Clojure… at the same time I was trying to dive in and learn it. This is never optimal; you shouldn't be fighting the environment while trying to learn something.

I feel like I went through a lot of pain searching Google, StackOverflow, blogs, and other sites for random tidbits of information and instructions.

This is a comprehensive "what I learned and what I ended up doing" that will hopefully be of use to others and act as a journal for myself if I ever have to do it again. I want to be very step-by-step and explain what's happening (and why) at each step.

Step 1: Getting Clojure (1.3)

# first install erlang using the R13b04 formula
brew install https://github.com/mxcl/homebrew/raw/810d52f4a386ea9e2b837030120ffd69cad73722/Library/Formula/erlang.rb
# now you are free to install riak
brew install riak
#>>lang=cf
@Factory = Factory = {}
ids = {}
sequences = {}
sequence = (name, callback) -> sequences[name] = callback
define = (name, defaults = {}) ->
Factory[name] = (attrs = {}) ->
Request summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Parsed lines: 389
Skipped lines: 0
Parsed requests: 122
Skipped requests: 0
Warnings: teaser_check_failed: 1
First request: 2012-05-14 15:44:03
@poshboytl
poshboytl / gist:3176487
Created July 25, 2012 14:34
relative time example
<div class="post">
<time class="timeago" datetime="2012-07-18T07:51:50Z">
about 8 hours ago
</time>
</div>
<div class="comment">
<time class="timeago" datetime="2012-07-18T15:50:50Z">
about 1 minute ago
</time>
@poshboytl
poshboytl / gist:3176477
Created July 25, 2012 14:31
Rails time_ago_in_words
time_ago_in_words(item.created_at)