Skip to content

Instantly share code, notes, and snippets.

View oddlyfunctional's full-sized avatar

Marcos Felipe Pimenta Rodrigues oddlyfunctional

View GitHub Profile
#!/bin/ruby
# https://www.hackerrank.com/contests/worldcodesprint/challenges/powerplants-in-flatland
n,m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
c = gets.strip
c = c.split(' ').map(&:to_i)
max_distance = 0
# https://www.hackerrank.com/contests/worldcodesprint/challenges/two-pluses
# Enter your code here. Read input from STDIN. Print output to STDOUT
N, M = gets.strip.split(' ').map(&:to_i)
GOOD = 'G'
class Plus < Struct.new(:x, :y, :length); end
def print_grid(grid)
puts grid.map(&:join)
#!/bin/ruby
# https://www.hackerrank.com/contests/worldcodesprint/challenges/colorful-ornaments
require 'set'
A,B,C,D = gets.strip.split(' ').map(&:to_i)
RR = %w(R R)
RB = %w(R B)
BB = %w(B B)
# https://www.hackerrank.com/contests/worldcodesprint/challenges/print-string
# Enter your code here. Read input from STDIN. Print output to STDOUT
require 'set'
t = gets.strip.to_i
class TestCase < Struct.new(:a, :b, :string); end
test_cases = []
function Guest(session) {
this.session = session;
this.name = "Anonymous";
this.avatar = session.avatar || "https://api.adorable.io/avatars/128/" + Math.random();
session.avatar = this.avatar;
}
Guest.prototype.getCart = function() {
this.cart = this.cart || Cart.find(this.session.cartId) || Cart.create();
return cart;
editInPlace = ->
restrict: 'A'
require: 'ngModel'
scope:
onSuccess: '&'
link: (scope, element, attrs, ngModelCtrl) ->
originalValue = ngModelCtrl.$modelValue
element.focus ->
originalValue = ngModelCtrl.$modelValue
focusOn = ($timeout) ->
link = (scope, element, attrs) ->
scope.$watch attrs.focusOn, (newValue) ->
$timeout(-> element.focus()) if !!newValue
restrict: 'A'
link: link
focusOn.$inject = ['$timeout']
@oddlyfunctional
oddlyfunctional / timeout_with_nested_callbacks.js
Created May 25, 2016 13:07
$timeout with nested callbacks
$timeout(function() {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - created'
}],
type: 'error'
};
$timeout(function() {
$timeout(function() {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - created'
}],
type: 'error'
};
@oddlyfunctional
oddlyfunctional / example.html
Created June 1, 2016 20:34
Show spinner over image while it's loading
<load-image>
<img #loadImage src="http://orig12.deviantart.net/210f/f/2014/146/9/e/snowy_winter_background_by_archangelical_stock-d7jtb1d.jpg"/>
</load-image>