Skip to content

Instantly share code, notes, and snippets.

View theterminalguy's full-sized avatar
🎯
Focusing

theterminalguy

🎯
Focusing
View GitHub Profile
@theterminalguy
theterminalguy / example.js
Created December 20, 2021 20:18
Live Coding
// Write a function that takes an object. The object contains a left, right and operator properties. The left and right properties are numbers. The operator property is a string. The function should return the result of the operation. The function should return null if the operator is not one of the following: +, -, *, /.
// Example:
// calculate({ left: 1, right: 2, operator: '+' }) // 3
// calculate({ left: 1, right: 2, operator: '-' }) // -1
// calculate({ left: 1, right: 2, operator: '*' }) // 2
// calculate({ left: 1, right: 2, operator: '/' }) // 0.5
// calculate({ left: 1, right: 2, operator: '%' }) // null
require 'ostruct'
def send_mail(to:, from:, subject:, body:)
puts "Sending mail to: #{to}"
puts "From: #{from}"
puts "Subject: #{subject}"
puts "Body: #{body}"
end
module FormBot
@theterminalguy
theterminalguy / hello.md
Last active February 23, 2019 12:14
hello gist

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version

  • System dependencies

def permutations(day_hours, missing_days, target)
results = []
values = (0..day_hours).to_a
size = missing_days
puts target
permuts = values.repeated_permutation(size).to_a
permuts.each do |permut|
if permut.inject(:+) == target.to_i
results.push(permut.join(','))
end
@theterminalguy
theterminalguy / web-fonts-asset-pipeline.md
Created August 12, 2018 08:41 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@theterminalguy
theterminalguy / example_activejob.rb
Last active June 8, 2018 04:05 — forked from ChuckJHardy/example_activejob.rb
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@theterminalguy
theterminalguy / tetris.html
Last active March 31, 2018 19:34
Credit goes to Martin Kleppe (https://twitter.com/aemkei?lang=en)
<body onload='setInterval(onkeydown=d=>{
for(d=d||5,(e=d.keyCode)&&(d=e%2?e%3?-1:1:5)
,t="",d=c-d,e=a|b<<d,0>d|a&b<<d&&(a=e=parseInt((a|b<<c)
.toString(d=32).replace(/v/,""),d),b=new Date%22?1:3)
,c=d,i=1;31>i;)O.innerHTML=t+=".#"[1&(1<<30|e).
toString(2)[i]]+(i++%5?"":"\n")},666,a=0,b=3,c=32)'>
<pre id=O>
" Leader
let mapleader = " "
set nocompatible " be iMproved, required
set backspace=2
set noswapfile " no swapfile
set ruler " show the cursor position all the time
set nowritebackup
set autowrite
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/simonpeterdamian/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# ZSH_THEME="robbyrussell"
module ObjectTracker
module ClassMethods
def track_method(method_name)
alias_method :"#{method_name}_without_tracking", method_name
define_method :"#{method_name}_with_tracking" do |*splat|
params = self.class.instance_method(:"#{method_name}_without_tracking").parameters.collect(&:last)
self.send(:"#{method_name}_without_tracking", *splat) # do method first
self.track_event!(method_name, Hash[*(params.zip(splat).flatten)]) # then track
end
alias_method method_name, :"#{method_name}_with_tracking"