Skip to content

Instantly share code, notes, and snippets.

View jacobwalkr's full-sized avatar

jacob jacobwalkr

  • On The Beach
  • Sheffield
View GitHub Profile
@jacobwalkr
jacobwalkr / date_time_splittable.rb
Last active February 9, 2021 17:18
ActiveRecord concern for accessing the date and time parts of a datetime attribute separately
module DateTimeSplittable
extend ActiveSupport::Concern
included do
def self.split_date_time(*attributes)
attributes.each do |attribute|
if self.type_for_attribute(attribute).type != :datetime
raise ArgumentError.new("#{attribute} is not of type datetime")
end
.callout {
padding: 1.25rem;
margin-top: 1.25rem;
margin-bottom: 1.25rem;
border: $card-border-width solid $card-border-color;
border-left-width: .25rem;
@include border-radius($card-border-radius);
h2,h3,h4,h5 {
margin-top: 0;
@jacobwalkr
jacobwalkr / 00000000000000_convert_to_gutentag.gutentag.rb
Created February 16, 2018 11:54
Converts an ActsAsTaggableOn database structure for use with Gutentag
# frozen_string_literal: true
# adapted from Gutentag's install migrations
# https://github.com/pat/gutentag
superclass = ActiveRecord::VERSION::MAJOR < 5 ?
ActiveRecord::Migration : ActiveRecord::Migration[4.2]
class ConvertToGutentag < superclass
def up
## taggings
@jacobwalkr
jacobwalkr / simple_text_editor.c
Last active July 21, 2016 00:35
C solution for Simple Text Editor on HackerRank
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define APPEND 1
#define DELETE 2
#define PRINT 3
#define UNDO 4
#define MAX_INPUT 1000000
module Main (main) where
import Control.Monad
import Control.Applicative
isOpener :: Char -> Bool
isOpener '(' = True
isOpener '[' = True
isOpener '{' = True
isOpener _ = False
use std::io;
use std::collections::HashMap;
use std::borrow::ToOwned;
fn get_number() -> u32 {
let mut number = String::new();
io::stdin().read_line(&mut number).expect("expected number");
return number.trim().parse::<u32>().ok().expect("expected number");
}
require "curses"
include Curses
SNAKE = "\u2588\u2588"
init_screen
begin
crmode
curs_set 0
@jacobwalkr
jacobwalkr / 02-lastbutone.hs
Created October 21, 2014 14:58
H-99 problem 2
myLastButOne :: [a] -> a
myLastButOne [] = error "Not enough elements!"
myLastButOne [x] = error "Not enough elements!"
myLastButOne [x,y] = x
myLastButOne (_:xs) = myLastButOne xs
@jacobwalkr
jacobwalkr / fizzbuzz.hs
Last active August 29, 2015 14:07
Start of Fizzbuzz in Haskell
noRem :: Int -> Int -> Bool
noRem x y = (rem x y) == 0
fizzbuzz :: Int -> String
fizzbuzz x
| noRem x 15 = "fizzbuzz"
| noRem x 3 = "fizz"
| noRem x 5 = "buzz"
| otherwise = show x
@jacobwalkr
jacobwalkr / CodeTeam10.java
Created November 7, 2013 14:16
Code team 10
/*
* COM1001 Crossover Assignment 1
* Team 10
*/
import sheffield.*;
public class CodeTeam10 {
private static Student[] students;
private static Lecturer[] lecturers;