Skip to content

Instantly share code, notes, and snippets.

View mgiuffrida's full-sized avatar

Michael Giuffrida mgiuffrida

View GitHub Profile
@mgiuffrida
mgiuffrida / magnetgolf.html
Last active August 29, 2015 14:01
magnetgolf
<html>
<head>
<script src="magnetgolf.js"></script>
</head>
<body>
</body>
</html>
@mgiuffrida
mgiuffrida / removeElements.js
Last active August 29, 2015 14:01
Remove elements from a page by clicking on them.
(function() {
var d = document;
d.styleSheets[0].addRule('.h7374',
'background:red !important');
var escape = function(e) {
if (e.keyCode==27)
cancel();
},
getElements = function() {
@mgiuffrida
mgiuffrida / gist:e2b72ad323e7946998b3
Last active August 29, 2015 14:24
ruby-warrior beginner level 9
# https://www.bloc.io/ruby-warrior
class Player
def deadlyArcher?(w, spaces)
w.health < @health and (spaces[0].enemy? or spaces[1].enemy? or spaces[2].enemy?)
end
def deadlyWizard?(w, spaces)
w.health <= 12 and w.health > @health and (spaces[0].enemy? or spaces[1].enemy?)
end
@mgiuffrida
mgiuffrida / player.rb
Created July 11, 2015 22:47
Solution to intermediate epic mode - github.com/ryanb/ruby-warrior
# Total Score: 917
# Your average grade for this tower is: A
#
# Level 1: S
# Level 2: A
# Level 3: B
# Level 4: A
# Level 5: B
# Level 6: A
# Level 7: A
@mgiuffrida
mgiuffrida / closure_properties.js
Last active November 13, 2015 21:58
Closure gets confused about property types when not annotated
/** @interface */
function Gum() {}
Gum.prototype = {
/** @return {boolean} */
isMinty: function() { return true; }
};
/** @constructor */
function Candy() {}
@mgiuffrida
mgiuffrida / scroll-to-bottom.js
Created December 5, 2015 05:19
codingame.com irc auto-scroll
setInterval(function() { if (document.activeElement.tagName == 'BODY') return; var a = document.querySelectorAll('.ircwindow')[0]; if (a) a.scrollTop = Number.MAX_VALUE; }, 200);
@mgiuffrida
mgiuffrida / santa7.sed
Created December 8, 2015 10:43
sed rules to convert input to C program
s/^([0-9]+) -> (.*)$/unsigned short solve_\2() { return \1; }/
s/^([a-z]+) -> (.*)$/unsigned short solve_\2() { static unsigned short \2_answer; static bool \2_solved; if (!\2_solved) { \2_answer = solve_\1(); \2_solved = true; } return \2_answer; }/
s/^([a-z]+) AND ([a-z]+) -> (.*)$/unsigned short solve_\3() { static unsigned short \3_answer; static bool \3_solved = false; if (!\3_solved) { \3_answer = solve_\1() \& solve_\2(); \3_solved = true; } return \3_answer; }/
s/^([0-9]+) AND ([a-z]+) -> (.*)$/unsigned short solve_\3() { static unsigned short \3_answer; static bool \3_solved = false; if (!\3_solved) { \3_answer = \1 \& solve_\2(); \3_solved = true; } return \3_answer; }/
s/^([a-z]+) AND ([0-9]+) -> (.*)$/unsigned short solve_\3() { static unsigned short \3_answer; static bool \3_solved = false; if (!\3_solved) { \3_answer = solve_\1() \& \2; \3_solved = true; } return \3_answer; }/
s/^([0-9]+) AND ([0-9]+) -> (.*)$/unsigned short solve_\3() { static unsigned short \3_answer; static bool \3_solved = f
// option 1:
myPromise.then(
function(result) {
// do stuff
}, function(error) {
// oh noes
})
.then(
function(result) {
@mgiuffrida
mgiuffrida / close_bug.js
Created May 5, 2016 16:30
Close MD bug bookmarklet
javascript:(function() { var c = document.getElementById('addCommentTextArea'); var s = document.getElementById('statusedit'); if (!c || !s) { alert('Sign in or whatever'); return; } c.value = 'This is a Material WebUI page which is a work in progress and isn\'t ready for launch.'; s.value='WontFix'; s.form.querySelector('input[type=submit]').click(); })()
@mgiuffrida
mgiuffrida / jump_to_failure.js
Created September 20, 2016 21:06
Jump to buildbot failure bookmarklet
javascript:(function() { var els = document.querySelectorAll('ol .failure'); if (typeof window._jtf_i == 'undefined' || window._jtf_i >= els.length) window._jtf_i = 0; els[window._jtf_i++].scrollIntoView(); })();