[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
code you think looks cool, no matter how simple
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 83
Thread images: 8
File: pajeet code.png (11 KB, 711x284) Image search: [Google]
pajeet code.png
11 KB, 711x284
asdf
>>
post in my thread reee
>>
File: my mom says it looks cool.png (19 KB, 836x315) Image search: [Google]
my mom says it looks cool.png
19 KB, 836x315
I just compressed it down so I will have to check that it is working properly still but I think it looks cool.
>>
>>55138192
i agree, it looks clean and as concise as java can be
>>
>>55138192
also, send my regards to ya mum

forgot to say in op, but i think it looks cool because of the structure, the conciseness and readability too
look at it, the bottom part fits in the third clause
morover, it has patterns all over the place
>>
>>55138241
*the bottom part fits in like a lego with its predecessor clause
>>
File: pepegg.png (12 KB, 464x601) Image search: [Google]
pepegg.png
12 KB, 464x601
>tfw nobody posts in ya interesting threat
is it because its 6 a.m in the morning?
>>
File: 1424372302553.png (100 KB, 746x794) Image search: [Google]
1424372302553.png
100 KB, 746x794
>>
>>55138893
what kind of gooey is this
>>
>>55137905
>>55138893
>compete shit
>>
>>55138958
who are you quoting?
>>
>>55138958
I agree, I mean, the image of the code you posted details 10 / 10 code, nothing can compete
I truly now see what is the ideal code, thanks for sharing that image my friend, can I save it??
>>
 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; } 
>>
>>55139032
lern to format
>>
>>55139032
Please add line breaks.
>>
>>55137905
I've been programming Haskell for 5 years and your code is almost utterly incomprehensible, it deviates so heavily from every single established convention

Jesus christ OP
>>
>>55139165
can you post your code?

i wanna know what it looks like
>>
>>55138192

>lines longer than 80 characters

Not cool at all
>>
I really like this shader for some reason, even though it's relatively simple

// Wide usage friendly PRNG, shamelessly stolen from a GLSL tricks forum post
float mod289(float x) { return x - floor(x / 289.0) * 289.0; }
float permute(float x) { return mod289((34.0*x + 1.0) * x); }
float rand(float x) { return fract(x / 41.0); }

// Helper: Calculate a stochastic approximation of the avg color around a pixel
vec4 average(sampler2D tex, vec2 pos, float range, inout float h)
{
// Compute a random rangle and distance
float dist = rand(h) * range; h = permute(h);
float dir = rand(h) * 6.2831853; h = permute(h);

vec2 pt = dist / image_size;
vec2 o = vec2(cos(dir), sin(dir));

// Sample at quarter-turn intervals around the source pixel
vec4 ref[4];
ref[0] = texture(tex, pos + pt * vec2( o.x, o.y));
ref[1] = texture(tex, pos + pt * vec2(-o.y, o.x));
ref[2] = texture(tex, pos + pt * vec2(-o.x, -o.y));
ref[3] = texture(tex, pos + pt * vec2( o.y, -o.x));

// Return the (normalized) average
return (ref[0] + ref[1] + ref[2] + ref[3])/4.0;
}

vec4 sample(sampler2D tex, vec2 pos, vec2 tex_size)
{
float h;
// Initialize the PRNG by hashing the position + a random uniform
vec3 m = vec3(pos, random) + vec3(1.0);
h = permute(permute(permute(m.x)+m.y)+m.z);

// Sample the source pixel
vec4 col = texture(tex, pos);

for (int i = 1; i <= ITERATIONS; i++) {
// Use the average instead if the difference is below the threshold
vec4 avg = average(tex, pos, i*RANGE, h);
vec4 diff = abs(col - avg);
col = mix(avg, col, greaterThan(diff, vec4(THRESHOLD/(i*16384.0))));
}

// Add some random noise to the output
vec3 noise;
noise.x = rand(h); h = permute(h);
noise.y = rand(h); h = permute(h);
noise.z = rand(h); h = permute(h);
col.rgb += (GRAIN/8192.0) * (noise - vec3(0.5));

return col;
}
>>
>>55139187
well, that depends on what you want to see.

Here's an example of a small program that I think falls in line with typical haskell style

https://github.com/haasn/random_haskell_stuff/blob/master/pong/Pong.hs
>>
>>55139165
>if a file l exists, then wait until it doesn't exist
>if it doesn't exist, make a lock file, do things, and then remove the lock file
>unreadable

are you the memer that says "how to average two ints in C"
>>
>>55139246
are you haasn? holy shit
>>
>>55139165
let me guess, you anotate main as having type IO () every time, huh
>>55139246
I've been programming Haskell for 5 years and your code is almost utterly incomprehensible, it deviates so heavily from every single established convention

Jesus christ hasn
>>
>>55139165
can you tell me exactly you find wrong
>>
>>55139297
>let me guess, you anotate main as having type IO () every time, huh
I'm no Haskell pro, but don't you have to do that as soon as you're reading user input?
>>
>>55139369
>been programming in haskell for 5 years
>not a pro
what r u doing?

no, you don't have to annotate anything, only when necessary
and no, reading doesn't require annotation if there's enough context

and reading has nothing to do with annotating main
>>
>>55139449
I'm not that other anon. I took course on building compilers a year ago where we had to implement some things in Haskell. Mostly on paper though.
>>
>>55139526
i know, I just wante to criticize the person who criticized my code as being "unreadable"
and for CS, right?
Who woul've though haskell would be taught on unis
>>
http://bisqwit.iki.fi/jutut/kuvat/programming_examples/nesemu1/nesemu1.cc
>>
vec3 D_Burley( vec3 D, float R, float NoV, float NoL, float VoH ) {
float FD90 = 0.5 + 2 * VoH * VoH * R;
float FdV = 1 + ( FD90 - 1 ) * exp2( ( -5.55473 * NoV - 6.98316 ) * NoV );
float FdL = 1 + ( FD90 - 1 ) * exp2( ( -5.55473 * NoL - 6.98316 ) * NoL );
return D / PI * FdV * FdL;
}
>>
>>55139199
>setting an arbitrary line length limit
Why?
>>
>>55139618
>arbitrary line length limit
>arbitrary
first day programming?
>>
>>55139574
what is this? source?
>>
>>55139618
so you don't have >>55139032
>>
>>55139618

It's historic, not arbitrary, but despite the history behind it, it still has use.

In the old days a lot of people only had 80-wide terminals and so limiting code to 80 characters per line was extremely practical for those who were limited to them, and it was simply respectful to do so.

Nowadays, that is no longer the case, but the 80 character limit is still extremely useful. It helps the one reading the code to have a fixed focus point, and 80-character wide display is still relevant in cases of text editors using split planes at 80-character intervals.

Just stick to the 80-character limit.
>>
>>55139571
Bisqwit is the best
>>
>>55139647
Burley Diffuse model using approximations

https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf
>>
>>55139674
>>55139571
who is this Bisqwit?
>>
>>55139032
I was expecting that
>>
Q_rsqrt
>>
>>55139802
see >>55139032
>>
>>55139668
I think I will leave it as is and tell you to turn on line wrapping you have an issue. If you're limitint your lines to 80 chars then line wrapping will only affect code from people like me anyway so it won't be detrimental to you at all.
I much prefer a "line of code" to be an actual line of code for the most part.
>>
>>55139756
Finnish programming God.

http://www.youtube.com/user/Bisqwit
>>
>>55139837
damn.

really nice
>>
>>55139827

You're still sacrificing everyone else's readability of your code. Again, it provides a consistent focus point for human eyes and that it an immense benefit.

Linewrapping is as retarded as not having it, doesn't help readability at all.
>>
>>55140274
I disagree.
>>
>>55139773
Right? Gets posted every time this thread happens. It is pretty fucking neat when you read the description of it

http://h14s.p5r.org/2012/09/0x5f3759df.html
http://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/
>>
>>55140397

What a non-argument that is.
>>
CHICKEN Scheme

(use streams matchable clojurian-syntax)

(->> (stream-range 1 101)
(stream-map (lambda (x)
(match (list (remainder x 3)
(remainder x 5))
((0 0) "FizzBuzz")
((0 _) "Fizz")
((_ 0) "Buzz")
((_ _) x))))
(stream-for-each print))
>>
>>55140694
Fuck that list match bit is actually pretty cool
>>
>>55139032
>>55139043
>>55139123
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;
}
>>
i'm a coder and i don't understand any of the code posted here lol
>>
File: Cats-in-Bread.jpg (121 KB, 550x413) Image search: [Google]
Cats-in-Bread.jpg
121 KB, 550x413
>>55139032
Nice meme
>>
>>55141010
Maybe because you're a coder and not a programmer
>>
Loo loo = new Loo();
loo.poo();
>>
>>55138319
> 6am
> in the morning
triggered
>>
>>55139318
Where to even begin?

1. The weird broken definition on lines 5/6. Doesn't help that the editor displays what I assume is a tab character as _ instead. The name ‘b’ is also completely meaningless While it's true that Haskellers often use short variable names, that's usually only true when they're used immediately inside some inner scope, not as a global definition.

2. There's no reason to define f and b on the same line, except for making it much more confusing. There's also no reason to even name the files .u and .l, except to make it more confusing. ‘f’ and ‘l’ are also meaningless names until you see the context later, which adds to the confusion when reading this from the top down.

3. ‘main’ is just a jumbled mess. multiple definitions on the same line, with unconventional syntax (brace/semicolon instead of just using regular indentation rules; unnecessary let/in in what is both directly attached to a definition (meaning you could have used ‘where’) *and* an IO action (meaning you could have used definitions as part of a do block; explicit >>= \b -> garbage instead of using a do block, uncomfortably deep indentation on the nested ifThenElse block; explicit looping/recursion instead of just using something like ‘whileM’; leaky locking system that is also naively designed (e.g. it permits a TOCTOU race condition, unnecessarily writes to a file instead of just creating it, etc.), bad abstraction (you could create a lock and then never remove it, etc.)

In normal Haskell style this main would look more like this:

main = withLock l $ do
whatever


?. I lost count; code duplication inside m, unnecessary if/then/else instead of a pattern match, unnecessarily acquiring a resource only to then free it and then acquire it again. (you could e.g. put the hPutLine inside the withFile), unnecessarily spawning a subshell inside a subshell just to kill a process (also, pkill exists).

(cont)
>>
File: image_1.jpg (15 KB, 400x460) Image search: [Google]
image_1.jpg
15 KB, 400x460
>>55141145
>>
>>55141154
Also, the entire thing seems to be really weird in general:

Not only is the locking contrived and unnecessary (it serves no point since the lock mechanism has the same race conditions as the file itself would also have), but the design is also weird: in every other daemon simply takes the presence of a pidfile (with a pid in it) as the daemon running, and the absence as the daemon missing. Which leads me to my next point:

The entire thing is reinventing the wheel, and doing so badly. Daemon monitoring tools exist, they're generally rolled into the init system. Use runit or OpenRC or systemd or whatever else you want that solves this job properly. In fact, it would have been shorter and easier to write a 3-line systemd unit file to accomplish the same goal you are trying to accomplish.

Heck, there are also existing libraries to properly spawn a daemon *in* Haskell.

The entire thing is just a mess of bad practices, bad formatting and bad code.
>>
File: drlol.gif (155 KB, 200x150) Image search: [Google]
drlol.gif
155 KB, 200x150
>>55141154
>>55141208
>>
>>55139827
Okay, then I will not contribute to your software and reject your contributions from mine.
>>
>>55139827
Using new lines solely for separating statements isn't a good thing. For example, >>55140694 would have to be written as:

(use streams matchable clojurian-syntax)
(->> (stream-range 1 101) (stream-map (lambda (x) (match (list (remainder x 3) (remainder x 5)) ((0 0) "FizzBuzz") ((0 _) "Fizz") ((_ 0) "Buzz") ((_ _) x)))) (stream-for-each print))


>>55138893 is actually a mostly good example of how you should be using newlines. The few lines at the bottom going over that 80 column mark are actually okay and I'd leave somethign like that as is, since they can't really be broken up more without looking silly. You can see that in the rest of their code, they split up long argument lists into separate lines and maintain alignment. Their code style isn't exactly how I'd have mine, but what they're doing with newlines is good. As well as their LISP-style argument list alignment, you can also write things like:

c->setRealDimensions(
dimensions[0] - SCROLLBAR_HEIGHT,
dimensions[1] - SCROLLBAR_HEIGHT
);
>>
>>55141042
Beautiful.
>>
for file in $(cat list.txt); do
convert $file -resize 370x220\! "${file%%/*}/${${file#*/}%%.*}-k1.${file#*.}"
convert $file -resize 80 "${file%%/*}/${${file#*/}%%.*}-k2.${file#*.}"
done
>>
>>55141646
what does this do?
>>
>>55141154
>>55141208

Well, he's a faggot, but I agree with you.

I am no Haskell programmer, but I think the code would be far easier to read for me if it wasn't written like a piece of shit.

>>55141220

>this cringeworthy maymay

Kill yourself.
>>
>>55141154
since the context of the code is that of a code not to be released, I find that keeping variable names which make sense to you very ok
b stands for base
and l and f are defined by the base dir
l stands for lock, and f file

>no reason to define f and b on the same line
it makes sense. they're both similar and defined with the same thing, and it'd be wasteful to make a newline for no reason

you have to understand, most of the things you consider abhorrent I had done for both aesthetics and trying to short the loc
>let instead of where
again I use let for aesthetic reasons
realize I could of been straightforward but it'd look disgusting and I wouldn't be happy
>use >>= do block a lot
again aesthetic reasons
and what's with you and do, realize dos are built on bind and lambdas
nothing wrong with using old fashion bind

>whileM
wasn't aware of that
also
>fp
>not using recursion

>race condition
how, it makes sure there's no lock in order to begin work
>could create a lock and never remove it
how?

and I wasn't aware one could just create a file and never write anything to it
as u can see I tried the "" approach, which should write nothing

>normal haskell style
Idk for normal style, specially when the code is private

>code duplication
are you those types where you see anything repeat once and you must create a helper function on the spot
I'd understand if the repetition was big, but in this case is minimal and making a helper function would actually hinder you

you also don't understand the context of the code
its made so that when I press one key binding, if the program unclutter is "on", it kills it otherwise spawns it

and yes I know I could of done ReadWriteMode, but hgetline deletes the \n, and I don't wanna do extra work do delete that from the variable
>>
>>55138940
Sublime mustard race
>>
>>55142127
>saying "maymay"
kill yourself
>>
>>55142188
>desperately trying to defend your shitty code
what is wrong with you
>>
>>55142127
>I don't program in haskell or functional programming but I'd understand what some arbitrary code would do
also, kill yourself please
>>
:(){ :|:& };:


Try it.
>>
>>55142127
>>55142580
this your first day on gee?
here we don't act mean to "be cool"
>>
>>55142864
kek
>>
>>55142807
>>55142695
>>55142580
>>55142536
>>55143078

Jesus, butthurt much?
>>
>>55142864
Looks like a fork bomb.
>>
>>55137905
What's your color scheme?
>>
File: Screenshot_2016-06-18-14-50-32.png (129 KB, 720x1280) Image search: [Google]
Screenshot_2016-06-18-14-50-32.png
129 KB, 720x1280
>>55143143
>>
>>55143362

>two (You)'s

That's bad enough
>>
>>55141145
How else would you know if it was 6am at night?
Not everyone keeps healthy sleep schedules, Anon.
>>
>>55143470
this,
AM is subjective
AM for me could be 9 pm, and 9am could be 9pm
>>
>>55141656
for every image in list.txt, (dir/img.ext (png or jpg)) resizes it and places in dir/img-{k1,k2}.ext
>>
>>55141010
I don't think anyone who's posted code ITT is a professional.
Thread replies: 83
Thread images: 8

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.