I was actually referencing the if/else if/else if joke, but whatever. I'll snip it if it bothers you that much :)
[editline]1st December 2011[/editline]
On the topic of the thread; I'm working on making a "File Mover" tool for Uplink, because whenever I played that game I always felt a need to rearrange the contents of my databanks.
Should make for a decent exercise in getting used to how that sort of stuff works.
After seeing the Terraria example, I think no-one else can ever make that funny again.
(But I'll never find the pastebin code again... Basically every item in Terraria was checked over with an if/elseif structure - hundreds of lines! The indentation wrapped onto newlines!)
[QUOTE=amcfaggot;33518187]Well, I'll be. It worked! Now I don't have to do any more gsub stuff. Thank you, LuaStoned. :)
[code]C:\Users\Andrew\Documents\Facepunch Lua API>lua main.lua
amcfaggot
Soviet_Banter
Titz
synthiac
supersnail11
Octave
Lord-Ned
ROBO_DONUT
mutated
Yogurt
ZenX2
Deco-Da-Man
chimitos
LuaStoned
Ortzinator
[/code]
[editline]1st December 2011[/editline]
Tomorrow I'll have it grab the actual displayed username rather than the href SEO names. If I don't, you'll see hyphens where spaces should be for some names.[/QUOTE]
Since amc was struggling with Lua Patterns I created this small (but hopefully useful) utility:
[lua]
local help = [[Lua Pattern Help:
. (a dot) matches any character
%a : from a to z upper and lower case
%c : special characters \t \n etc.
%d : digits( from 0 to 9 )
%l : any letter that is lower case
%p : punctuation characters . , etc.
%s : space characters <space> tab etc.
%u : any letter that is upper case
%w : alphanumeric characters ( all letters and numbers )
%x : hexadecimal digits ( 0-9, a-f, A-F )
%z : null character \0
%x : represents itself ( x is any non-alphanumeric character )
[s] : Union of characters
[^s] : Opposite of the Union s
Upper case will match the opposite, %A matches non letters
Characters separated with - eg. 0-5, a-e will match everything inbetween
+ after a class matches 1 or more and the longest sequence
- after a class matches 0 or more and the shortest sequence
* after a class matches 0 or more and the longest sequence
? after a class matches 1 or 0 characters
%n ( n is a digit between 1 and 9 ) will match the nth capture
%bXY matches strings that start with X and end with Y
% is the escape character
Starting the pattern with ^ will match a string at the beginning
Ending the pattern with $ will match a string at the end]]
function Pattern(...)
local cmd = ""
print("Enter your pattern below:")
while (cmd ~= "stop" and cmd ~= "exit") do
io.write("-> ")
cmd = io.read()
if (cmd ~= "help") then
for _, str in pairs({...}) do
if (type(str) == "string") then
for match in string.gmatch(str, cmd) do
print("=> " .. match)
end
end
end
else
print(help)
end
end
end
--[[
Usage: Pattern("one", "or more strings", "you want to check with your pattern")
It'll switch into the interactive mode you can leave with stop or exit.
]][/lua]
[QUOTE=subenji99;33519036]After seeing the Terraria example, I think no-one else can ever make that funny again.
(But I'll never find the pastebin code again... Basically every item in Terraria was checked over with an if/elseif structure - hundreds of lines! The indentation wrapped onto newlines!)[/QUOTE]
Fair enough, I guess I can't top that! There are quite a few places in Uplink that do similar things to this, it makes me wonder why they didn't use a hashmap or some other viable alternative that would have simplified the code a lot.
[QUOTE=Chris220;33519057]Fair enough, I guess I can't top that! There are quite a few places in Uplink that do similar things to this, it makes me wonder why they didn't use a hashmap or some other viable alternative that would have simplified the code a lot.[/QUOTE]
If I remember correctly, Uplink was Chris Delay's first project - literally written in his bedroom, which gave rise to their motto "last of the bedroom programmers". Given this situation, I can see why he wasn't using the most efficient\cleanest\best code - he probably didn't know any better at the time.
[QUOTE=amcfaggot;33517944]Wikipedia syndrome is a fascinating thing; I don't know of any other website I can lose so much time on and not realize it, even if I'm in the middle of a Hitler-related article.[/QUOTE]
tvtropes
See you in a week
[editline]1st December 2011[/editline]
Also, new thread time
[QUOTE=mechanarchy;33519119]If I remember correctly, Uplink was Chris Delay's first project - literally written in his bedroom, which gave rise to their motto "last of the bedroom programmers". Given this situation, I can see why he wasn't using the most efficient\cleanest\best code - he probably didn't know any better at the time.[/QUOTE]
Hm, I didn't know that. That's pretty awesome!
[QUOTE=Murkrow;33519125]tvtropes[/QUOTE]
cracked
[QUOTE=Murkrow;33519125]Also, new thread time[/QUOTE]
That's true. I wonder - Has anyone happened to collect some highlights yet?
[QUOTE=Chris220;33518720]So there I was, browsing the Uplink source code when suddenly...
[cpp]ifelseifelse[/cpp]
That's some [I]sexy[/I] code right there.[/QUOTE]
Since C++ can't do switch/case over strings, it's a bit more understandable that they did it with ifelse.
[QUOTE=simie;33519321]Since C++ can't do switch/case over strings, it's a bit more understandable that they did it with ifelse.[/QUOTE]
Good point - it's the same in the Source Engine
[cpp]
if (Q_stristr( entname, "func_button" ) == 0 ) return new CFuncButton();
else if (Q_stristr( entname, "weapon_pistol" ) == 0 ) return new CWeaponPistol();
else if (Q_stristr( entname, "something_else" ) == 0 ) return new CSomethingElse();
[/cpp]
Oh wait no it isn't, this is what [URL="http://en.wikipedia.org/wiki/Abstract_factory_pattern"]factories [/URL]are for.
[QUOTE=garry;33519787]Good point - it's the same in the Source Engine
[cpp]
if (Q_stristr( entname, "func_button" ) == 0 ) return new CFuncButton();
else if (Q_stristr( entname, "weapon_pistol" ) == 0 ) return new CWeaponPistol();
else if (Q_stristr( entname, "something_else" ) == 0 ) return new CSomethingElse();
[/cpp]
Oh wait no it isn't, this is what [URL="http://en.wikipedia.org/wiki/Abstract_factory_pattern"]factories [/URL]are for.[/QUOTE]
I did only say its a bit more understandable, not the best way to do it.
[QUOTE=q3k;33520264]dude. dude no. no, dude, no, just no.
[cpp]#include <stdio.h>
#include <string.h>
static char *b64_lut = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void bin_to_b64(char *out, char* in, unsigned int in_length)
{
unsigned int complete_quads = in_length / 3;
unsigned int additional = in_length - complete_quads * 3;
for (unsigned int i = 0; i < complete_quads; i++)
{
char a, b, c;
a = in[i * 3]; b = in[i * 3 + 1]; c = in[i * 3 + 2];
out[i * 4 ] = b64_lut[ (a & 0b11111100) >> 2 ];
out[i * 4 + 1] = b64_lut[((a & 0b00000011) << 4 ) | ((b & 0b11110000) >> 4)];
out[i * 4 + 2] = b64_lut[((b & 0b00001111) << 2) | ((c & 0b11000000) >> 6)];
out[i * 4 + 3] = b64_lut[ c & 0b00111111 ];
}
unsigned int final_length = complete_quads * 4;
switch (additional)
{
case 1:
{
char a = in[complete_quads * 3];
out[complete_quads * 4 ] = b64_lut[(a & 0b11111100) >> 2];
out[complete_quads * 4 + 1] = b64_lut[(a & 0b00000011) << 4];
out[complete_quads * 4 + 2] = '=';
out[complete_quads * 4 + 3] = '=';
final_length += 4;
break;
}
case 2:
{
char a, b;
a = in[complete_quads * 3]; b = in[complete_quads * 3 + 1];
out[complete_quads * 4 ] = b64_lut[ (a & 0b11111100) >> 2 ];
out[complete_quads * 4 + 1] = b64_lut[((a & 0b00000011) << 4) | ((b & 0b11110000) >> 4)];
out[complete_quads * 4 + 2] = b64_lut[((b & 0b00001111) << 2) ];
out[complete_quads * 4 + 3] = '=';
final_length += 4;
break;
}
}
out[final_length] = 0;
}
int main()
{
char *in = "t87nct7g3mcv57o2yt43";
char out[200];
bin_to_b64(out, in, strlen(in));
printf("b64: %s\n", out);
}[/cpp]
It's still not wonderful code, but at least it isn't string-oriented programming.[/QUOTE]
Any idea why it's giving me this error on every line?
[code]aaa.c:56:1: error: stray ‘\302’ in program
aaa.c:56:1: error: stray ‘\240’ in program
aaa.c:56:1: error: stray ‘\302’ in program
aaa.c:56:1: error: stray ‘\240’ in program
aaa.c:56:1: error: stray ‘\302’ in program
aaa.c:56:1: error: stray ‘\240’ in program
aaa.c:56:1: error: stray ‘\302’ in program
aaa.c:56:1: error: stray ‘\240’ in program
[/code]
Also... I didn't know you could directly deal with binary values in C, I swear I read that there was only octal and hex. The whole lookup table and string representation wouldn't have been necessary if I had known that.
[QUOTE=Darwin226;33518692]Well we're working with complex number in math class and when you want to square it you first translate it to trigonometric form then the square is r^2(cos(2*angle) + i*sin(2*angle)).[/QUOTE]
You don't have to use trig to square it. It's like polynomial multiplication. FOIL.
i.e.
(x + iy)*(x + iy) = x*x + 2iyx - y*y
Remember that i = sqrt(-1) so i*i = -1.
In code this is:
[code]
z.r = z.r * z.r - z.i * z.i
z.i = 2.0 * z.r * z.i
[/code]
[editline]1st December 2011[/editline]
[QUOTE=Octave;33520303]Also... I didn't know you could directly deal with binary values in C, I swear I read that there was only octal and hex. The whole lookup table and string representation wouldn't have been necessary if I had known that.[/QUOTE]
You can't write binary constants in standard C. That's a compiler-specific extension.
You don't need it, either. Each digit of a hex character represents four bits (this is exactly why it's there), and it isn't hard to do bit-twiddling stuff in hex.
0x1 = 0b0001
0x2 = 0b0010
0x4 = 0b0100
0x8 = 0b1000
0xC = 0b1100
0xF = 0b1111
0x8F = 0b10001111
Use it a little and you'll get used to it, and start thinking in hex/binary.
[QUOTE=Yogurt;33516444]Parsing HTML with regex...[/QUOTE]
How do you parse it otherwise?
Fractals are fun
[IMG]http://dl.dropbox.com/u/17216535/screengrab_20111201150605.png[/IMG]
Still doing something wrong, though. That's supposed to be a dragon curve...
[IMG]http://dl.dropbox.com/u/17216535/screengrab_20111201153043.png[/IMG]
Oh wow found that one by accident :D (13 iterations/levels of recursion, takes 5 mins to render)
Next up: first trying to get an actual dragon curve out of it, then ditching that and trying colour coding stuff, maybe even some 3D stuff, and in my wildest dreams a function that takes a random curve (could be your name in cursive) and uses that as a base figure.
[code]
function draak(X,Y,n)
hold on %Need to hold the current figure window, otherwise it'll draw each line segment in a new window
if n==0
axis square % x & y axis are same scale
plot(X,Y) %Plots the given line if recursion level is 0
else
m=n-1; %Reduce recursion level by 1
v=[X(1,2)-X(1,1) Y(1,2)-Y(1,1)]; %Move the X,Y line to origin (X contains the x coordinates of two points (row vector form))(Y analogous to X)
h=atan(v(1,2)/v(1,1)); %Determine angle with x-axis
R1=[cos(-h) -sin(-h); sin(-h) cos(-h)]; %Rotation matrix
R2=R1'; %Inverse rotation matrix
p=R1*[v(1,1) v(1,2)]'; %Rotate line so it's parallel with x-axis
p=p'; %Terug transponeren %Make p a row vector again
k1=[0 -p(1,1)/2]'; %k1 k2 and k3 determine the shape that replaces this line, you can modify these to change the fundamental replacement shape,
k2=[p(1,1)/2 -p(1,1)/2]'; %though try changing the stuff below first, it's easier
k3=[p(1,1)/2 0]';
l1=(R2*k1+[X(1,1) Y(1,1)]')'; %Use inverse rotation and translate them to where the X,Y line is
l2=(R2*k2+[X(1,1) Y(1,1)]')';
l3=(R2*k3+[X(1,1) Y(1,1)]')';
%Dragon curve preset:
draak([X(1,1) l1(1,1)],[Y(1,1) l1(1,2)],m) %calls the function on every line of the figure that replaces the original line, but with recursion m=n-1,
draak([l2(1,1) l1(1,1)],[l2(1,2) l1(1,2)],m) %changing these four thingies will also drastically change the curve
draak([l2(1,1) l3(1,1)],[l2(1,2) l3(1,2)],m)
draak([X(1,2) l3(1,1)],[Y(1,2) l3(1,2)],m)
end
hold off %Done drawing stuff
end
% Other preset:
% draak([X(1,1) l2(1,1)],[Y(1,1) l2(1,2)],m)
% draak([l2(1,1) X(1,2)],[l2(1,2) Y(1,2)],m)
% draak([l2(1,1) l3(1,1)],[l2(1,2) l3(1,2)],m)
%draak([X(1,2) l3(1,1)],[Y(1,2) l3(1,2)],m)
[/code]
Another one (the code also has this one as a preset):
[IMG]http://dl.dropbox.com/u/17216535/screengrab_20111201154249.png[/IMG]
Just realised I forgot to save all the previous configurations. Although there seems (well there actually ARE) to be an endless amount of cool shapes...
Edit:
Got it:
[IMG]http://dl.dropbox.com/u/17216535/screengrab_20111201160001.png[/IMG]
[QUOTE=synthiac;33517768]i thought i wouldn't need to explain why it's not a hash table because i supposedly don't know what they are![/QUOTE]
easy there buddy, you don't wanna become the next nullsquared
what a douche that guy was
[QUOTE=Naarkie;33520680]How do you parse it otherwise?[/QUOTE]
HTML parsers. Always use a proper parser if you need to parse the HTML. If you need to extract data, regexp can work.
See also:
[url]http://stackoverflow.com/a/1732454[/url]
[url]http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not[/url]
If we go into linguistics (I'm not really familiar), HTML is a [url=http://en.wikipedia.org/wiki/Context-free_grammar]context-free language[/url] and thus can't be described by a [url=http://en.wikipedia.org/wiki/Regular_language]regular language[/url] (ex. regexp)
[QUOTE=raBBish;33520986]HTML parsers. Always use a proper parser if you need to parse the HTML. If you need to extract data, regexp can work.
See also:
[url]http://stackoverflow.com/a/1732454[/url]
[url]http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not[/url]
If we go into linguistics (I'm not really familiar), HTML is a [url=http://en.wikipedia.org/wiki/Context-free_grammar]context-free language[/url] and thus can't be described by a [url=http://en.wikipedia.org/wiki/Regular_language]regular language[/url] (ex. regexp)[/QUOTE]
There's a worksheet for my course that involves converting LaTeX into HTML using regex.
I'm not doing on moral grounds.
[QUOTE=Murkrow;33519125][editline]1st December 2011[/editline]
Also, new thread time[/QUOTE]
anyone got a content scraper?
Who makes the new Thread?
[QUOTE=thisBrad;33515310]Shows what I'm listening to in winamp in real-time.
But I just realized fucking avatars are cached :( God damn it. It's useless on this forum now.
edit:
They aren't even cached, they are copied right over to the fucking FP server.[/QUOTE]
Late but most, if not all, forums copy avatars.
[QUOTE=benjojo;33521156]Who makes the new Thread?[/QUOTE]
[code]
var waywo_dec = new Thread("What are you working on? - Final 2011 version")
facepunch.getForum(240).addThread(waywo_dec)
[/code]
[t]http://dl.dropbox.com/u/7995419/Screenshot/1322754742.png[/t]
I just wanted to let you know that I could create an empty window.
Also
[t]http://dl.dropbox.com/u/7995419/Screenshot/1322757358.png[/t]
why do SFML sprites have a white max-alpha pixel in their top left corner when uninitialized?
:( Sorry guys, my Facepunch API isn't gonna be done in time to scrape content (partially why I started on it), so that video won't be done in time. Instead, I think I'll work on the video for December and make it a larger "saying goodbye to 2011" type dealio.
I do have a couple resources to start the generation process with though! :)
Mind if I just make it?
This is the [U]November[/U] edition after all.
[QUOTE=Darkwater124;33522360][B]Mind if I just make it?[/B]
This is the [U]November[/U] edition after all.[/QUOTE]
yes.
we have no highlights. A new thread is silly without highlights since that's kinda the whole reason to make a new thread in the first place.
-snip-
[QUOTE=amcfaggot;33522442][table="width: 100%, align: center"]
[td="align:center"][IMG]http://i.imgur.com/bK3RZ.png[/IMG][/td]
[/table]
Here's a header logo for the new thread. Do you want a "Highlights" header as well? Anything else we need besides highlights (obviously)?[/QUOTE]
Awards for special stuff
Sorry, you need to Log In to post a reply to this thread.