Skip to content

Instantly share code, notes, and snippets.

@beeleebow
beeleebow / JsBooleanCoercion.js
Last active April 3, 2016 03:25
A set of examples that remind me how Boolean coercion works in JavaScript
var truthTest = function(value){
return value ? "true" : "false";
}
// Boolean literals behave as expected
var trueLiteral = true;
var falseLiteral = false;
truthTest(trueLiteral); // true
truthTest(falseLiteral); // false
@beeleebow
beeleebow / group_by_intervals_postgres.sql
Last active January 16, 2023 00:28
PSQL - Group Rows with timestamp interval
-- POSTGRES SQL.
-- Count of rows where a timestamp column falls in interval.
-- This example uses a 5 minute interval ( 300 seconds = 5 minutes).
-- You need to replace the things inside square brackets, i.e. provide
-- the name of the table and timestamp column.
SELECT COUNT(*) cnt,
to_timestamp(floor((extract('epoch' from [Timestamp Column]) / 300 )) * 300)
AT TIME ZONE 'UTC' as expiry_interval
FROM [Table] GROUP BY expiry_interval
order by expiry_interval
@beeleebow
beeleebow / LogEntityFrameworkQueries.cs
Created September 7, 2017 00:13
Log Entity Framework Queries to Debug Output
/*
When you want to see the sql that entity framework is generating you
can turn on logging that will go to Visual Studios debug output
*/
using(var dbContext = new MyDbContext())
{
dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
// do your queries here...
}
@beeleebow
beeleebow / CreditCardValidator.hs
Created July 25, 2018 21:48
cis194 w01 solution
module Week01.CreditCardValidator
( toDigits
, toDigitsRev
, doubleEveryOther
, sumDigits
, validate
) where
reverseList :: [Integer] -> [Integer]
reverseList [] = []
@beeleebow
beeleebow / Log.hs
Last active July 27, 2018 04:08
cis194 w02 solution
-- CIS 194 Homework 2
module Week02.Log
( MessageType(..)
, TimeStamp
, LogMessage(..)
, MessageTree(..)
, testParse
, testWhatWentWrong
) where
@beeleebow
beeleebow / Golf.hs
Last active August 2, 2018 22:55
cis194 w03 solutions
module Week03.Golf
( skips
, localMaxima
, histogram
, histogramGen
) where
skips :: [a] -> [[a]]
skips xs = map (`everyNth` xs) [1..(length xs)]
where everyNth n = map snd . filter ((==0) . (`mod` n) . fst) . zip [1..]
@beeleebow
beeleebow / Week04Soln.hs
Last active August 9, 2018 10:25
cis194 w04 solution
module Week04.Soln
( fun1
, fun2
, fun1'
, fun2'
, Tree(..)
, foldTree
, showTree
, printTree
, xor
@beeleebow
beeleebow / FreeMonadAddNumbers.cs
Created November 23, 2018 05:24
Exploring using IO monad to structure programs and and interpretter to run them
/*
Modified from https://gist.github.com/dadhi/59cfc698f6dc6e31b722cd804aae185a
which was in turn modified from: https://gist.github.com/louthy/524fbe8965d3a2aae1b576cdd8e971e4
Simplified to a program that adds two numbers
Useful links:
- [John DeGoes: Beyond Free Monads - λC Winter Retreat 2017](https://www.youtube.com/watch?v=A-lmrvsUi2Y)
- [Free and tagless compared - how not to commit to a monad too early](https://softwaremill.com/free-tagless-compared-how-not-to-commit-to-monad-too-early)
@beeleebow
beeleebow / UsingApplyOnOption.cs
Last active March 20, 2019 21:37
Lifting functions that deal with non-optional values into an Optional context.
using System;
using Blackbaud.Registration.Tests.Common.Extensions;
using LanguageExt.UnitTesting;
using Xunit;
using static LanguageExt.Prelude;
namespace Blackbaud.Registration.MessageHandlers.UnitTests.CommandHandlers
{
public class UsingApplyOnOption
{
#!/bin/bash
TAGS=$(git tag --list)
IFS=$'\n' read -rd '' -a TAGS_ARRAY <<<"$TAGS"
ARR_LENGTH="${#TAGS_ARRAY[@]}"
MOST_RECENT="${TAGS_ARRAY[ARR_LENGTH - 1]}"
printf "$MOST_RECENT\n"
jq '.builder = $version' --arg version "$MOST_RECENT" test.json > temp.test.json