Skip to content

Instantly share code, notes, and snippets.

View fbacall's full-sized avatar

Finn Bacall fbacall

  • University of Manchester
  • Manchester, United Kingdom
View GitHub Profile
@fbacall
fbacall / list_user_and_person_fks.rb
Created November 30, 2023 13:15
Place in db directory and run via plain `ruby`
module ActiveRecord
class Schema
attr_reader :users, :people
def initialize
@people = []
@users = []
end
def self.define(*args, &block)
@fbacall
fbacall / flat.rb
Last active June 17, 2023 23:27
Add alternative stack version
# Allow iteration on a flattened Enumerable.
# e.g. [1,[2,3],[[4]]].flat.map { |x| x * 2 }
#
module Enumerable
def stack_flat_wip(&block)
return to_enum(__method__) unless block_given?
idx = [0]
curr = self
while idx.any? && curr
puts idx.inspect
@fbacall
fbacall / circular_queue.js
Created August 6, 2019 14:36
Circular Queue
class CircularQueue {
constructor (size) {
this._max = size;
this._start = 0;
this._end = 0;
this._length = 0;
this._queue = new Array(size);
}
enq (item) {
@fbacall
fbacall / enum.rb
Created July 18, 2019 10:43
Yielder & Enumerator pure Ruby example implementation
# Using standard library
fib = Enumerator.new do |y|
a = b = 1
loop do
y << a
a, b = b, a + b
end
end
p fib.take(10)
@fbacall
fbacall / t.js
Last active March 20, 2019 11:36
Easier DOM element creation
function t(type, htmlPropsOrFirstChild, ...children) {
const element = document.createElement(type);
if (htmlPropsOrFirstChild) {
if (htmlPropsOrFirstChild.constructor === Object) {
Object.assign(element, htmlPropsOrFirstChild);
} else {
children.unshift(htmlPropsOrFirstChild);
}
}
@fbacall
fbacall / gist:d53bef7da113474e6524cea9e991482d
Created October 26, 2018 09:53
Click all Doodle poll options
// Put this in JavaScript console (F12 -> "Console")
document.querySelectorAll('.d-options input').forEach(function (input) { input.click(); })
@fbacall
fbacall / github_commits.rb
Last active July 31, 2018 10:19
List all commits pushed to github this week
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
USER = 'YOUR-GITHUB-USERNAME'
# Generate a token with "repo" scope enabled: https://github.com/settings/tokens/new
TOKEN = 'YOUR-PERSONAL-ACCESS-TOKEN'
today = Date.today
@fbacall
fbacall / utf8_conversion.sql
Created August 7, 2014 08:45
Convert SEEK mySQL database to UTF-8 (as of schema version 20140625135500)
ALTER DATABASE seek_production CHARACTER SET utf8 COLLATE utf8_unicode_ci;
connect seek_production;
ALTER TABLE activity_logs CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE admin_defined_role_projects CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE annotation_attributes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE annotation_value_seeds CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE annotation_versions CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE annotations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;