Skip to content

Instantly share code, notes, and snippets.

View danielpaul's full-sized avatar
🏠
Working from home

Daniel Paul danielpaul

🏠
Working from home
View GitHub Profile
@danielpaul
danielpaul / revision.java
Last active October 7, 2024 14:52
Basic Java Revision Notes - Written in 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... ||
* \ ------------------------------------------------------------------------------------------- /
*
*
* ____ _ __ ____ __
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 / csv.rake
Created May 10, 2016 17:01
Read a CSV and match details from DB and save new columns back to new CSV
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)
@danielpaul
danielpaul / socket.rb
Created August 28, 2019 22:43
Simple Ruby TCP Server
# 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
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."
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"
@danielpaul
danielpaul / anything_controller.rb
Created August 18, 2020 14:55
Rails API Controller Error Handling Pattern
class AnythingController < ApiController
def index
raise ApiError.new("My custom message", 401)
end
end
@danielpaul
danielpaul / minitest_example.rb
Last active March 4, 2021 15:55
MiniTest Example
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 / User.rb
Created April 29, 2021 10:23
Generate Unique User Referral Code
class User < ApplicationRecord
validates_length_of :first_name, :last_name, minimum: 2
validates :refferal_code, presence: true, uniqueness: true
before_validation :set_referral_code
private
@danielpaul
danielpaul / cookiechimp.css
Created September 21, 2023 13:29
CookieChimp CSS Example
/* CookieChimp consent banner */
#c-p-bn, #s-all-bn {
background: #fcd34d !important;
border: 1px solid #fcd34d !important;
color: #111827 !important;
}
#c-p-bn:hover, #s-all-bn:hover {
background: #fbbf24 !important;
border: 1px solid #fbbf24 !important;