Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Daniel Paul danielpaul

🏠
Working from home
View GitHub Profile
View minitest_example.rb
require 'minitest/autorun'
class ValidPhoneNumberTest < Minitest::Test
def test_when_valid_phone_number
assert is_valid_phone_number("(123) 456-7890")
end
def test_extra_extra_number_missing_bracket
refute is_valid_phone_number("1111)555 2345")
end
@danielpaul
danielpaul / anything_controller.rb
Created Aug 18, 2020
Rails API Controller Error Handling Pattern
View anything_controller.rb
class AnythingController < ApiController
def index
raise ApiError.new("My custom message", 401)
end
end
View hello_world.rb
puts 'Hello World!'
greeting = 'Good morning!'
puts greeting
forecast = "rainy" # string
temperature = 32 # number
is_summer = true # boolean
# overwrite the existing value with a new one
forecast = "sunny"
View ask_user_name.rb
first_name = nil
print "Hello, what's your name?"
# read what the user types in
first_name = gets
puts "Welcome, #{first_name}"
puts "It's really nice to meet you."
@danielpaul
danielpaul / socket.rb
Created Aug 28, 2019
Simple Ruby TCP Server
View socket.rb
# ruby socket.rb
require 'socket' # Sockets are in standard library
class Server
def initialize(socket_port)
@server_socket = TCPServer.new(socket_port)
puts 'Started server.........'
end
@danielpaul
danielpaul / csv.rake
Created May 10, 2016
Read a CSV and match details from DB and save new columns back to new CSV
View csv.rake
namespace :csv do
desc "TODO"
# to run: rake csv:match
task match: :environment do
puts "Starting..."
csv_text = File.read('./tmp/exported-report.csv')
csv = CSV.parse(csv_text, :headers => true, :return_headers => true)
View install_psql_php.sh
PHP_VER="5.5.14"
# Check if extension exists first
php -m | grep pgsql
# Update brew and install requirements
brew update
brew install autoconf
# Download PHP source and extract
@danielpaul
danielpaul / revision.java
Last active Apr 19, 2021
Basic Java Revision Notes - Written in Java
View revision.java
/*
*
* / --------------------------------[ NUIM CS141 Java Revision ]------------------------------- \
* || Designed to easily revise everything covered in CS141 by just reading through this code. ||
* || Comments accompany almost every line of code to explain its purpose. ||
* || Some theory we need to know are included in the bottom... ||
* \ ------------------------------------------------------------------------------------------- /
*
*
* ____ _ __ ____ __