1 registered members (AbrahamR),
717
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: fogman]
#444593
08/14/14 20:06
08/14/14 20:06
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
using System.Collections.Generic; Someone just encountered the awesomeness of having a awesome standard library? I have two snippets: C#
list.RemoveAll((client) => !client.Update());
C/C++
void magicFunc(char *d, const char *s) {
while(*d++ = *s++);
}
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: MasterQ32]
#444600
08/14/14 22:25
08/14/14 22:25
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
String copy and functional programming. I can +1 the functional programming with reactive functional programming. I know that C# can do it better, but oh well.
RAC(createButton, enabled) = [RACSignal
combineLatest:@[ RACObserve(self, password), RACObserve(self, passwordConfirmation) ]
reduce:^(NSString *password, NSString *passwordConfirm) {
return @([passwordConfirm isEqualToString:password]);
}];
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: MasterQ32]
#444601
08/14/14 22:26
08/14/14 22:26
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Java 7 allows switches on strings. O-m-f-g!
public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
String typeOfDay;
switch (dayOfWeekArg) {
case "Monday": typeOfDay = "Start of work week";
break;
case "Tuesday":
case "Wednesday":
case "Thursday": typeOfDay = "Midweek";
break;
case "Friday": typeOfDay = "End of work week";
break;
case "Saturday":
case "Sunday": typeOfDay = "Weekend";
break;
default: throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
}
return typeOfDay;
}
Last edited by HeelX; 08/14/14 22:27.
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: HeelX]
#444604
08/14/14 22:45
08/14/14 22:45
|
Joined: Oct 2002
Posts: 806
Zapan@work
User
|
User
Joined: Oct 2002
Posts: 806
|
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: HeelX]
#444605
08/14/14 22:50
08/14/14 22:50
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
@Sid: I just wondered that you know C# that good, but then i stopped wondering. Testing programming languages is a nice thing, but sometimes hard to get into I for myself keep distance to Objective-C, so much parenthesis, @s and stuff @HeelX: And that's why C# is better. Could do it from day 0. No, just kidding, but i have a strong personal preference to C# over Java as i like the concepts built into the language (structs, function pointers / delegates and the standard library is really awesome) Another snippet in Lua:
Object = { new = function (self)
local o = {}
setmetatable(o, self)
self.__index = self
return o
end }
EDIT: @Zapan@work: One of the most awesome C hacks i've ever seen.
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: MasterQ32]
#444613
08/15/14 07:24
08/15/14 07:24
|
Joined: Aug 2003
Posts: 7,439 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,439
Red Dwarf
|
i have a strong personal preference to C# over Java fuck java, seriously. Fuck it right up the fucking arse with a 100" big black dildo. edit: a dildo with titanium thorns and coated in 1.000.000 scoville hot sauce. On fire.
Last edited by Michael_Schwarz; 08/15/14 07:30.
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: Michael_Schwarz]
#444628
08/15/14 17:08
08/15/14 17:08
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
i have a strong personal preference to C# over Java fuck java, seriously. Fuck it right up the fucking arse with a 100" big black dildo. edit: a dildo with titanium thorns and coated in 1.000.000 scoville hot sauce. On fire. Can this scale up? And sideways? Nope? Meh.
|
|
|
Re: What's (currently) your favourite snippet of code?
[Re: HeelX]
#444629
08/15/14 17:36
08/15/14 17:36
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
That dildo can scale diagonally if you use it with the wrong angle
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|