Skip to content

Instantly share code, notes, and snippets.

View rr-codes's full-sized avatar

Richard Robinson rr-codes

View GitHub Profile
#include <iostream>
#include <array>
template<typename T, size_t N, size_t M>
class matrix {
public:
template<size_t ... n>
constexpr explicit matrix(const T (&...list)[n]) : _data{}
{
auto pos = &_data[0];
std::string reverse_domain2(const std::string& s) {
std::string result;
auto index = 0;
for (const auto& c : s) {
if (c == '.') {
index = 0;
result.insert(result.begin() + index, '.');
continue;
}
data class Task(val name: String, val files: List<String>, val deps: List<String>)
fun globMatches(pattern: String, path: String): Boolean {
val start = "^"
val end = "$"
val regex = buildString {
append(start)
append(pattern.replace("([\\^\\[\\]\\.\\+\\?])".toRegex(), "\\\\$1").replace("*", "[^/]*"))
append(end)
/**
* Apple's `Result` type ported to Kotlin. Instead of using enums with associated values, this implementation uses a
* sealed interface with implementations.
*
* ```
* /* create a Result */
*
* fun makeResult() = Result { // throw a `Throwable` or return a value }
*
func index(countries: [Country]) {
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypePNG as String)
let items = countries.map { (country) -> CSSearchableItem in
attributeSet.title = country.name.common
attributeSet.contentDescription = "The flag of \(country.name.official)"
attributeSet.thumbnailData = UIImage(named: country.flagImageName)!.pngData()!
return CSSearchableItem(
uniqueIdentifier: country.id,
class FlagListTableViewCell: UITableViewCell, ReusableView {
private let flagImageView = UIImageView()
private var cellHeightConstraint: NSLayoutConstraint!
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.cellHeightConstraint = self.flagImageView.heightAnchor.constraint(equalToConstant: 0)
self.cellHeightConstraint.isActive = true
package com.eecs1021;
import java.io.PrintStream;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Student {
private final String name;
/**
* Recursively maps values of an object
*
* @param object the target object
* @param transformation a mapping function, which is applied recursively to the deepest values
*/
function mapValues<O, K extends keyof O, R>(object: O, transformation: RecursiveTransform<O[K], R>): MappedObject<O, R> {
return Object.entries(object).reduce((prev, [key, value]) => {
prev[key] = typeof value === 'object' ? mapValues(value, transformation) : transformation(value);
return prev;
@rr-codes
rr-codes / Main.java
Last active January 28, 2021 00:05
Jmusic demo
import jm.constants.Instruments;
import jm.constants.Pitches;
import jm.constants.RhythmValues;
import jm.music.data.*;
import jm.util.Play;
import java.util.List;
public class Main {
public static void main(String[] args) {
query IssueComments($owner: String!, $name: String!, $num: Int!) {
rateLimit {
limit
cost
remaining
resetAt
}
repository(owner: $owner, name: $name) {
issue(number: $num) {
timelineItems(last: 10, itemTypes: [ADDED_TO_PROJECT_EVENT, REMOVED_FROM_PROJECT_EVENT, MOVED_COLUMNS_IN_PROJECT_EVENT, RENAMED_TITLE_EVENT]) {