[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
/dpt/ - Daily Programming Thread
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: 255
Thread images: 44
File: ew.png (389 KB, 934x1000) Image search: [Google]
ew.png
389 KB, 934x1000
What are you working on, /g/?

Old thread: http://boards.4chan.org/g/thread/52146363/dpt-daily-programming-thread#bottom
>>
First for multi-threading support

>>52152486
>>
File: mems.jpg (362 KB, 1366x768) Image search: [Google]
mems.jpg
362 KB, 1366x768
>>52152484
Posting image downloader code, python 2.7 with requests installed
filename.py board threadNumber

import urllib,sys,requests,os

board,thread=sys.argv[1:]

url="https://a.4cdn.org/"+board+"/thread/"+thread+".json"

posts=requests.get(url).json()["posts"]
title=posts[0]["semantic_url"]

newDir=os.getcwd()+"\\"+board+"\\"+title+" ("+thread+")"

if not os.path.exists(newDir):
os.makedirs(newDir)

for keys in posts:
if "tim" in keys:
urllib.urlretrieve("https://i.4cdn.org/"+board+"/"+str(keys["tim"])
+keys["ext"],newDir+"\\"+str(keys["tim"])+keys["ext"])
>>
>>52152484
New Hime thread in 296 posts!
>>
>>52152520
>urllib
>AND requests
why
>>
>>52152531
I'll beat you again senpai.
>>
>>52152548
Not if I beat you first!
>>
>>52152553
You've already lost.
>>52152484
>>
>>52152566
see >>52152531
>>
>>52152571
See
>>52152553
>>
>>52152581
see >>52152548
>>
File: jn.png (29 KB, 1033x958) Image search: [Google]
jn.png
29 KB, 1033x958
What memes are you working on, /dpt/?
>>
File: 1434476164801.jpg (53 KB, 597x519) Image search: [Google]
1434476164801.jpg
53 KB, 597x519
>opengl
>second shader program compiles fine
>get uniform locations != -1
>set uniform variables, after glUseProgram of course
>glUseProgram -> glDrawArrays -> nothing
h-help
>>
About to buy this book, tell me why I shouldn't.
>>
>>52152598
>>>/v/
>>
>>52152630
you should
>>
>>52152630
because it's free online
>>
>>52152630
2nd edition is much cheaper
also, you need a strong math base before you can understand the math in it
>>
File: uh.jpg (49 KB, 1280x720) Image search: [Google]
uh.jpg
49 KB, 1280x720
>>52152598
>tfw I can only make the triangle and star meme
>>
>>52152630
because Algorithm Design Manual is both more concise and more comprehensive.
>>
>>52152520
Is it just the forwardslash/backslash in directories you need to change for linux?
import urllib,sys,requests,os,platform

board,thread=sys.argv[1:]

url="https://a.4cdn.org/"+board+"/thread/"+thread+".json"
slash=("\\","//")[platform.system()=="Linux"]

posts=requests.get(url).json()["posts"]
title=posts[0]["semantic_url"]

newDir=os.getcwd()+slash+board+slash+title+" ("+thread+")"

if not os.path.exists(newDir):
os.makedirs(newDir)

for keys in posts:
if "tim" in keys:
urllib.urlretrieve("https://i.4cdn.org/"+board+"/"+str(keys["tim"])
+keys["ext"],newDir+slash+str(keys["tim"])+keys["ext"])


>>52152538
I call what I'm used to m8, it's just a quick meme program. If I do any bigger or serious projects, I'm not going to import a ton of stuff
>>
I've got a question. I've gone through all the basic tutorials here: https://pythonprogramming.net/dashboard/?completed=/python-exec-tutorial/

what do i do now? should i just do the pygame tutorials
>>
>>52152656
>>> import platform
>>> platform.system()
'Windows'
>>> import os
>>> os.path.sep
'\\'
>>>
>>
File: mirror-of-erised1.jpg (170 KB, 500x376) Image search: [Google]
mirror-of-erised1.jpg
170 KB, 500x376
This is some legwork I need done for a scripting project.

I've got a set of Jumper servers that use my private key to jump onto though a Putty script.

I'm looking to launch putty from the command like and read a shell script though a file.

I have two problems.

1). The second jumper server rejects the key i'm using and it looks like the .ssh script it's calling is running commented out.
When I make a ssh connection manually the commands in the file do not appear commented out.

2). the script terminates the session once it's done. I think I can make it stay alive by throwing into bash, but I'm unsure how.

Please enjoy a windows default pic, as it is all I have to adorn this with.
>>
>>52152656
>>52152695
you should use os.path.join() instead

https://docs.python.org/2/library/os.html

os.sep

The character used by the operating system to separate pathname components. This is '/' for POSIX and '\\' for Windows. Note that knowing this is not sufficient to be able to parse or concatenate pathnames — use os.path.split() and os.path.join() — but it is occasionally useful. Also available via os.path.
>>
>>52152695
I am way too new to this m8, cheers
>>
Anyone know how to get C++ autocomplete working on atom? Im using Autocomplete-clang but its not working.
>>
>>52152656
use `os.path.join`
os.path.join(os.getcwd(), board, title+" ("+thread+")")
>>
Doing Project Euler problems in D. What's the easiest way to find prime numbers? Erasthosenes sieve?
>>
/g/ made reddit again

Wahey.

https://www.reddit.com/r/ProgrammerHumor/comments/3yukgl/anon_writes_java_xpost_r4chan/
>>
>>52152744
I don't know what it's called, but I use this.
int is_prime(unsigned num)
{
num = abs(num);
unsigned sq = sqrt(num);

if (num < 2)
return 0;
unsigned i;
for (i = 2; i <= sq; i++)
{
if (num % i == 0 && i != num)
return 0;
}
return 1;
}


If a number is greater than 1 and it's not divisible by any number from 2 to the square root of that number, it's prime.
>>
>>52152587
See
>>52152553
>>
>>52152788
Both those posts you linked to are mine.
I don't know what you're trying to do, but I suggest you stop.
>>
>>52152775
I came here from /r/ProgrammerHumor.

On the internet nobody knows you're a Bernie-voting redditor.
>>
File: acmel.webm (637 KB, 1920x1080) Image search: [Google]
acmel.webm
637 KB, 1920x1080
added some basic paren highlighting to acme
>>
>>52152799
See
>>52152566
>>
>>52152531
do I read
http://bato.to/comic/_/comics/himegoto-tsukudani-norio-r2619
or
http://bato.to/comic/_/comics/himegoto-tsukudani-norio-comic-rex-r11022
>>
>>52152821
I don't know how anyone can use that autistic shitheap of an editor.
Is there even any way to change the font?
The lack of syntax highlighting must be awful.
>>
>>52152817
>reddit
I told you guys to go light on the memes
>>
>>52152563
>still
C# is an excellent language
Many of us have only just realised F# deprecates it

Still, Unity >>>/vg/agdg
>>
>>52152744
if you want to find all prime numbers less than n, use a sieve. if you're only finding a few primes, use the algo the other anon mentioned (or if you really need something fast use the miller-rabin primality test)

>>52152784
just to note, it'd be faster to increment i by 2 in the loop, only checking only odd numbers. it'd be even faster to increment i by 6 and only check i-1 and i+1 each loop (after checking i=2 and i=3 separately).
>>
>>52152833
>Is there even any way to change the font?
yeah you can change the font, it a little inconvenient tho because it only takes plan9 font formats
>The lack of syntax highlighting must be awful.
doesn't really bother me, in fact I now usually turn off most syntax highlighting when I use other editors.
It is a pretty autistic editor I admit, but I find it kind of comfy desu, and its crazy powerful if you know how ot use it
>>
>>52152832
Himegoto was published in 2 different magazines simultaneously.
The original is a 4koma, and the other one is a proper manga format.
Read both.
Or just download hachimitsu scan's definitive scanlations, they include all the tank artwork and the chapters are ordered correctly according to the author's intentions.
>>
>>52152855
I'm doing the problem where you have to find the 10,001st prime, so I don't know what number I'm looking for at the start.
>>
>>52152874
code tag that shit bro
>>
>>52152867
unsigned ct = 0;
unsigned i = 0;
while (ct != 10001)
{
if(is_prime(i))
ct++;
i++;
}

return i;
>>
>>52152867
the check-if-anything-divides-n algorithm should be adequate
>>
>>52152874
That's simpler than I thought. My starting approach was to just create an array of int.max - 1 numbers and then go from 0..int.max - 1 filtering each multiple from the array; but that also requires that you know the number HAS multiples in the first place, AKA non-prime, so I don't really gain anything from doing that.
>>
File: mems.jpg (311 KB, 1366x768) Image search: [Google]
mems.jpg
311 KB, 1366x768
disappointed in the quality of fit's roid general today, barely any girls, they're clearly not roiding enough

but damn, wish I knew I could program this before instead of just downloading one by one
>>
File: 1451518883750.jpg (109 KB, 1080x1080) Image search: [Google]
1451518883750.jpg
109 KB, 1080x1080
>>52152963
What should be my next meme project?

Or serious project
>>
>>52153009
Write a programming language and say it's the official /dpt/ language.
Keep posting about it in every thread.
Talk about higher kinded types, as well as dependent types and type linearity
>>
>>52152907
Finished the problem. Since >>52152889 already gave me the iterative answer I wanted to try a more "functional" approach, as follows:

import std.algorithm;
import std.math;
import std.range;
import std.stdio;

bool isPrime(ulong num)
{
num = abs(num);
auto sq = cast(typeof(num))sqrt(cast(real)num);

if (num < 2)
return false;
for (int i = 2; i <= sq; i++)
{
if (num % i == 0 && i != num)
return false;
}
return true;
}

int[10_001] primes;

void main()
{
iota(2, int.max - 1).filter!isPrime.takeExactly(primes.length).copy(primes[]);
writeln(primes[10_000]); //Prints 104743, which is the correct answer
}


This is probably slower than an iterative approach, but I think it looks fairly elegant. Note that none of this code allocate on the heap, either; The only allocation is the stack allocation of the static array to hold the results. Everything else is just calls to really small struct functions that should be inlined.
>>
>>52153080
>i think it looks fairly elegant
>auto sq = cast(typeof(num))sqrt(cast(real)num);

is this a joke?
why are you doing this?
also, what language is this?
>>
>>52153080
functional programming is a meme
that looks fucking awful
>>
>>52152484
Fuck off nigger.
>>
>>52153102
>is this a joke
I was talking about the code that actually strings everything together in the main function, not isPrime (though that's just a small modification of the C function from >>52152784). The

auto sq = cast(typeof(num))sqrt(cast(real)num);


Is just detritus left over from when I was trying to make something typecheck correctly. The code works fine if you write it as:

auto sq = sqrt(num);


And change the type of num to long instead of ulong.

>why are you doing this
for fun

>also, what language is this
D
>>
>>52153080
I will write an FP version of this
>>
>>52152688
If this is your first language you're learning, and you plan on using CS in your job, look up some data structures and basic algorithms (sorting, graph, string, etc.) and try to implement them. If it's your first programming language and you're doing it for fun then ignore all that and do something that's fun or useful. Find something that takes you 2 minutes to do that you do every day and make it 10 seconds (like a recent program I made that checks the site that homework is assigned to and automatically adds an event to my phone calendar so I can see when everything is due). Programming is supposed to be powerful and fun, so do something you like. If this isn't your first programming language why the fuck are you asking us?
>>
File: screen.png (90 KB, 1508x1050) Image search: [Google]
screen.png
90 KB, 1508x1050
I've been working on learning some Javascript. I miss type saftey but it seems to be a neat scripting language. I like it much better than LUA so far.

Anyway, I used my limited knowledge of web dev to make a cancer creator for my favorite hat simulator, http://ralphorama.github.io//tf2-chatterbox/
>>
>>52153131
If you don't like it here's an iterative version >>52152889
>>
Does ocaml work well with Windows or should I go with f#?
>>
File: feelsgood.png (75 KB, 659x609) Image search: [Google]
feelsgood.png
75 KB, 659x609
>>52152484
>mfw libwebp
seriously the webp api is really pleasant
>>
>>52153146
The isPrime function? I certainly didn't try to make that iterative, but it'd be easy enough to rewrite it as a tail-recursive function.
>>
>>52153255
I certainly didn't try to make that functional*
>>
File: attempt 1.png (11 KB, 402x255) Image search: [Google]
attempt 1.png
11 KB, 402x255
>>52153255
Should be the same algorithm.
>>
Alright lads, will attempt a 4chan thread search through regex program. Coupled with the image downloader, you should be able to download all images from your favourite boards just through the command line. Alternatively, there will be an option to open up any desired thread as well instead
>>
def isPrime(x):return len(i for i in range(2,int(x**0.5)+1) if x%i==0)==0

:^)
>>
File: fart.webm (211 KB, 374x232) Image search: [Google]
fart.webm
211 KB, 374x232
Ask your very beloved programming literate anything.

>>52153146
it's already a function but he should have used pure.

https://dlang.org/spec/function.html#pure-functions
>>
>>52153558
It wasn't very FP
>>52153345
>>
>>52153558
What's your favourite g meme program?
>>
File: black_shiba_inu.webm (717 KB, 640x640) Image search: [Google]
black_shiba_inu.webm
717 KB, 640x640
>>52153567
fizzbuzz of the Christ
>>
>>52153345
Nice, I tried to stay as close to you example as possible, looks like it works:

import std.algorithm;
import std.range;
import std.stdio;

auto factorize = (int x) => iota(1, x + 1).filter!(i => x % i == 0);

bool isPrime(int x)
{
if (x == 1)
return false;
else
return factorize(x).count == 2;
}

void main()
{
iota(0, 101).map!isPrime.each!((i, b) => writeln(i, " ", b));
}
>>
>>52153581
never heard of it, what does it look like?
>>
File: fizz.png (402 KB, 1024x768) Image search: [Google]
fizz.png
402 KB, 1024x768
>>52153589
>>
>>52153600
my god, it's beautiful
>>
File: 1388333729112.jpg (30 KB, 299x313) Image search: [Google]
1388333729112.jpg
30 KB, 299x313
>>52153600
>>
>>52153600
holy shit
>>
>>52153600
>8--i
Wut? Is this post-decrementing the value 8 or pre-decrementing i?
>>
>>52153600
Not sure if I'm typing the operators incorrectly, or python 3 adds new ones, but I couldn't get it to work. The following works for me on 2.7:
for i in range(1,101): print ("FizzBuzz"[(i%3!=0)*4:(i%5==0)*4+4] or i)


but jesus christ, it's a glorious concept
>>
>>52152644
>This book provides a comprehensive introduction to the modern study of com-
puter algorithms. It presents many algorithms and covers them in considerable
depth, yet makes their design and analysis accessible to all levels of readers.
>to all levels of readers
>>
>>52153586
Nice
Did some changes based on that, it's pretty meme tier

let factor x = (%) x >> (=) 0
let factorise x = [| 1 .. x |] |> Seq.filter (factor x)
let isPrime = factorise >> Seq.length >> (=) 2

[|0..100|]
|> Array.map isPrime
|> Array.iteri (printfn "%i : %b")
>>
>>52153682
oh never mind, I think I ran it with the parens next to print, it works now
>>
>>52153682
http://ideone.com/3GvtDX
>>
>>52153692
you still a decent understanding of math
>>
File: computerstate.jpg (77 KB, 1920x1080) Image search: [Google]
computerstate.jpg
77 KB, 1920x1080
>>52152644
>you need a strong math base before you can understand the math in it
it's still way more accessible than the art of computer programming.
>>
How complicated would it be to make an intepretated language
>>
>>52153697
The nice thing about D is that it's easy to make it parallel as well:

import std.algorithm;
import std.parallelism;
import std.range;
import std.stdio;

auto factorize = (int x) => iota(1, x + 1).filter!(i => x % i == 0);

bool isPrime(int x)
{
if (x == 1)
return false;
else
return factorize(x).count == 2;
}

bool[101] answers;

void main()
{
foreach (i, n; parallel(iota(0, 101)))
{
answers[i] = n.isPrime;
}
answers.each!((i, b) => writeln(i, " ", b));
}
>>
>>52153674
Think about precedence
First it does ** (the result is 1 modulo 5 if i%5 is not 0)
Then it applies the 2nd - (unary) (the result, because it's negative, is 4 modulo 5 if i%5 is not 0)
Then it actually applies the % operator
Lastly 8 minus the result is 8 if i%5 is 0, and 4 if i%5 isn't
>>
File: 1436550309041.png (491 KB, 724x674) Image search: [Google]
1436550309041.png
491 KB, 724x674
>>52153760
a dozen lines of code

(define (eval exp env)
(cond ((self-evaluating? exp)
exp)
((variable? exp)
(lookup-variable-value exp env))
((quoted? exp)
(text-of-quotation exp))
((assignment? exp)
(eval-assignment exp env))
((definition? exp)
(eval-definition exp env))
((if? exp)
(eval-if exp env))
((lambda? exp)
(make-procedure
(lambda-parameters exp)
(lambda-body exp)
env))
((begin? exp)
(eval-sequence
(begin-actions exp)
env))
((cond? exp)
(eval (cond->if exp) env))
((application? exp)
(apply (eval (operator exp) env)
(list-of-values
(operands exp)
env)))
(else
(error "Unknown expression
type: EVAL" exp))))


read sicp chapter 4 and prepare for a severe mind blow.
>>
>>52153761
why are you not using pure ?
>>
>>52153778
I could if I wanted to, but who cares for a little toy example?
>>
>>52152520
m..m..make it download all of the images from all of the threads on a specified board
>>
>>52153786
>>52153778
In fact, factorize will be inferred by the compiler as pure because it has a return type of `auto`.
>>
>>52153786
because it would actually make the example more relevant about doing fp with D.
>>
>>52153793
The code is obviously pure whether I annotate the function as such or not. Besides, `pure` in D means something a little different from `pure` in FP languages. It doesn't mean "nothing in this function will be mutated", it means "the effects of any mutation within this function can only escape through its parameters".
>>
>>52153791
there is no json file for all threads combined, I would have to request it from every thread, and there's a limit of 1 json call per 10 seconds

I could modify it so that it collates every existing thread, adds it onto a stack, and every 10 seconds, downloads all images from the top of the stack(so it starts from the last thread), but I've got to get ready and go

Which board you looking to do?
>>
File: PrimeCircle.gif (13 KB, 455x436) Image search: [Google]
PrimeCircle.gif
13 KB, 455x436
Why isn't there a pattern with primes, /dpt/?

You'd think meme magic would find a way.
>>
>>52152730
> C++
> editor run in a web browser
Do yourself a favor and use YCM with Vim or Emacs+Evil+<preferred auto complete package>.

The support is much more mature and you'll thank me later.
>>
>>52153815
/wg/
>>
>>52153828
That's an interesting pattern. I haven't seen this sequence presented in this way.
>>
>>52153761
In my impl.
change Array.map to
Array.Parallel.map
;)
>>
>>52153851
goddamn dude, that's a lot of stuff to download

alright, but it won't be for a good number of hours, got a new years party, you could try implementing it yourself if you wanted to
>>
>>52153854
>interesting
It just showcases how primes aren't divisble by 2 or 3
>>
File: spiral.png (36 KB, 411x567) Image search: [Google]
spiral.png
36 KB, 411x567
>>52153828
>>52153854
>>
>>52153856
damn, pretty good. Actually mine doesn't quite work because it locks on the result of iota(0, 101), not on answers. The correct solution is:

bool[101] answers;

void main()
{
foreach (i, ref b; parallel(answers[]))
{
b = i.isPrime;
}
answers.each!((i, b) => writeln(i, " ", b));
}
>>
>>52153880
I wish someone combined the good bits of D with all of F#
>>
>>52153873
2 is divisible by 2 and 3 is divisible by 3.
>>
>>52153889
I'd probably take more of F# than I would of D. It'd probably mainly benefit from D's compile-time introspection and function execution abilities.
>>
>>52153894
yeah, I guess I didn't mention it, but I meant the rest and it's why those are the only 2 outside of those lines
>>
>>52153905
>mixin (both the string->code and the template mixins)
>alias
>universal templates
>constraints
>>
i finished my first api and my first python script, it searches a user specified board for OPs with either a comment or subject containing the search term, it also can handle searching other cases and searching for padding with spaces, im pretty pleased with it as i had never used JSON or and api or python before, next is autodownloading images from threads
>>
>>52153875
Do you think if you want on for infinity you would eventually start to see a pattern?
>>
>>52153927
>want
went*

smdh
>>
>>52153924
>tfw I was about to do the searching, and I've already done the image downloading
If it's not just for personal learning, I could post my updated code, I will modify it to download from every thread:
from urllib import urlretrieve
import requests,os

def imgdl(board,thread):
url="https://a.4cdn.org/"+board+"/thread/"+thread+".json"

posts=requests.get(url).json()["posts"]
title=posts[0]["semantic_url"]

newDir=os.path.join(os.getcwd(),board,title+" ("+thread+")")

if not os.path.exists(newDir):
os.makedirs(newDir)

for keys in posts:
if "tim" in keys:
newFile=str(keys["tim"])+keys["ext"]
urlretrieve("https://i.4cdn.org/"+board+"/"+newFile,
os.path.join(newDir,newFile))


It's in a function for modularity (which all programs should be), since I'll be combining it with thread search
>>
>>52153923
Honestly D's constraints kind of suck. They're much more powerful than C++ concepts or Rust traits (not sure about Nim), but if one term in the constraint expression fails, the compiler doesn't tell you which one it is, so you're stuck having to pull them all out and test each separately.
>>
>>52153956
That's a compiler limitation
>>
>>52153954
neat
it was just for personal learning, i can post my code if you want
>>
>>52153987
Yes it is, but nobody working on D seems to want to put in the work to fix it. It's been like that ever since D got the feature.
>>
>>52153993
Yeah, it could be helpful for others too. I'll take a look later. Have fun m8
>>
File: ddd.jpg (23 KB, 400x400) Image search: [Google]
ddd.jpg
23 KB, 400x400
Write a script that downloads every single image on a board (for example, /b/), but it automatically deletes all the images that make it to the archive so you're only left with the images the mods have deleted.
>>
>>52154016
>how to get speedv&
>>
>>52153184
thanks for the guidance. much appreciated. im doing this for fun, but wouldnt mind having a job doing this so I'll do a little of both.
>>
File: ggfd.png (24 KB, 256x256) Image search: [Google]
ggfd.png
24 KB, 256x256
>>52154016
/b/ doesn't have an archive, baka.

There will be a better way of doing this.
>>
File: zheleznogorsk-svg.png (55 KB, 770x513) Image search: [Google]
zheleznogorsk-svg.png
55 KB, 770x513
>>52154005
import urllib2
import ujson
import string

board = str(raw_input("Please enter a board: "))
sTerm = str(raw_input("Please enter a searchterm (no spaces): " ))
sTerm1 = sTerm.center(len(sTerm)+2) #pad with spaces either side
sTerm2 = sTerm+' '
sTerm3 = ' '+sTerm

acceptedStrings = [sTerm, sTerm.upper(), sTerm.lower(), sTerm.title(),
sTerm1, sTerm1.upper(), sTerm1.lower(), sTerm1.title(),
sTerm2, sTerm2.upper(), sTerm2.lower(), sTerm2.title(),
sTerm3, sTerm3.upper(), sTerm3.lower(), sTerm3.title()]

response = urllib2.urlopen('http://a.4cdn.org/'+board+'/catalog.json')

catalogJSON = response.read()
parsedJSON = ujson.loads(catalogJSON)
#parsedJSON[pagenumber]['threads'][thread number (on page)(~15 per page it seems)]['no']

i=j=a=0 #index for pagenum,threadnum,results


for i in range(0,11):#search all pages
for j in range(0,20):#search all threads
try:#search subject for search term
if any(x in parsedJSON[i]['threads'][j]['sub'] for x in acceptedStrings):
a+=1
print("http://boards.4chan.org/"+board+"/thread/"+str(parsedJSON[i]['threads'][j]['no'])+" "+parsedJSON[i]['threads'][j]['sub'])
# try: #print comment
# print parsedJSON[i]['threads'][j]['com']
# except:
# print("<comment blank>")
except:# if subject is empty
try:#search comment for search term
if any(x in parsedJSON[i]['threads'][j]['com'] for x in acceptedStrings):
a+=1
print("http://boards.4chan.org/"+board+"/thread/"+str(parsedJSON[i]['threads'][j]['no'])+" <Subject Bank>")
# print parsedJSON[i]['threads'][j]['com'] #print comment
except:#if subject and comment are empty
continue
print str(a)+' results for "'+sTerm+'" on '+board.center(len(board)+2,'/')


the commented out bit will print the OP comment along with the subject but it also spits out the raw html <quote>foo </quote> shit for stuff like greentext and i cba to filter that out. No promises its the most elegant solution but i feel its readable
>>
>>52154049
constantly scan the boards for deleted posts until the whole thread expires
>>
>>52154076
hmm, 4chan renders comments differently to my text editor :/
>>
>>52154086
beat me too it, you would still have to cache the images tho
>>
>>52154086
What would be a reasonable amount of requests? 1 a second? I don't want want 4chan to be mad at me.
>>
>>52154142
the api says no more than 1 a second and thread refreshes once every ten seconds or more
>>
>>52154142
1 request/sec times the number of active threads times the number of posts in every thread
>>
>>52152705
I can't even understand what you're trying to say. .ssh script? Putty script? Are you trying to automate putty logins across two servers?

Pretty sure you can invoke putty in a .bat file (or there's a command line flag) that will prevent closing out the connection when finished.

2/10 wouldn't read again.
>>
>>52154156
If I don't use the API am I allowed to do more?
>>
>>52154086
If you monitor the catalog, you can tell when a new image has been added and when an image has been deleted, so that would probably be a good way to cut down on requests.
>>
>>52154212
>cut down on requests
i'm pretty sure 4chan rate throttles you automatically, but that doesn't stop me from checking for new posts every second on every open tab.
(i have 30 open threads)
>>
>>52154190
its just a read only JSON file that you pull from a url, its nothing fancy
https://github.com/4chan/4chan-API
looks as though moot wrote it and given hiroshimas technical ability i doubt he would even know
>>
>>52153772
Oh, I don't know Python so I thought it was the unary -- operator. Does Python not have that?
>>
>>52154229
CTRL +
TAB + R
TAB + R
TAB + R
>>
>>52154242
m8 those unary operators are a meme
>>
>>52154242
you have to do shitt +=, -= nonsense
>>
>>52154212
What if an image gets deleted and an image gets added during the request cool down?

It will look like nothing has changed.
>>
>>52154261
folds and associativity
3 - 6 + 2
vs
(+3) + (-6) + (+2)
>>
>>52154288
cross-reference post numbers
If a specific post number suddenly disappears and it had a picture attached, that's how you know it was deleted and worth saving.
If you make these checks fast enough, you will be able to differentiate between a thread being deleted by mods and a thread being pruned naturally.
If an OP gets deleted and it was recently on page 10, delete all the pics attached to that thread.
If an OP gets deleted while it's not on page 10, save all the pics in that thread.
>>
What does HEAD and OPTIONS do in regards to getting requests from 4chan's json api? I'm quite new to json stuff and away from the comp
>>
>>52154349
it's specific to 4chan's api, not to json
json is a very generic format
>>
File: reqs.png (414 KB, 403x587) Image search: [Google]
reqs.png
414 KB, 403x587
Finally, posting works again.
>>
File: l.jpg (357 KB, 1920x1080) Image search: [Google]
l.jpg
357 KB, 1920x1080
>>52153865
so i have this so far, it's slow, might look into adding threads

http://pastebin.com/PZU32409
>>
I'm trying to make reproduce Conway's Game of Life in c. The cells are stored in a 2d array, i have to check in 8 directions, but on the edges that would be outside of the array. Is there a way to implement this non autistically, or I have to check for very edge case?

For example in python i could use:
try:
# check 8 directions
except IndexError:
# deal with edge case


pls help
>>
>>52150541
>https://ocaml.org/learn/tutorials/ocaml_and_the_web.html
ocaml web development and mobile development support seems experimental or non existent. F# wins again for actually letting you shit done.
>>
File: mems.jpg (234 KB, 1366x768) Image search: [Google]
mems.jpg
234 KB, 1366x768
>>52154470
I will post my code in a bit, but yeah me too, felt like programming instead of partying
>>
Fixed go bindings with C for onset detection. What does /dpt/ think? http://neetco.de/0xBA5/kami
>>
>>52154571
programming > partying
>>
>>52154521
if(out_of_bounds(x) || empty(x))
#there is neighbor to this slot here
>>
>>52154609
Meant to write that there is no neighbor but it's too late since I already posted it despite there being error that I did not want to post, doushio~
>>
>>52151308
>Black women are fine.
https://www.youtube.com/watch?v=aZzcw5dpb2s
enjoy your moldy, maggoty pooinloo hair i guess
>>
>>52154571
It's messy lads, and I haven't yet switched from urllib.urlretrieve to whatever it is requests has, but here it is. I pretty much run the functions from the command line, and I've changed the threadDl function so that the board must be enclosed in quotes, but the threadNumber can be left without. Next is a board-thread regex searcher

from time import sleep
import urllib,requests,os

clear=lambda: os.system('cls')

def threadDl(board,thread):
thread=str(thread)
url="https://a.4cdn.org/"+board+"/thread/"+thread+".json"

urlInfo=requests.get(url)
if urlInfo.status_code!=requests.codes.ok:
print "Thread not found."
return

posts=urlInfo.json()["posts"]
title=posts[0]["semantic_url"]

newDir=os.path.join(os.getcwd(),board,title+" ("+thread+")")

total=sum(1 for keys in posts if "tim" in keys)
count=0

if total==0:
print "0 images found."

if not os.path.exists(newDir):
os.makedirs(newDir)

for keys in posts:
if "tim" in keys:
newFile=str(keys["tim"])+keys["ext"]
try:
urllib.urlretrieve("https://i.4cdn.org/"+board+"/"+newFile,
os.path.join(newDir,newFile))
except urllib.error.ContentTooShortError:
print "Thread download interrupted."
return

count+=1
print "{} of {} images done - {}".format(count,total,newFile)

contd. (all 1 file)
>>
File: mems.jpg (161 KB, 975x509) Image search: [Google]
mems.jpg
161 KB, 975x509
>>52154739
def boardDl(board):
url="https://a.4cdn.org/"+board+"/catalog.json"

pages=list(i for i in requests.get(url).json())
sleep(1)

threads=[]
titles=[]

for page in pages:
threads.extend(list([thread["no"],thread["semantic_url"]]
for thread in page["threads"]))

total=len(threads)
count=0

while threads:
currThread=threads.pop()
print "{} of {} threads done - {}".format(count,total,currThread[1])

threadDl(board,currThread[0])
print "\n"

count+=1
sleep(1)

print str(total)+" threads completed."


Oops. I'm getting pic related. I guess the code isn't fully ready yet
>>
>>52154541
You apparently didn't read the link you even quoted. Well done, faggotsharp.
>>
>>52154783
i did tho. theres one web framework. hardly used by anyone.
>>
>>52152644
You need only high school level math
>>
Is there a reason why Prolog is much faster than most conventional languages?
Any kind of AI that needs to exhaustively search for solutions is going to be fast as fuck no matter how shit your algorithm implementations are

In addition, recursion doesn't eventually cause stack overflow like it would everywhere else
>>
>>52154849
Ocamlnetlib is a decade old and its latest update was in june this year. That's the complete opposite of experimental or nonexistent. Ocsigen is also very old and couldn't be more complete. It even offers many features not available in other full-stack frameworks, such as the ability to readily persist elements without reloading across the site. Then there's the usual lightweight http client-server libraries.
As expected, faggotsharps are no sharper than polished turds.
>>
>>52154880
The reason is that you have gone through lobotomy given that prolog is one of the slowest languages out there and that precisely 0 people use prolog for anything, let alone AI which actually requires high performance.
>>
>>52154880
The first benchmark I found says that prolog isn't really fast. Do you have benchmarks proving the contrary?
http://wiki.visual-prolog.com/index.php?title=Execution_Speed_(compare_to_C%2B%2B)
>>
>>52154853

There is a surprisingly large number of people who suck at high school level math.

>>52154880

>Is there a reason why Prolog is much faster than most conventional languages?
Compiler optimizations.

>In addition, recursion doesn't eventually cause stack overflow like it would everywhere else
Hate to break it to you, but tail call removal is a fairly normal thing. Every functional language not running on the JVM can do it (sorry Scala, Clojure), C and C++ can do it (or more specifically, the standard does not require pushing a stack frame, and every compiler worth using supports it), and even Ruby can do it... if you compile it from source with a few optimization flags (you can also get it to support goto if you build it from source). The only thing you can't optimize with recursion is recursive backtracking.
>>
>>52154940
>Compiler optimizations.
Ah, that makes sense

thank you
>>
>>52154758
pastebin all of the code please
>>
>>52154905
fair enough. Not experimental, just really old, unsupported and unused.

suave.io is a niche lightweight http server for F#, and has like 10x more stars on github than that stuff: https://github.com/SuaveIO/suave and that by no means that main web stack you would use for F#.
>>
>>52154940
Scala does have tail call optimization.
>>
>>52154980
http://pastebin.com/P417dbug
Changed what it prints a bit, set the pastebin to expire after 1 hour forgot why
>>
In a grid represented by a 2D array, what's the best way to get all neighbours of a field (i.e. the fields north, east, south and west of it)? Should you hardcode that shit in and comment it?
>>
Just did https://github.com/darkfeline/ytplay

Now I know why Golang is so great. Channels and goroutines.

What's the most magical thing about shell scripting? Pipes, man. What Golang does is give you pipes, except they work with native objects, not just text streams, and lightweight threads, and a proper, low-ish level programming language. It's beautiful.

The built-in tools like gofmt, go get make it easy to use as a scripting language. It's not going to replace C like its creators wanted, but it's great for some tasks you would use Python or Ruby for.
>>
>>52154986

Really? Because last I checked, the JVM was incapable of supporting tail call optimization on any language targeting it.

>>52154951

Never underestimate the power of compilers, especially in languages with strong typing, or which allow the compiler to make assumptions in certain areas. That said, I'm not entirely sure if Prolog is actually fast compared to, say, C++ or Fortran.
>>
File: mems.jpg (200 KB, 977x511) Image search: [Google]
mems.jpg
200 KB, 977x511
>>52155004
>>52154571
The misalignment looks uglier than I thought

You can comment out oldFile in threadDl() and change the following part, if you want:
print "{} of {} images done - {} to {}".format(count,total,oldFile,newFile)

to
print "{} of {} images done - {}".format(count,total,newFile)
>>
>>52155035
You're right, the JVM doesn't support tail call optimization, but the scala compiler does.
>>
>>52155020
list( (x+i,y+j) for i in (-1,1) for j in (-1,1) )
>>
>>52154983
>just really old, unsupported and unused.
>last update a few months ago
>very active development as seen in the source repository
>widely used by all
You're not even trying anymore, faggotsharp.
>>
>>52155035
Prolog is slow as fuck even compared to non-compiled languages.
>>
>>52155084
Smart, thanks man.
>>
File: mems.jpg (368 KB, 1366x768) Image search: [Google]
mems.jpg
368 KB, 1366x768
>>52155051
Actually, better not to use the old code as it can't read certain characters anyway

New one:
http://pastebin.com/uMZte2bt
>>
>>52155105
that depends on the specific implementation
>>
>>52155108
No problem m8, you can add your array bounds too:
list( (x+i,y+j) for i in (-1,1) for j in (-1,1) if (0<=x+i<100 and 0<=y+j<100) )
>>
>>52155032
Another fellow gopher.
Did you know mpv already has built-in youtube-dl support?
>>
>>52155097
>widely used by all
Seems like it's hardly used at all. Hardly anyone following the github account. And again, it's the one and only web framework for ocaml. Pathetic.
>>
What the fuck is the point of lambdas in Java?
>>
>>52155032
>Pipes
is that was
c chan<- string
is?
>>
>tfw don't know how to pipe in python
It's making cryptography from http://cryptopals.com/ a little inconvenient
>>
>>52153600
christ almighty
>>
>>52153600
I gotta memorise this one for job interviews. Fuck me....
>>
>>52153600
i thought fizzbuzz was 1 2 fizz 4 buzz ... fizzbuzz
how does that script separate fizz and buzz? or does it?

so much going on i may have missed it
>>
>>52155396
python array slicing notation is

array[start:end:step]


from here

"fizzbuzz[0:4]
returns "fizz"

"fizzbuzz[4:8]
returns "buzz"
>>
>tfw c++unts will never write fizzbuzz of the christ as nicely as python users can
>>
>>52155430
oh shit i see i see, didnt know strings were just lists/arrays of chars in python, or at least that they were manipulated as such
>>
>>52155133
I'm using youtube-dl to buffer asynchronously

mpv only
>play song
>song ends
>mpv gets next url
>mpv buffers
>play song


with youtube-dl
>play song
>youtube-dl gets next url
>youtube-dl buffers
>song ends
>play song

which is why I said golang is awesome. You can't do this kind of thing very well with shell or Python.

>>52155173
Yes. You can send discrete string objects instead of just a stream of bytes. You can also send (pipe) complex structs, and all of this can work asynchronously in goroutines.
>>
>>52155502
m8 strings are always just a chain of chars
>>
File: mems.jpg (61 KB, 682x230) Image search: [Google]
mems.jpg
61 KB, 682x230
import requests,re

def threadSearch(board,regex):
url="https://a.4cdn.org/"+board+"/catalog.json"

pages=list(i for i in requests.get(url).json())

subjects=[]

for page in pages:
subjects.extend(list([thread["semantic_url"],thread["no"]]
for thread in page["threads"]))

for subject in subjects:
if re.match(eval("r\".*"+regex+".*\""),subject[0]):
print str(subject[1])+": "+subject[0]


Code to search for a thread in any board using a regex expression. You will still need to use r when calling the function if you want to use \
threadSearch("g",r"\\?programming")
>>
>tfw moved from 3GHz Core 2 Duo with 3GB of RAM to a 4GHz i7 6700k with 64GB of RAM and motherboard which actually can do SATA 3 for my SSD

Programming is so much nicer when you don't have to wait around forever for shit in VMs &c, especially for work
>>
>>52155589
>64 gb ram
>i7
You got too much money on your hands, friend?
>>
>>52155595
I have a job and don't have to support anyone else but myself so yeah. I also got 980 ti, another SSD, water cooling and all that but didn't seem relevant to mention. I might buy a 4k monitor but I don't know how I feel about programming on one.
>>
>>52155568
ye but not every lang allows you to reference them like an array
>>
>>52155622
>consumerism
Better use that money properly like holidays or investing instead of buying tech gadgets.
>>
>>52155149
>being this desperate
>denying reality this hard
>pretending facts that were stated don't exist
You faggotsharps really are loyal, I'll give you that.
>>
>>52155655
>buy recent fast hardware so I don't have to sit around for 20 minutes between rebuilds
>consumerism

o-ok
>>
>>52155685
Anon would've bought a proper workstation instead of an unlocked CPU and meme watercooling.
>>
>>52155683
>>denying reality this hard
I'm not, I'm just saying how unpopular that web framework is, and that it's the only option.

Saying it's used widely by all ocaml developers is not saying much.

>pretending facts that were stated don't exist
such as?
>>
>>52155715
what's a proper workstation then?
>>
>>52155735
Any modern dual socket Xeon machine will do. 8 logical cores are a joke.
>>
>>52155575
You can now open a matched link
import requests,re,webbrowser,sys

def threadSearch(board,regex):
url="https://a.4cdn.org/"+board+"/catalog.json"

pages=list(i for i in requests.get(url).json())

subjects=[]

for page in pages:
subjects.extend(list([thread["semantic_url"],thread["no"]]
for thread in page["threads"]))

count=0
matched=[]
for subject in subjects:
if re.match(eval("r\".*"+regex+".*\""),subject[0]):
count+=1
matched.append(subject[1])
print str(count)+": "+str(subject[1])+": "+subject[0]

if len(matched)==0:
sys.exit()

while 1:
openPage=raw_input("Enter page to open. -1 to exit: ")
if openPage=="-1": break

webbrowser.open("https://boards.4chan.org/"+board+
"/thread/"+str(matched[int(openPage)-1]))
threadSearch("fit","roids")
>>
>>52155752
>8 logical cores are a joke.
But hyperthreading does work, what are you going on about?
>>
>>52155808
I never said it didn't work. 8 cores really isn't much. 32 logical cores sounds more like it.
>>
>>52155766
What should be my next meme project lads?
>>
>>52155924
Make it watch for those keywords.
>>
>>52155924
make a chrome extension that filters all anime images
>>
>>52155938
que?

>>52155947
serious meme projects
>>
>>52155924
a programming language implementations benchmark.
>>
>>52155956
Make it so the script checks every x seconds instead of running once.
>>
>>52155956
make a script that finds the most commonly used words across all boards (filtering out common words like "the")

call it the meme tracker
>>
>>52155969
>every x seconds
It's an easy implementation, but you're basically watching for a new thread to appear with that relevant topic, which happens once every few hours unless you browse int/brit

>>52155962
come on lad
>>
>>52155956
write something useful in haskel
>>
>>52155988
It's feasible for checking text in the catalog, but for every thread, that's a lot of json calls, and at 1 max per second, it'll take a long while to finish, the memes would have gotten too stale at that point

>>52156002
close to impossible m8
>>
>>52153600
What does ** do
>>
>>52156040
x**y -> x to the power of y
>>
>>52156040
power
>>
>>52155989
Make it keep watching for new threads. Once a thread has been found, notify the user once by a notification, panic or w/e and keep looking for new threads. Let's say I want to watch for 'loli' threads on /b/ and report them to the FBI. I want to be notified for all current threads and newly created threads.
>>
I need to design a function that recognises upper case letters and turns them into lowercase, and lowercase letters into upper in python.

I understand .upper and .lower but can't think of a way that I can do this. Any ideas?
>>
>have bug
>add debugging
>bug goes away

oh boy it's going to be one of those
>>
>>52156166
That's literally how debugging sprays work though.
>>
>>52156193
pls…
>>
>>52156202
What? Never learned about how farms work? Git gud, kid.
>>
>>52156118
import string

a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
c = string.maketrans(a, b)

print "The QuIck brown FOX! 123456789".translate(c)
>>
>>52156118
Any reason why you have to devise a function?

"String".swapcase() does it for you.
>>
I got told to use 4KiB buffer for reading because it fits the CPU L1 cache most of the time.
But using a 1MiB buffer is about 1000% faster.

So should I stick to 4KiB or use something higher?
>>
>>52156118
def switchCase(string):
newWord=[]
for i in string:
if i.isupper(): newWord.append(i.lower())
elif i.islower(): newWord.append(i.upper())
else: newWord.append(i)
return "".join(newWord)
>>
>>52156118
could have something as simple as

map(lambda x: if x.islower() then x.upper() else x.lower(), your_string)


>>52156241
only works for that specific character set
>>
File: 1443400176559.jpg (8 KB, 234x250) Image search: [Google]
1443400176559.jpg
8 KB, 234x250
>>52153600
how
>>
>>52156305
>I've been told X but Y is faster
Tough question senpai.
>>
>>52156305
Hard data beats chair philosopher muh low level cache hits shit. Optimising compilers exists for a reason so if they way you do it ends up faster, stick to it.
>>
>>52153674
there no such thing as ++ or -- operators in python.
>>
>>52156341
through the glory of our lord and savior
>>
Ayyy, got my run time from 5.1s to 2.9s by using -Ofast and -march=native. Are there any more optimization flags?
>>
>>52156241
>.maketrans
SJWs pls go
>>
>>52155924
make a rar archive password cracker
>>
>>52156990
what information are you trying to steal now anon?
>>
File: 200_s[1].gif (52 KB, 357x200) Image search: [Google]
200_s[1].gif
52 KB, 357x200
>>52157045
stuff
>>
>>52156487
ofast doesn't enable those

-fgcse-sm
-fgcse-las

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
>>
>>52156487
-lto -O3 -fwhole-program -fuse-linker-plugin -ffat-lto-objects -floop-interchange -floop-strip-mine -floop-block -floop-nest-optimize -floop-parallelize-all -floop-parallelize-loops=4
And make sure to use a custom gcc that uses graphite, openmp, cloop and ppl. Then make sure to use -lgomp in LDFLAGS
>>
>>52156323
def switchCase(string):
newWord = ""
for char in string:
if char.isupper(): newWord += i.lower()
elif char.islower(): newWord += i.upper()
else: newWord += char
return newWord

FTFY
>>
>>52157119
oh shit, I forgot immutable only applied to string assignment, I got a lot of code to change now
>>
>>52157149
>>52156323
>>52157119
Oops I fucked up anyway

def switchCase(string):
newWord = ""
for char in string:
if char.isupper(): newWord += char.lower()
elif char.islower(): newWord += char.upper()
else: newWord += char
return newWord
>>
Hey /g/, I'm working on browser game that has lobbies players can join and stuff, I'm doing it in PHP (using Laravel), as well as jQuery and node.js.

I'm creating the lobbies with Laravel, storing each one on a database, for logging and settings purposes, but the actual playable lobby that players join is instantiated via node.js, however, I need to have my Laravel controller call a a javascript function, and I can't for the life of me figure out what to do. Been stuck here for half a day, and google isn't helping either.

What's my best shot? Can anyone point me in the right direction?

also
>inb4 >php
>inb4 >node.js
>inb4 >javascript
I hate webdev as much as the next guy, but it has to be done
>>
>>52153600
Do we have any other programs of the Christ, as glorious as this?
>>
>>52157207
>I need to have my Laravel controller call a a javascript function, and I can't for the life of me figure out what to do
I should proof-read more often. What I meant is that I have no idea how to call the javascript code from within the Laravel/PHP controller.

Would be very thankful if anyone could give me a hint or two on what would be a good idea.
>>
File: Screenshot_2015-12-31-16-54-37.png (109 KB, 720x1280) Image search: [Google]
Screenshot_2015-12-31-16-54-37.png
109 KB, 720x1280
I was bored so i made python run on android
nearly bricked it
>>
>>52157286
>tfw we can now show off fizzbuzz of the christ on the go
This is an exciting time for programming
>>
>>52157247
>Laravel
Why PHP? Why not do it all in one language? Cross calling between PHP and node sounds sounds like white hot development hell.
>>
>>52157080
Seems slightly faster. Maybe a ms or 2.
>>52157090
-floop-parallelize-loops=4 -floop-nest-optimize
are unrecognized. I also use gcc from the arch repo. CBA to compile it from source. It also takes a poo poo while compiling, so I'll stick with the previous reply.
>>
>>52157315
It's for a college project. The teachers prefer that everyone uses the same platforms so that it is easier to teach and shit.

Like I said, it's not like I like webdev, I actually fucking hate it, but it has to be done
Thread replies: 255
Thread images: 44

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.