Skip to content

Instantly share code, notes, and snippets.

(def options {:a ["a" "b" "c"] :b "thingy" :c {"x" [1 2 3]}})
(defn option-template
[options]
(for [[k v] options]
(case v
vector? (select-field k v)
map? (option-template v)
[:label v)))
@eldewall
eldewall / gist:017fb3d0589bbfc10493
Created July 17, 2014 12:51
one-liner vs flera läsbarhet
// form.Make och form.Models är IEnumerable<string>
// one-liner vs flera
if (make != null) {
form.Makes = new List<string>(form.Makes ?? new List<string>()) { make };
}
if (model != null) {
if (form.Models == null) {
form.Models = new List<string>();
}
import deck from Deck
from mock import Mock
# deck.Deck typ:
# from card import Card
# class Deck:
#
# def __init__(self):
# self.cards = [Card(x) for x in range(0, 52)]
#
public interface IEmediateAd {
int ContentUnit { get; }
string Url { get; }
int Height { get; }
int Width { get; }
}
public class Loader {
public string Load(IEmediateAd ad) {
def test_game_kills_cell_if_not_two_or_three_neighbours:
c = Cell(neighbours=1)
c2 = Cell(neighbours=4)
game = GameOfLife()
game.decide_fate(c)
game.decide_fate(c2)
assert c.dead
assert c2.dead
[HttpPost]
public ActionResult Login(LoginModel model) {
if (!ModelState.IsValid) {
return View(model);
}
if (UserValidator.IsValid(model)) { // USES REPOSITORY
FormsAuthentication.SetAuthCookie(model.Email, false);
var user = this.UserRepository.Get(model.Email); // USES IT AGAIN
BankIdValidator = new BankIdValidator(user, this.UserRepository);
[Authorize]
[OutputCache(NoStore = false, Duration = 0, Location = OutputCacheLocation.None)]
public ActionResult AuthorizeBankId(string returnUrl)
{
BankIdValidator = new BankIdValidator(this.CurrentUser, this.UserRepository);
var url = !String.IsNullOrEmpty(returnUrl) ? returnUrl : Url.Action("Index", "Home");
if (this.CurrentUser.IsBankIDAuthorized)
{
return Redirect(url);
}
public interface IResult<T> {
bool Success { get; }
T Data { get; }
string Error { get; }
}
public class ErrorResult<T> : Result<T> {
public ErrorResult(string error) : base(null, false, error) {
@eldewall
eldewall / gist:5803739
Last active December 18, 2015 15:19
Cached Reader decorator
public class AsdController : BaseController {
private IReader<Encrypted, SalesObject> Reader { get; private set; }
public AsdController(IReader<Encrypted, SalesObject> reader) {
Reader = reader;
if (base.UseCaching) {
Reader = new CachedReader<Encrypted, SalesObject>(Reader);
}
}
GET /company/1
{
"Id": 1,
"Name": "Företaget",
"Resources": {
"Notes": "http://host/company/1/notes",
"Users": "http://host/company/1/users",
"Facilities": "http://host/company/1/facilities"
}