Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
jacopotarantino / ci.yml
Last active June 15, 2024 20:46
Microsoft Principal CI Engineer Take Home
# .github/workflows/ci.yml
name: CI
on: [push]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
steps:
@jacopotarantino
jacopotarantino / trumpnames.md
Created April 13, 2021 04:19
trumpnames.md

Scone Fiddler

Wankmaggot General

Twatbiscuit

Westminster Flabby

DJ Tranny

@jacopotarantino
jacopotarantino / calculate.js
Created April 29, 2020 03:54
Calculating _real_ income tax percentage
// income tax
const base_income = // annual income before any tax
const federal_tax_rate = // 0.xx format
const state_tax_rate = // 0.xx format
// property tax
const monthly_rent = // dollar amount per month
const property_tax_rate = 0.18 // in new jersey at least
// medical tax
const monthly_health_insurance = // dollar amount per month
// consumption tax
@jacopotarantino
jacopotarantino / die-fairness.js
Created December 9, 2019 21:59
is my die balanced?
// determines number of times you should roll a die to determine if it is "fair"
const find_number_of_rolls = (number_of_sides, required_confidence) => {
const allowed_deviation = 1 - required_confidence
const expected_value_per_side = 1/allowed_deviation
const rolls = expected_value_per_side * number_of_sides
return Math.round(rolls)
}
// rolls array takes the form: value_of_side(int)[]
@jacopotarantino
jacopotarantino / safe_read.js
Created December 5, 2019 20:48
safe_read.js
const safe_read = (object, property) => {
try {
return property.split('.').reduce((acc, current) => {return acc[current] || undefined}, object)
} catch(e) {
return null
}
}
@jacopotarantino
jacopotarantino / _proposal.md
Created May 9, 2019 18:02
Proposal: split CSS files by media query

I've seen others struggle(and have struggled myself) with media queries and gigantic CSS files separately and together. I recently learned that CSS import statements support media queries and have done so for a long time (see: https://developer.mozilla.org/en-US/docs/Web/CSS/@import). In other implementations I've seen this ability being used for including external stylesheets into a stylesheet the developer actually controls. I'd like to propose a system where developers use CSS imports by default in order to minimize the amount of data sent to clients and in order to better structure our CSS. An example index.css file and small.css (included file) is show in this gist. Structuring our files this way means that the initial CSS payload is only 306 bytes. Anything more than that is only included if it's relevant to the current client. We can also inline this initial block into the `` of the html removing a single network request from the initial

@jacopotarantino
jacopotarantino / test.md
Last active April 23, 2019 21:44
angular1-dependency-injection.js

so, in earlier angular1 code, we would list all of the dependencies of a controller in an array where the last item in the array is the controller to inject them into. it looked like this:

someModule.controller('MyController', ['$scope', 'dep1', 'dep2', function MyController ($scope, dep1, dep2) {
  // do something...
}]);

this pattern works but it's ...not great. right? tons of nesting, repetition, people unfamiliar with javascript would be very confused. so then we started using injection syntax.

@jacopotarantino
jacopotarantino / translate.js
Created October 17, 2018 18:37
Proxying to an i18n function in order to treat it like an object.
// assume this is our original translate function
const translate = (key) => {
return key.split('.').reduce((acc, current) => {
return acc[current];
}, english);
}
// an example of a dictionary of i18n strings with nested properties
const english = {
foo: {
@jacopotarantino
jacopotarantino / render_ads.js
Created August 4, 2018 00:10
triplelift ad challenge
((global) => {
function getTemplate () {
return fetch('http://backend-php-test.prod.dcos.triplelift.net/ad-experience/template')
.then(function(response) {
return response.json();
});
}
function getContent () {
@jacopotarantino
jacopotarantino / test.js
Created March 5, 2018 18:47
Impossible JavaScript Question
/* what do each of these statements return?
(assume that they are evaluated individually but in order.)
*/
const foo = 'asdf'; //=> ?
foo.bar = 12345; //=> ?
foo; //=> ?