Skip to content

Instantly share code, notes, and snippets.

View cmpitg's full-sized avatar
💭
I may be slow to respond.

Ha-Duong Nguyen cmpitg

💭
I may be slow to respond.
  • Finland
View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@ibdknox
ibdknox / alephNoir.clj
Created October 2, 2011 19:53
aleph and noir
(require '[noir.server :as server])
(use 'noir.core 'aleph.http 'lamina.core)
(defn async-response [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
:body "async response"}))
(defpage "/" [] "hey from Noir!")
@coolaj86
coolaj86 / how-to-publish-to-npm.md
Last active June 9, 2024 23:19
How to publish packages to NPM

Getting Started with NPM (as a developer)

As easy as 1, 2, 3!

Updated:

  • Aug, 08, 2022 update config docs for npm 8+
  • Jul 27, 2021 add private scopes
  • Jul 22, 2021 add dist tags
  • Jun 20, 2021 update for --access=public
  • Sep 07, 2020 update docs for npm version
@zobar
zobar / gist:1499822
Created December 20, 2011 01:39
Running a Cinch IRC bot on Heroku
  1. Add Heroku to your Gemfile and bundle install.
  2. Create your Heroku app. This will only work with their (currently-beta) 'cedar' stack, so you have to heroku create --stack=cedar.
  3. Create a Procfile for your bot. This tells Heroku how to run your worker. In our case, the bot is bot.rb, so the only line in the Procfile is cinch: bundle exec ./bot.rb
  4. Commit and push to Heroku.
  5. You do not want a Web worker running, so heroku scale web=0 cinch=1. This also sets up your deployments to restart the bot.
@myguidingstar-zz
myguidingstar-zz / charset-helpers.sh
Created April 10, 2012 04:47
Generate charset-table (cpp vector) for all charsets
#!/bin/sh
convertibles=('À' 'Á' 'Ả' 'Ã' 'Ạ' 'Ằ' 'Ắ' 'Ẳ' 'Ẵ' 'Ặ' 'Ă' 'Ầ' 'Ấ' 'Ẩ' 'Ẫ' 'Ậ' 'Â' 'È' 'É' 'Ẻ' 'Ẽ' 'Ẹ' 'Ề' 'Ế' 'Ể' 'Ễ' 'Ệ' 'Ê' 'Ì' 'Í' 'Ỉ' 'Ĩ' 'Ị' 'Ò' 'Ó' 'Ỏ' 'Õ' 'Ọ' 'Ồ' 'Ố' 'Ổ' 'Ỗ' 'Ộ' 'Ô' 'Ờ' 'Ớ' 'Ở' 'Ỡ' 'Ợ' 'Ơ' 'Ù' 'Ú' 'Ủ' 'Ũ' 'Ụ' 'Ừ' 'Ứ' 'Ử' 'Ữ' 'Ự' 'Ư' 'Ỳ' 'Ý' 'Ỷ' 'Ỹ' 'Ỵ' 'Đ' 'à' 'á' 'ả' 'ã' 'ạ' 'ằ' 'ắ' 'ẳ' 'ẵ' 'ặ' 'ă' 'ầ' 'ấ' 'ẩ' 'ẫ' 'ậ' 'â' 'è' 'é' 'ẻ' 'ẽ' 'ẹ' 'ề' 'ế' 'ể' 'ễ' 'ệ' 'ê' 'ì' 'í' 'ỉ' 'ĩ' 'ị' 'ò' 'ó' 'ỏ' 'õ' 'ọ' 'ồ' 'ố' 'ổ' 'ỗ' 'ộ' 'ô' 'ờ' 'ớ' 'ở' 'ỡ' 'ợ' 'ơ' 'ù' 'ú' 'ủ' 'ũ' 'ụ' 'ừ' 'ứ' 'ử' 'ữ' 'ự' 'ư' 'ỳ' 'ý' 'ỷ' 'ỹ' 'ỵ' 'đ')
#Usage: convertTo charsetName id
function convertTo() {
printf "${convertibles[$2]}" | uvconv -f UTF-8 -t $1 | hexdump -e '1/1 "%02X"'
}
#Usage: makeTable charsetName
@coderoshi
coderoshi / gist:3729593
Last active March 31, 2022 15:43
A Very Short Guide to Writing Guides

A Very Short Guide to Writing Guides

This is just a few thoughts on the topic of writing technical guides. This was intended for Basho's engineering team, but this may apply to open source projects in general.

Audience

It's commonly preached that the first step in writing is to identify your audience; to whom are you writing? This is the most well known, most repeated, and most overlooked step of writing in general and technical writing in particular. Take this document, for example. My audience is technical people who need to communicate technical information, and not teenagers, so I shy away from images of pop icons and memes. I use jargon and words like "identify" rather than "peep this".

Pronouns

@HarryR
HarryR / racket-libevent-webserver-example.rkt
Created November 8, 2012 21:26
Example of basic libevent http server in Racket using FFI
#lang racket
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-libevent (ffi-lib "libevent"))
; Event Base
(define evbase-ptr (_cpointer 'evbase))
(define-libevent event_base_new (_fun -> evbase-ptr))
(define-libevent event_base_dispatch (_fun evbase-ptr -> _void))
# Elixir v1.0
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
@cky
cky / gist:8500450
Last active June 21, 2022 02:25
Guile implementation of Clojure's `#(...)` reader macro, but using `##(...)` instead to avoid conflicting with vectors.
(use-srfis '(1 69))
(read-hash-extend #\#
(lambda (c port)
(define ht (make-hash-table eqv?))
(define (ht-ref key)
(hash-table-ref ht key (lambda ()
(define sym (gensym))
(hash-table-set! ht key sym)
sym)))
(define (hash-key x)
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active May 19, 2024 19:25
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.