Skip to content

Instantly share code, notes, and snippets.

View julioolvr's full-sized avatar
💭
I may be slow to respond.

Julio Olivera julioolvr

💭
I may be slow to respond.
View GitHub Profile
@julioolvr
julioolvr / machine.js
Created March 3, 2020 17:28
Generated by XState Viz: https://xstate.js.org/viz
const slottingMachine = {
initial: 'selectingSection',
states: {
selectingSection: {
on: {
SELECT_SECTION: 'slottingSection',
},
},
slottingSection: {
on: {
@julioolvr
julioolvr / delete-remote-tracking-branches.sh
Created September 9, 2014 13:58
Delete remote-tracking branches from local git repo
# TODO: Don't delete from origin
git branch -vv | awk '$1 !~ /\*/ { print $1 }' | xargs git branch -D
@julioolvr
julioolvr / jquery-cachedDelegation.js
Created February 17, 2013 06:03
jQuery cached delegation blah
// TESSSSSSSSST
(function($) {
$.fn.cachedDelegation = function(event, selector, callback) {
var $context = $(this);
$context.on(event, selector, function(e) {
console.log('evaluating callback for ', this);
var $target = $(this);
var savedCallback = $(this).data('lazydelegation-callback');
if (!savedCallback) {
@julioolvr
julioolvr / lazy.js
Last active December 13, 2015 19:29
Lazy function evaluation
function something() {}
function doSomethingExpensive() {
console.log('expensive!');
return 42;
}
something.prototype.lazy = function() {
var value = doSomethingExpensive();
return (this.lazy = function() {
@julioolvr
julioolvr / css-selectors-count.js
Created January 14, 2013 13:50
Count CSS selectors per file
// From http://stackoverflow.com/a/12313690
var
styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length;
for (var j = 0; j < totalStyleSheets; j++){
var
styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
@julioolvr
julioolvr / binary-files.sh
Created January 7, 2013 20:43
Checkout files with only mode changes from HEAD
git diff --numstat | awk '{if ($1 == "-" && $2 == "-") print $3}' | xargs git checkout HEAD
@julioolvr
julioolvr / .bashrc
Created December 12, 2012 16:02
bash prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\h \e[30;1m\w\e[0m\n"
PS1="$PS1\$(parse_git_branch)\$ "
@julioolvr
julioolvr / robot.js
Created December 4, 2012 22:54
blaquened
var Robot = function(robot) {};
var strategies = {
scan: function(robot) {
robot.ahead(100);
robot.rotateCannon(360);
robot.back(100);
robot.rotateCannon(360);
},
attack: function(robot) {
@julioolvr
julioolvr / StateMachine.coffee
Created November 5, 2012 15:51
CoffeeScript simple state machine w/ jQuery events
class StateMachine
constructor: (@initial_state) ->
@current_state = @initial_state
transition_to: (state) ->
$.event.trigger "from_#{@current_state}.state_machine"
$.event.trigger "to_#{state}.state_machine"
$.event.trigger "#{@current_state}_to_#{state}.state_machine"
@current_state = state