From 48e55aafab7951a022505782c2fa8a2fa7b88f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Mon, 29 Oct 2018 21:09:22 -0700 Subject: [PATCH] 2018 work :) --- SecretSanta.js | 38 ++++++++++++++++-- assets/snow.png | Bin 0 -> 3483 bytes index.html | 98 +++++++++++++++++++++++++++++++++++++++------- pairing.html | 101 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 197 insertions(+), 40 deletions(-) create mode 100644 assets/snow.png diff --git a/SecretSanta.js b/SecretSanta.js index 08427a4..524d94a 100644 --- a/SecretSanta.js +++ b/SecretSanta.js @@ -2,6 +2,7 @@ var SecretSanta = function () { this.names = []; + this.enforced = Object.create( null ); this.blacklists = Object.create( null ); }; @@ -15,6 +16,14 @@ SecretSanta.prototype.add = function ( name ) { var subapi = { }; + subapi.enforce = function ( other ) { + + this.enforced[ name ] = other; + + return subapi; + + }.bind( this ); + subapi.blacklist = function ( other ) { if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) @@ -38,12 +47,33 @@ SecretSanta.prototype.generate = function () { this.names.forEach( function ( name ) { - var candidates = _.difference( this.names, [ name ] ); + if ( Object.prototype.hasOwnProperty.call( this.enforced, name ) ) { - if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) - candidates = _.difference( candidates, this.blacklists[ name ] ); + var enforced = this.enforced[ name ]; - candidatePairings[ name ] = candidates; + if ( this.names.indexOf( enforced ) === -1 ) + throw new Error( name + ' is paired with ' + enforced + ', which hasn\'t been declared as a possible pairing' ); + + Object.keys( pairings ).forEach( function ( name ) { + + if ( pairings[ name ] === enforced ) { + throw new Error( 'Per your rules, multiple persons are paired with ' + enforced ); + } + + } ); + + pairings[ name ] = this.enforced[ name ]; + + } else { + + var candidates = _.difference( this.names, [ name ] ); + + if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) + candidates = _.difference( candidates, this.blacklists[ name ] ); + + candidatePairings[ name ] = candidates; + + } }, this ); diff --git a/assets/snow.png b/assets/snow.png new file mode 100644 index 0000000000000000000000000000000000000000..7097c4c2f7ec5fb69f477661f165e5ec6e3a6fe4 GIT binary patch literal 3483 zcmds)e>4+%AICS-{Muyg7FNg@858+gu?i70xqc2|)}vp#^2GcOGi57M!$^9%T^2Le z>QW(XYUQEO52o^Kl(~M*R5FBT-FxnN{&;$xzwTep`JUJLobx{4@B4hu_j}Iw`~J{< zeLSG*2z3Ae0QEfJ<_7=(Exw@&RwyZFE|L`mOu~7%0oJ~apIfR56^dHifslAbJ@7m3 z?J?MIVq)CBqkpakEIXb)4gf&po^JaBlHbh?rk&~+>1NI4GV9*lE;MN|4za475do)O zC@rr>R_t#k=`xRmZ`zG7m+MCgSLQwj)J_taHeu=Q<0`6*Vx+Ip(#sK83Za*buQ(A4 zAjcP0b`fHoEiczt1u=FVn z`pFNBI}->zOw51NRX{NkD^rV^t$qd=pt&Gd;7Zg>hC0Paox7~esH}$w&_dR&tIMVW z!#F^><rv^qr6V40?r!dhKO8$-tAqX2&M4P9nSD1c`Cx zLg_IBcr$gkPHj((sJ+|odePvcG09vGtr#w)>sri*kh|hzW%Nc|HP*(*`Te~d#w#nr z_sEWnwDz2|D0qyxd)ij+_eq}Th#Yud(&Gt^xsN8g)so_VO-WashMQ_0v|J0u1wST2 zgV)t6El@lJQ1MRL5893X9=f$r=;myPEEPep03+T_@??gS7JMgvFdfWgW5@r#JfxOP zW*F6u)KKmTOk|kX;g6gT*?8%VecbUl&}6WW7M*h~A$VNjV%`>+Uv@o)B<;v|x%M}n zF>9ocC~@?^6SWz0_G?OGI)xF9vz;vm!*y7L}g{d zjJA6a{;;_S*aL{L?`}c52XRkq4Tl#b@Jr8^p5(huZyHig%&LTKKVsqulm^Lq#X*J(1B8bmhgX7CJ`q86d$ zfTFUnoGh3XIEWsn2l5c8xtr^KlW2rNP)48As;=CDcfqJG0m59WLAnQU+-g_VPXhL6 z-QH#F9_A(VOqw55B^Z(#_9>rqQ^vPDKJtq!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;I1ODK?Xz%$=R)w4PRcQ7RsZs#9j4WwI=pr2e;~DtNe}|&<>6XHsNAf zSc>$~Y)oKZEU3LmZGlY6A(zP44I|x++l1Sb5(B4(=!rnEIp8hn zpxEg8z{AzHfUc;qAd?-?VsL9O;-gIv0zyTZLH`fP=Ylz*pEWM^I6u3P0ko+R)y2lv zOHoilU$&jnQ-Qh_@FJy9(w)b&jSE*7soqx`07*C8NCiGHeiY3sdOK~K+y4obfFf*! z)%FXtJAX2eZ*m0q&|xJ-_$#9X6G@(_ASC`&y`-m@xbMN0!(xya%hRa67jgJXALGup z+o49-ygpjXS-qPE!ZO#AY%+L@QkY;*S=+5EQcZ+;v@IB`ym}yAix1QXb<=(tnn~3R z*AQvW9f{p=9osK}Nj1?`cg&MD4cpaM)-5y--7j8~*$?@)} zHo5!WpHvW4Pir@LP{eYPr z)edsbt3~|ZQ|wT@-3F0c>4A4czvJ_@Ln=!76&PZ%`qy^nztfA z2EglDBk#a>v(Atzqw9?^13Rn>8q}SXA1a9`ZGs=; -
+

Secret Santa Generator

-

No signup, no email, no bullshit. Just a straightforward open-source tool to help you generate your secret santa pairings. Static page only.

-

The DSL that is used to set the pairing rules is dead simple: in the most common use case (no special rule, pair each guest to another), you just have to enter the name of your guests, one line at a time. Once done, press "generate" and voilà, you will get a set of links that you will just have to give to each one of them (by mail, chat, whatever float your boat). Once they access the link, their pairing will be revealed (to them and only them).

-

Should you have more complex needs (for example if you want to prevent a couple from being paired together, or want to prevent someone to be paired with someone else they don't know), just append !<name> after a guest name, and he will never be paired with <name> (check on the right for an example).

+

No signup, no email, no bullshit. Just a straightforward open-source tool to help you generate your secret santa pairings. One static page, and that's it.

+

In the most common case (no exclusion rules, pair each guest with another at random), enter the name of your guests one line at a time. Once done, press "generate" and you're all set: send the generated links to your guests (by mail, chat, whatever floats your boat) and their pairing will be revealed to them (and only them) once they open the link.

Where does this tool come from?

-

I just wanted to make a Secret Santa over Facebook without giving up my guests email addresses to do so (so nothing that requires a backend). I also wanted to ignore who was paired with me, so I had to find a way to obfuscate it. And since I'm a developer, well, I just thought "Let's AES it, for fun and profits!". Classic.

- +

I wanted to make a Secret Santa over Facebook without having to reveal to anyone my guests email addresses (so nothing that would require a backend). I also wanted not to know who was paired with me, so I had to find a way to somehow obfuscate the information. And being a developer, well, my first thought was "Let's AES it, for fun and profits!". Classic.

@@ -181,6 +178,13 @@ Maël !Aurélie Aurélie !Maël + # You can also exclude someone from being paired with multiple people + # Careful: too many exclusion rules can make your secret santa less interesting! + Rudolph !Maël !Santa + + # You can also cheat a bit and force someone to be paired with another + Aurélie =Santa + ... @@ -188,13 +192,23 @@ +
+
-

- - -

Good luck!

- - +
Hi ! You've been paired with
+ + +
+ + +
Good luck!
+ + + +
+ + Want to start your own Secret Santa with your friends? Click here to get started! + +