Skip to content

Instantly share code, notes, and snippets.

View briandk's full-sized avatar

Brian A. Danielak briandk

View GitHub Profile
@briandk
briandk / applebuggycode.c
Created February 24, 2014 22:34
The SSL bug in Apple's code
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
uint8_t *signature, UInt16 signatureLen)
{
OSStatus err;
...
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
@briandk
briandk / nestingComplexity.py
Created April 1, 2014 17:42
Nesting complexity in Data Structures.
{"pages": [ {"playerName": "Boris",
"livesLeft": 1},
{"playerName": "Anna",
"livesLeft": 1} ],
"items": ["broadsword", "healingPotion", "mirrorShield"]
"timestamp": 12593829349045 }
@briandk
briandk / stringingFormulaVariablesTogether.r
Created September 17, 2014 00:16
Helping Cynthia with her problem
getFormula <- function(checkboxOutput, variablesThatMustAppearInModel) {
formula <- "testScores ~"
variables1 <- paste(variablesThatMustAppearInModel, collapse = " + ")
variables2 <- paste(checkboxOutput, collapse = " + ")
fullCall <- paste(variables1,
variables2,
collapse = " + ",
sep = " + ")
return(paste(formula,
fullCall))
@briandk
briandk / sampleSchemCode.scm
Created September 22, 2014 20:59
Syntax color testing for scheme
(define (clockpatience cards)
(let ((hand (deal cards 'K)))
(play (topcard 'K hand) 'K hand 1)
)
)
@briandk
briandk / precommit.sh
Created October 3, 2014 22:11
a precommit hook for naive build versioning in R package development
#!/bin/bash
D=`date +%Y%m%d%H%M%S`
branch=`git status|grep -ie 'on branch master'`
if [ -z "$branch" ]; then
cat DESCRIPTION | sed -e 's/^\(Version: [0-9]*\.[0-9]*\).*/\1.'$D'/' > DESCRIPTION.temp
rm DESCRIPTION
mv DESCRIPTION.temp DESCRIPTION
git add DESCRIPTION
@briandk
briandk / cantorDiagonal.py
Last active August 29, 2015 14:08
Cantor's Diagonal Proof Code
complement = {0: 1,
1: 0} # Maps 0 to 1 and vice versa
newNumber = [] # Initialize an empty list as a new number
def CantorDiagonal(MatrixOfAllNumbers, newNumber):
for i in range(len(MatrixOfAllNumbers)):
"""
Remember, the length of the matrix is infinite,
so this loop runs forever. It scans the diagonal
@briandk
briandk / transdown.js
Created November 30, 2014 22:49
transdown debugging
var transdownNamespace = {
updatePreviewAfterEachKeypress : function () {
$('#text-to-transdownify').keyup(this.renderTranscriptPreview);
},
transdownify : function (text) {
return (text);
},
renderTranscriptPreview : function () {
@briandk
briandk / logicalToBinary.scm
Created December 9, 2014 06:27
Inspired by Wil Doane, this is a probably broken function that's designed to take a list of 0s and 1s (say, from a matrix of indicator values like "single", "employed", "ownsHome") and generate a unique integer to represent that binary string
​(define (logicalToBinary listOfZeroesAndOnes powerOfTwo runningSum)
(if (= (cdr listOfZeroesAndOnes) `()); Not sure if this is right, but it should be "if you've exhausted the list,
; implemented as "if the remainder of the list equals an empty list"
; http://stackoverflow.com/questions/9115703/null-value-in-mit-scheme
runningSum)
(else return (logicalToBinary (cdr listOfZeroesAndOnes)
(+ powerOfTwo 1)
(+ runningSum (* runningSum powerOfTwo)))))
@briandk
briandk / usingMapWithAnExternalContext.js
Last active August 29, 2015 14:11
Figuring out how to pass an external context to a JavaScript map function. Why? Say you want a function that operates element-wise on an array, but generates results that it needs to add to some outside object, like an array or a dictionary.
var myDictionary = {
rocket: 'Atlas V',
spaceport: 'Cape Canaveral',
astronauts: [
'Brian',
'Wil'
]
};
var getValueFromExternalDictionary = function (currentKey, indexOfCurrentKey) {
@briandk
briandk / magrittrExamples.R
Last active August 29, 2015 14:12
Formatting conventions for piping with magrittr in R
df <-
  df %>%
  select(col1 = str_split(oldcol2, ','),
         col2,
         col3 = paste0(oldcol1, 'amber')) %>%
  filter(col1 == "America" | col2 >= 55) %>%
  group_by(col1, col2) %>%
  summerize(count = n())
df <-