Skip to content

Instantly share code, notes, and snippets.

View jbranchaud's full-sized avatar

Josh Branchaud jbranchaud

View GitHub Profile
@jbranchaud
jbranchaud / summary.rb
Last active February 21, 2021 18:26
TIL Repo: Generate List of Links For Past Week's TILs
results = `git log HEAD@{'7 days ago'}..HEAD --oneline | sed 's/^\([[:alnum:]]*\) .*$/\1/'`
commit_list = results.split(/\n/).map do |item|
item.split(' ', 2)
end.filter do |sha, commit_message|
commit_message.start_with?('Add ')
end
commit_data = commit_list.map do |sha, commit_message|
diff_tree_result = `git diff-tree --no-commit-id --name-only -r #{sha}`
@jbranchaud
jbranchaud / retry.rb
Created February 8, 2021 23:10
Ruby's rescue exception and retry functionality
def sometimes_fails
puts "Beginning of sometimes_fails"
begin
retries ||= 0
puts "About to do a thing (#{retries})"
raise StandardError if rand(5) != 4
puts "Success!"
@jbranchaud
jbranchaud / thing.rb
Created February 4, 2021 18:15
Returning out of a Ruby begin block
class Thing
def initialize(value)
@value = value
end
def call(other_value)
@other_value = other_value
puts final_value
end

Congratulations! Josh Branchaud 🏆:

Check your terminal for next steps 👀

@jbranchaud
jbranchaud / advent_of_code_2020_day_9_part_one.sql
Last active December 10, 2020 01:25
Advent of Code 2020, Day 9, Part One, SQL
-- create temp table with sample input
insert into xmas_data (value) values (35), (20), (15), (25), (47), (40), (62), (55), (65), (95), (102), (117), (150), (182), (127), (219), (299), (277), (309), (576);
-- starter subquery
select
v1.id v1id,
v2.id v2id,
v1.value,
v2.value,
v1.value + v2.value sum
@jbranchaud
jbranchaud / dafny-exercise3
Created March 11, 2013 02:14
Exercise 3 from Microsoft's Dafny on Rise4Fun.com
/*
* Keeping the postconditions of Abs the same as above, change
* the body of Abs to just y := x + 2. What precondition do you
* need to annotate the method with in order for the verification
* to go through? What precondition doe you need if the body is
* y := x + 1? What does that precondition say about when you can
* call the method?
*/
method Abs(x: int) returns (y: int)
requires x == -1;
@jbranchaud
jbranchaud / QuickJavaSearch.bash
Created November 16, 2012 17:44
Quick search through a large Java project for a string
#!/bin/bash
# the first argument is the string you are looking for --> $1
searchString="$1"
for f in `find . -type f -name "*.java"`
do
result=`grep "$searchString" $f`
@jbranchaud
jbranchaud / CSVtoLaTeX.bash
Created April 19, 2012 04:36
Convert CSV to LaTeX table
# Convert a CSV like the following:
# a,b,c,d,e,f,g
# To the LaTeX table format like the following:
# {a} & {b} & {c} & {d} & {e} & {f} & {g} \\\hline
sed 's/,/} \& {/g' Table1.csv | sed 's/^/{/' | sed 's/$/} \\\\\\hline/' > Table1Format.txt
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
var picArray [][]uint8
picArray = make([][]uint8, 0, dy)
for i := 0; i < dy; i++ {
var currX []uint8
currX = make([]uint8, 0, dx)