Skip to content

Instantly share code, notes, and snippets.

@matstc
matstc / borderify.rb
Created January 9, 2024 08:59
Convert letters to squared equivalents and numbers to circled equivalents
#!/usr/bin/env ruby
#
# Adds a border around all the arguments passed to this script.
#
# Example:
#
# $ borderify hello you
# => 🄷 🄴 🄻 🄻 🄾   🅈 🄾 🅄
LOOKUP_TABLE = {
@matstc
matstc / server.js
Created January 23, 2017 11:08
Simple ExpressJS server
var express = require('express')
var app = express()
app.use(express.static('.'))
app.listen(3000, function () {
console.log('App listening on port 3000!')
})
@matstc
matstc / webpack.config.js
Last active May 18, 2018 16:20
Simple webpack 2 config with ES6 modules
let webpack = require('webpack')
module.exports = {
devtool: 'inline-sourcemap',
context: __dirname,
entry: "./index.js",
output: {
path: "./js",
publicPath: '/js',
filename: "bundle.js"
@matstc
matstc / gist:d93c138ba1238c5bd38c
Created October 21, 2014 13:41
RSpec example
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should eq(0)
end
end
@matstc
matstc / gist:de6315cbb22027465152
Created October 21, 2014 13:40
Example of a single layer of abstraction
def favorite post
favorite = post.favorites.create!(user: current_user)
post.user.notify_of favorite if post.user.likes_emails?
end
@matstc
matstc / gist:9d3f2cffae739c59140a
Created October 21, 2014 13:39
Example of varying levels of abstraction
def favorite post
post.favorites.create!(user: current_user)
if post.user.email_settings.email_favorites?
UserMailer.favorite_email('Your post was favorited!',
"Good job! Your post was favorited.
#{link_to post_path(post), 'Have a look for yourself'}. \
Your friendly social networking team.").deliver
end
end
@matstc
matstc / gist:381a4521b2e5c9659813
Last active August 29, 2015 14:07
Example of late branching
def greet user
"Hello, %s!" % if user.admin?
"sir"
else
"you"
end
end
@matstc
matstc / gist:3d933b340da467c8f352
Last active August 29, 2015 14:07
Example of an eager definition
def greet user
title = if user.admin?
"sir"
else
"you"
end
"Hello, #{title}!"
end
@matstc
matstc / gist:8d693575d17f2e1e3f6c
Created October 21, 2014 13:36
Example of skinny if branch
def comment_on_popularity
if post.stars.empty?
"Your post is flying under the radar."
else
if post.stars.count > 100
"Congratulations. Your post is popular!"
elsif post.stars.count > 50
"Well done. Your post is trending."
else
"Doing well but could use a little attention."
@matstc
matstc / gist:993b82f7a5623710e6fe
Created October 21, 2014 13:35
Example of heavy if branch
def comment_on_popularity
if !post.stars.empty?
if post.stars.count > 100
"Congratulations. Your post is very popular."
elsif post.stars.count > 50
"Well done. Your post is trending."
else
"Your post is doing well but could use a little attention."
end
else