• What are you working on? November 2011 Edition
    3,673 replies, posted
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=Octave;33516005][cpp]{ "00000000", "00000001", "00000010", "00000011", "00000100", "00000101", "00000110", "00000111", "00001000", "00001001", "00001010", "00001011", "00001100", "00001101", "00001110", "00001111", "00010000", "00010001", "00010010", "00010011", "00010100", "00010101", "00010110", "00010111", "00011000", "00011001", "00011010", "00011011", "00011100", "00011101", "00011110", "00011111", "00100000", "00100001", "00100010", "00100011", "00100100", "00100101", "00100110", "00100111", "00101000", "00101001", "00101010", "00101011", "00101100", "00101101", "00101110", "00101111", "00110000", "00110001", "00110010", "00110011", "00110100", "00110101", "00110110", "00110111", "00111000", "00111001", "00111010", "00111011", "00111100", "00111101", "00111110", "00111111", "01000000", "01000001", "01000010", "01000011", "01000100", "01000101", "01000110", "01000111", "01001000", "01001001", "01001010", "01001011", "01001100", "01001101", "01001110", "01001111", "01010000", "01010001", "01010010", "01010011", "01010100", "01010101", "01010110", "01010111", "01011000", "01011001", "01011010", "01011011", "01011100", "01011101", "01011110", "01011111", "01100000", "01100001", "01100010", "01100011", "01100100", "01100101", "01100110", "01100111", "01101000", "01101001", "01101010", "01101011", "01101100", "01101101", "01101110", "01101111", "01110000", "01110001", "01110010", "01110011", "01110100", "01110101", "01110110", "01110111", "01111000", "01111001", "01111010", "01111011", "01111100", "01111101", "01111110", "01111111" };[/cpp][/QUOTE] 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=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 &#8216;\302&#8217; in program aaa.c:56:1: error: stray &#8216;\240&#8217; in program aaa.c:56:1: error: stray &#8216;\302&#8217; in program aaa.c:56:1: error: stray &#8216;\240&#8217; in program aaa.c:56:1: error: stray &#8216;\302&#8217; in program aaa.c:56:1: error: stray &#8216;\240&#8217; in program aaa.c:56:1: error: stray &#8216;\302&#8217; in program aaa.c:56:1: error: stray &#8216;\240&#8217; 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.