Skip to content

Instantly share code, notes, and snippets.

View br3nt's full-sized avatar

br3nt

View GitHub Profile
@br3nt
br3nt / prime_number_generation.md
Last active August 21, 2023 07:37
Prime number generation in C#
@br3nt
br3nt / binary_search_js_iterative.md
Last active August 21, 2023 03:48
Binary search in JS

Features:

  • Returns the index of the search value if found, otherwise, undefined
  • No array copy
  • Iterative
function binarySearch(arr, number) {
    let start = 0
    let end = arr.length - 1
@br3nt
br3nt / backlava_js.md
Last active August 21, 2023 02:11
Backlava in Javascript

See: https://sampleprograms.io/projects/baklava/javascript/

My attempt at backlava in JS.

Fetaures and difference to other implementation:

  • memoise the spaces and stars
  • use of substr to print the number of spaces and stars
  • use of a string builder instead of string concatenation
  • the algorithm is contained within backlava()
  • backlava() returns a string rather than printing directly to the console
@br3nt
br3nt / query_language.md
Last active January 2, 2022 03:22
Ideas for SQL for structured data

Upon researching GraphQL, the question immediately came to my mind:

Why do we need another query language when we already have SQL?

A second question then came to mind:

Can we use SQL for API endpoints?

After asking this question, it now seems odd that REST style APIs would even be considered a good choice.

@br3nt
br3nt / median.js
Last active November 28, 2019 05:35
JS median and splitMedian functions
function medianSplit(array) {
let midPoint = array.length / 2
array = array.sort((a, b) => a - b)
let firstHalf = array.slice(0, Math.floor(midPoint))
let middle = array.slice(Math.floor(midPoint), Math.ceil(midPoint))[0]
let lastHalf = array.slice(Math.ceil(midPoint), array.length)
return [firstHalf, middle, lastHalf]
}
function median(array) {
@br3nt
br3nt / post-receive.rb
Last active September 16, 2019 00:23 — forked from ryanflorence/post-receive.rb
A git hook to be installed on a remote server. The remote's repo will updated when a push is made.
#!/usr/bin/env ruby
# Aside from removing Ruby on Rails specific code this is taken verbatim from
# mislav's git-deploy (http://github.com/mislav/git-deploy) and it's awesome
# - Ryan Florence (http://ryanflorence.com)
#
# Install this hook to a remote repository with a working tree, when you push
# to it, this hook will reset the head so the files are updated
if ENV['GIT_DIR'] == '.'
@br3nt
br3nt / README.md
Last active July 16, 2019 13:36
The Caves of Lemaria

One of the earliest Ruby constructs I learned about was Hash.new {|h, k| h[k] = {} }. This small one-liner is explored in many Ruby tutorials and it completely captured my imagination. I've never been able to use this in a production app as I've always found a better solution. However, one thing it might be good for is to take you on a short journey.

This journey will be interactive, so you will need to copy snippets of code into an irb or pry console. I recommend using ruby 2.6 or higher as the copy-paste functionality is better (and I havn't debugged on lower versions).

UPDATE: I've now added the caves_of_lemaria.rb script which will run through the whole adventure!

@br3nt
br3nt / README.md
Last active March 28, 2024 04:12
Ideas for a less verbose language as beautiful as Ruby

Inspiration

I really dislike repeating my self in code I really dislike writing code just to get around language limitations

Typed languages are the absolute worst for code verbosity. The need to create object upon object to wrap and transform and present data is crazy

However, I do appreciate the type checking that goes along with Typed languages. I feel dynamic languages could actually acheive this by having the compiler create virtual interfaces for

@br3nt
br3nt / sketch-never-ending.md
Created November 29, 2018 00:38 — forked from Bhavdip/sketch-never-ending.md
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

@br3nt
br3nt / secure_attribute.rb
Created November 15, 2018 04:39
Better Implementation of Rails' ActiveModel::SecurePassword
# frozen_string_literal: true
module SecureAttribute
extend ActiveSupport::Concern
# BCrypt hash function can handle maximum 72 bytes, and if we pass
# password of length more than 72 bytes it ignores extra characters.
# Hence need to put a restriction on password length.
MAX_PASSWORD_LENGTH_ALLOWED = 72