Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Barylko amirci

View GitHub Profile
View configutil.java
 public static <A, B> Optional<Map<B, Set<A>>> tryReverse(final Map<A, Set<B>> maybeInput) {
    return Optional.ofNullable(maybeInput).map(ConfigUtil::reverse);
 }
private static <A, B> Map<B, Set<A>> reverse(final Map<A, Set<B>> input) {
    return filterNullValues(input)
             .flatMap(kvp -> filterNullValues(kvp).map(v -> mkEntry(v, kvp.getKey())))
             .collect(groupingBy(x -> x.getKey(), HashMap::new, mapping(y -> y.getValue(), toSet())));
}
@amirci
amirci / Lunky's day 11.fs
Last active Feb 10, 2016
Lunky's day 11 modified
View Lunky's day 11.fs
namespace adventofcode
open System.Text.RegularExpressions
module Day11 =
let abc = ['a'..'z']
let succ (c: char) = int c |> (+) 1 |> char
let incChar = function
View Invert statement.cs
public double RefDoingCalculations()
{
if (!_firstGuard)
{
return 0;
}
if (!_secondGuard)
{
return FirstCalculation();
@amirci
amirci / viewmodel_spec.coffee
Created May 7, 2013
Spec using mock to call response method
View viewmodel_spec.coffee
describe "ChildrenCheckinViewModel", ->
beforeEach ->
spyOn(jQuery, 'getJSON')
@actualChildren = ko.observableArray()
@subject = new Childcarepro.ChildrenCheckinViewModel @actualChildren
@response = [
{FIRSTNAME:'John',LASTNAME:'Locke',BIRTHDATE:12312312312},
{FIRSTNAME:'Matt',LASTNAME:'Zandstra',BIRTHDATE:12312312312}
]
@amirci
amirci / line_spec.rb
Created Apr 24, 2013
Acceptance tests for bowling game
View line_spec.rb
require_relative 'bowling'
describe Line do
def roll_balls(line, frames)
frames.each { |pins| line.knock pins }
end
def self.should_behave_like_a_bowling_game(result, frames, descr=nil)
context descr || "when doing a game with #{frames}" do
@amirci
amirci / demo.coffee
Created Oct 2, 2012
Demo for Coffeescript presentation
View demo.coffee
# String interpolation
result = "The result is #{3}"
console.log result
movieId = 452
url = "http://movies/#{movieId}"
console.log url
# Functions
square = (x) -> x * x
View fluent_build.cs
Build.UsingCsc(config => config
.Target(Library)
.Sources(....)
.References(....)
.OutputTo(.....));
View wpsh_review.rb
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
require 'word_press_security_hardening'
describe WordPressSecurityHardening do
# when method is an instance method use "#"
# when is a class method use "."
describe '#harden' do
let(:db) { double(WordPressDatabase) }
let(:config) { double(WordPressConfigFile) }
@amirci
amirci / C# NumberFor
Created Jan 7, 2012 — forked from anonymous/C# NumberFor
NumberFor extension for HtmlHelper
View C# NumberFor
using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text.RegularExpressions;
namespace Website.Extensions
{
public static class HtmlExtensions
{
@amirci
amirci / expression_property_name.cs
Created Sep 15, 2011
Using expression to pass property names
View expression_property_name.cs
// Given the class
class PropertyId {
public int Id {get;set;}
public int StateCode {get;set;}
}
var id = new PropertyId { Id = 1, StateCode = "NY" };
// call the method
SetProperty(id => id.StateCode, "CA");