Skip to content

Instantly share code, notes, and snippets.

View mgiuffrida's full-sized avatar

Michael Giuffrida mgiuffrida

View GitHub Profile
// libcurses: sudo apt-get install libncurses5-dev
// g++ -o snake snake.cpp --std=c++11 -lncurses -Wall && ./snake
#include <curses.h>
#include <unistd.h>
#include <cassert>
#include <cstdlib>
#include <string>
@mgiuffrida
mgiuffrida / find_unused_ash_icons.sh
Created August 11, 2017 00:03
Find unused Ash vector icons in Chromium
#!/usr/bin/env sh
icons=(ash/resources/vector_icons/*.icon)
icons_stripped=()
for icon in ${icons[@]}; do
icon=$(basename "$icon")
icon=${icon/.1x/}
icon=${icon/.icon/}
icons_stripped+=($icon)
done
@mgiuffrida
mgiuffrida / gist:3e2b97aa96558cd6d4664e3e55a59496
Created July 13, 2017 04:47
heartharena.net deck tracker
function start() {
for (let el of Array.from(document.querySelectorAll('li.deckCard'))) {
el.addEventListener('click', function() {
draw(el.querySelector('span.name').textContent.toLowerCase());
});
}
}
function draw(name) {
let costReduced = false;
for (var el of Array.from(document.querySelectorAll('li.deckCard'))) {
@mgiuffrida
mgiuffrida / log_settings.sh
Created June 5, 2017 18:20
count lines inserted by each user
#!/bin/sh
DIRS=(
chrome/browser/ui/webui/settings/
chrome/browser/resources/settings/
chrome/test/data/webui/settings/
ui/webui/resources/cr_elements/cr_dialog/
ui/webui/resources/cr_elements/policy/
ui/webui/resources/cr_elements/network/
)
<div>Hello</div><script src="volume.js"></script>
console.log('hello');
@mgiuffrida
mgiuffrida / count_net_lines.sh
Created June 3, 2017 01:54
LOC added to settings by user (only counts "insertions")
#!/bin/sh
DIRS=(
chrome/browser/ui/webui/settings/
chrome/browser/resources/settings/
chrome/test/data/webui/settings/
ui/webui/resources/cr_elements/cr_dialog/
ui/webui/resources/cr_elements/policy/
ui/webui/resources/cr_elements/network/
)
@mgiuffrida
mgiuffrida / blame_settings.sh
Created June 3, 2017 01:49
count lines attributed to each user
#!/bin/sh
DIRS=(
chrome/browser/ui/webui/settings/
chrome/browser/resources/settings/
chrome/test/data/webui/settings/
ui/webui/resources/cr_elements/cr_dialog/
ui/webui/resources/cr_elements/policy/
ui/webui/resources/cr_elements/network/
)
<!DOCTYPE html>
<body itemscope itemtype="http://schema.org/WebPage">
<div itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">Correct URL (Relative)</span>
<link itemprop="url" href="google.tar.gz">
</div>
<div itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">Bad URL (Absolute)</span>
<link itemprop="url" href="google.com">
</div>
@mgiuffrida
mgiuffrida / binary-search-approx.js
Created December 17, 2016 23:47
Approximate binary search
/**
* Returns the index of the item in a sorted array closest to |target|.
* @param {!Array<number>} arr Sorted array (ascending or descending).
* @param {number} target
* @return {number} Index of closest item, or -1 on error.
*/
function binarySearchApprox(arr, value) {
if (!arr.length || !Number.isFinite(value)) return -1;
if (arr.length == 1) return 0;