Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian A. Danielak briandk

View GitHub Profile
@briandk
briandk / applebuggycode.c
Created Feb 24, 2014
The SSL bug in Apple's code
View applebuggycode.c
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 Apr 1, 2014
Nesting complexity in Data Structures.
View nestingComplexity.py
{"pages": [ {"playerName": "Boris",
"livesLeft": 1},
{"playerName": "Anna",
"livesLeft": 1} ],
"items": ["broadsword", "healingPotion", "mirrorShield"]
"timestamp": 12593829349045 }
@briandk
briandk / stringingFormulaVariablesTogether.r
Created Sep 17, 2014
Helping Cynthia with her problem
View stringingFormulaVariablesTogether.r
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 Sep 22, 2014
Syntax color testing for scheme
View sampleSchemCode.scm
(define (clockpatience cards)
(let ((hand (deal cards 'K)))
(play (topcard 'K hand) 'K hand 1)
)
)
@briandk
briandk / precommit.sh
Created Oct 3, 2014
a precommit hook for naive build versioning in R package development
View precommit.sh
#!/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 Aug 29, 2015
Cantor's Diagonal Proof Code
View cantorDiagonal.py
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 Nov 30, 2014
transdown debugging
View transdown.js
var transdownNamespace = {
updatePreviewAfterEachKeypress : function () {
$('#text-to-transdownify').keyup(this.renderTranscriptPreview);
},
transdownify : function (text) {
return (text);
},
renderTranscriptPreview : function () {
@briandk
briandk / logicalToBinary.scm
Created Dec 9, 2014
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
View logicalToBinary.scm
​(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 Aug 29, 2015
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.
View usingMapWithAnExternalContext.js
var myDictionary = {
rocket: 'Atlas V',
spaceport: 'Cape Canaveral',
astronauts: [
'Brian',
'Wil'
]
};
var getValueFromExternalDictionary = function (currentKey, indexOfCurrentKey) {
@briandk
briandk / magrittrExamples.R
Last active Aug 29, 2015
Formatting conventions for piping with magrittr in R
View magrittrExamples.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 <-