Skip to content

Instantly share code, notes, and snippets.

View lennyferguson's full-sized avatar

Stewart Charles lennyferguson

View GitHub Profile
@lennyferguson
lennyferguson / fontsizes.py
Last active January 14, 2019 22:27
Example of a function that generates a range of font sizes from min -> max -> min modeling the traversal of a sin wave
from typing import List, TypeVar, Callable
from math import sin, pi
# TypeVar for a generic number type
Num = TypeVar('Num', int, float)
"""
Function that generates a List of integers that represent a interpolation of font sizes from min to max along
a sin wave function that has been transformed to have the desired properties.
Returns a List of Integers (List[int]) of size num_pages containing font sizes interpolated between min and max.
@lennyferguson
lennyferguson / generics.go
Last active August 22, 2018 19:10
Hacky approach to generics in go
func AllMatch(arr interface{}, test func(interface{})bool) bool {
switch reflect.TypeOf(arr).Kind() {
case reflect.Array,reflect.Slice:
a := reflect.ValueOf(arr)
for i := 0; i < a.Len(); i++ {
if !test(a.Index(i).Interface()) {
return false
}
}
}
(defprotocol ToCard
"Protocol for coercing a CardItem to a card"
(to-card [card] "Produces a bootstrap styled card item"))
(defrecord CardItem [title content img-link link]
ToCard
(to-card [_]
[:div.card.bg-dark.text-white
[:a.card-top {:href link}
[:img.card-img-top {:src img-link}]]
from django.db import models
from functools import reduce
class Result:
passed = 1
failed = 2
skipped = 3
def count_results(results, result):
return reduce(lambda accum, current: accum + (current.result_id == result),
/**
* Asserts that there is a row on the Student Grades Page that contains every field of each
* Grade in the students list of Grades
* @param student the argument student
* @return the invoked student grades page
*/
public StudentGradesPage assertStudentGrades(final StudentManager.SummaryStudent student) {
Assert.assertTrue(student.getStudentGrades().size() > 0);
final SelenideElement gradesBody = Util.demand($("div.panel-heading + table tbody"));
Assert.assertTrue(student.getStudentGrades().stream().allMatch(grade ->
/**
* QaUser type that encapsulates information displayed for StudentSummary
* which involves enrolled classes, and grades
*/
public class SummaryStudent extends QaUser {
private List<StudentGrade> studentGrades;
private List<StudentClass> studentClasses;
/**
@lennyferguson
lennyferguson / polyhedral_circle_approx.py
Last active April 18, 2018 15:17
Draw Bot script that creates and renders an approximation of a circle by subdividing a polyhedron
import math
from functools import reduce
"""
Vector Class to handle 2D transformations and operations
"""
class Vec2(object):
def __init__(self, x,y):
self.x = x
self.y = y
@lennyferguson
lennyferguson / quadcopter_src.js
Created April 5, 2018 06:11
Source Code for Quadcopter Animation
/* Author: Stewart Charles
/ Assignment 3
/ CS 4600
/ Version: 2/20/2017
-- Utilizes Matrix Stack and Shape/Objects to draw Quadcopter*/
/* Initialize Variables persistent variables. */
var time;
var xSlider, xText, ySlider, yText;