Skip to content

Instantly share code, notes, and snippets.

@vjt
vjt / copy-from-time-machine.sh
Last active June 21, 2025 01:13
Copy data from a Time Machine volume mounted on a Linux box.
#!/bin/bash
#
# Copy data from a Time Machine volume mounted on a Linux box.
#
# Usage: copy-from-time-machine.sh <source> <target>
#
# source: the source directory inside a time machine backup
# target: the target directory in which to copy the reconstructed
# directory trees. Created if it does not exists.
#
@tmiller
tmiller / README.md
Last active August 30, 2024 01:22
A very simple example of using a map of channels for pub/sub in go.
@avdi
avdi / maybenull.rb
Created May 24, 2013 19:56
Pondering Null Objects and Optional Types in Ruby
# I've been thinking about Null Objects and Optional Types in Ruby lately.
# Optional Types are often defined using both a Null type and some kind of
# Proxy for non-nulls, but proxies have all sorts of subtle problems in Ruby.
# Let's say we do optional types without a proxy. E.g.:
x = Maybe("foo") # => "foo"
y = Maybe(nil) # => NullObject.instance
# In order to keep NullObjects from "leaking" into places they aren't wanted,
# we need an inverse conversion function to "collapse" values back to either
@sauloperez
sauloperez / signal_catching.rb
Last active December 14, 2024 13:43
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@keithrbennett
keithrbennett / server.rb
Last active August 9, 2019 11:39
Getting Sinatra to run alongside other threads in an app.
require 'socket'
require 'sinatra/base'
require 'pry'
puts "Ruby runtime parsing SinatraServer in main thread: #{Thread.current}"
sinatra_thread = Thread.new do
class SinatraServer < Sinatra::Application
puts "Sinatra running in thread: #{Thread.current}"
@staceysern
staceysern / irc-grammar
Created December 2, 2013 04:10
IRC protocol ABNF grammar
<MESSAGE> = *<SPACE> *1(<':'> PREFIX <1*SPACE>) COMMAND *<SPACE> *1PARAMS
PREFIX = NICKNAME
NICKNAME = (LETTER / SPECIAL) *(LETTER / DIGIT / SPECIAL / '-')
COMMAND = 1*LETTER / 3DIGIT
PARAMS = *14(1*<SPACE> MIDDLE *<SPACE>) *1(1*<SPACE> <':'> TRAILING) /
15(1*<SPACE> MIDDLE) *<SPACE>
MIDDLE = NOSPCRLFCL *(':' / NOSPCRLFCL)
TRAILING = *(':' / SPACE / NOSPCRLFCL)
<NOSPCRLFCL> = %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF
@PWSdelta
PWSdelta / ruby-open-uri-request.rb
Created December 9, 2013 17:16
4-line Ruby script that uses open-uri to fetch the contents of a URL & displays it in the console. This is the foundation for all web requests, whether to scrape a page, request a JSON response, and more.
# http://ruby-doc.org/stdlib-2.0.0/libdoc/open-uri/rdoc/OpenURI.html
require 'open-uri'
# Go fetch the contents of a URL & store them as a String
response = open('http://www.example.com').read
# "Pretty prints" the result to look like a web page instead of one long string of HTML
URI.parse(response).class
# Print the contents of the website to the console
@SteveBenner
SteveBenner / _html5video.slim
Last active June 14, 2022 05:02
Slim partial - HTML5 video tag
/ Generate an HTML5 video tag with embedded Flash fallback
/ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video HTML5 video tag spec
/
/ @local [Hash] video Attribute hash for the `video` tag
/ @option video [Integer] :width (320) Width of the video tag in pixels
/ @option video [Integer] :height (240) Height of the video tag in pixels
/
/ @local [Hash] src Mapping of source file types to URLs for source files
/ @option src [String] :mp4 URL of an MP4 source file for the video
/ @option src [String] :webm URL of a WebM source file for the video
package sergius.fun;
/**
* Based on demo http://download.oracle.com/otndocs/products/javafx/2/samples/Ensemble/index.html#SAMPLES/Scenegraph/Events/Mouse Events
* with next license:
* Copyright (c) 2008, 2012 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*/
import javafx.application.Application;
import javafx.scene.Scene;
@edubkendo
edubkendo / atom_opal.md
Last active April 19, 2018 05:09
Writing Atom Plugins in Opal (Ruby)

I want to write plugins for Atom's editor in Ruby. Opal makes this possible. Atom is one of several projects in recent times to combine Chromium with Node.js for a desktop app. While it utilizes chromium for it's gui, and boasts "[e]very Atom window is essentially a locally-rendered web page", writing Atom plugins is more like writing a server-side node.js app than a typical single-page client-side app (albeit with really awesome integration with Chrome Devtools). Opal development, on the other hand, has to-date been focused primarily on the browser use-case.

Because of this, I had to make a choice between using the opal-node package from npm, using Opal via Ruby w/ a compile step, or packaging up opal-parser.js, including it with the app, and writing in compilation on the fly. Each choice came with compromises. Using opal-node would have been easiest, just create a top level index.coffee that required opal-node, and then require in your ruby