Skip to content

Instantly share code, notes, and snippets.

View gacardinal's full-sized avatar
💭
Wait, has this become Facebook?

Gabriel Cardinal gacardinal

💭
Wait, has this become Facebook?
View GitHub Profile
@gacardinal
gacardinal / day5.ts
Created December 6, 2020 04:45
Advent of Code 2020 Day 5 TypeScript
import { readFileSync } from 'fs';
const findRowNumber = (address: string, lowerBoundary: number, upperBoundary: number): number => {
if (!address.length) {
return lowerBoundary;
}
const remainingAddress = address.slice(1);
const distance = ((upperBoundary - lowerBoundary) / 2);
if (address[0] === 'F' || address[0] === 'L') {
@gacardinal
gacardinal / day4.ts
Created December 5, 2020 01:25
Advent of Code 2020 Day 4 Chapter 1
import { readFileSync } from 'fs';
import * as jf from 'joiful';
class Passport {
@jf.string().required()
public byr = '';
@jf.string().required()
public iyr = '';
@jf.string().required()
public eyr = '';
@gacardinal
gacardinal / day3.ts
Last active December 3, 2020 05:32
Advent of Code 2020 Day 3 TypeScript
import { readFileSync } from 'fs';
const map = readFileSync('input.txt').toString('utf8').split('\n');
const patternWidth = map[0].length;
const countTreesInSlope = (right: number, down: number) => {
let totalTrees = 0;
let y= 0;
for (let x = 0; x < map.length; x = x + down) {
const line = map[x];
@gacardinal
gacardinal / day2.ts
Created December 3, 2020 04:32
Advent of Code 2020 Day 2
import { readFileSync } from 'fs';
type PasswordPolicy = {
[key: string]: any
}
type OcurrencePasswordPolicy = {
[key: string]: { min: number, max: number }
}
type PositionPasswordPolicy = {
[key: string]: number[]
@gacardinal
gacardinal / day1.ts
Created December 3, 2020 03:57
Advent of Code 2020 Day 1 TypeScript
import { readFileSync } from 'fs';
const expenses = readFileSync('input.txt').toString('utf8').split('\n').map(n => parseInt(n));
const threeNumberSumIndices = (numbers: number[], targetSum: number) : [number, number, number] | null=> {
let first, second, third;
for (let i = 0; i < numbers.length; i++) {
first = numbers[i];
for (let j = i + 1; j < numbers.length; j++) {
second = numbers[j];
@gacardinal
gacardinal / DisconnectAsyncTaskExtension.cs
Last active January 9, 2020 18:27
C#.NET Socket Task Extension for DisconnectAsync
namespace DisconnectAsyncTaskExtension
{
static class DisconnectAsyncTaskExtension
{
public static Task<SocketAsyncEventArgs> DisconnectAsyncTask(this Socket that, SocketAsyncEventArgs disconnectArgs)
{
TaskCompletionSource<SocketAsyncEventArgs> tcs = new TaskCompletionSource<SocketAsyncEventArgs>();
disconnectArgs.Completed += (object sender, SocketAsyncEventArgs completedArgs) => {
try
@gacardinal
gacardinal / sparkMongo.py
Created February 14, 2019 17:16
Python code to initialize a SparkSession with MongoDB
from pyspark.sql import SparkSession
# The important thing that seems to be often omitted in the docs is the
# spark.jars.packages option.
# Be sure to change the value to reflect your particular version of the spark-mongo connector you are using
spark = SparkSession \
.builder \
.appName("pysparktestapp") \
.config("spark.mongodb.input.uri", "mongodb://127.0.0.1/<database>.<collection>") \