[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


File: 1419379128418.jpg (30.13 KB, 400x357, 400:357, shit-eating-grin.jpg)

31dd89 No.899

Small questions that don't need a separate thread.




The code:

gifts = ['bike', 'cancer', 'rattler', 'toaster']
for n in gifts:
if n != 'cancer':
print " You are getting a " + n + " for christmas!"
elif n == 'cancer':
"You're getting cancer!"
else:
print "fgfgsdf"


The output:

You are getting a bike for christmas!
You are getting a rattler for christmas!
You are getting a toaster for christmas!


Why don't I have cancer?

50f065 No.900

Santa ain't gonna give you any cancer if you don't tell him to print it out.

Also there's no reason to have that else clause, you could just have "You're getting cancer!" as your else clause.

31dd89 No.901

>>900
Thank you.
*Self facepalm*

da059a No.911

If you wanna get fancy, check the first letter of the string to see if it's a vowel, and use 'a' and 'an' accordingly.

08e600 No.912

>>911
>an unicorn

bb41db No.923

>>899
Hey /prog/ here's the deal, I'm looking for a language recommendation. I've obtained a decent grasp of python (basic data entry programs, basic board game AI, text based games). And I am looking to continue my self improvement and take up another language.

To establish a motive for myself, I've taken on the goal of creating a program to simplify the playing of a card based RPG from a few years ago that went under. I don't think it will be too difficult to program the game system, but I've never worked with creating any sort of UI outside of using CSS, html, and basic JS to make text based rogue-like likes.

I want something that I can include simple animations and an interactive interface. For example, I want the card deck listed on a sidebar, then when you click on the specific card listing, I want the actual card to appear and all of the stats to be listed on another info bar.

As I said, I know some JS, but I don't know if that's the best language for this or not. I'd prefer that whatever language I use it be cross platform. I intend to actually run some games with this system once I've finished programming it and users of all OS's are represented in the group. Bonus points if it will work on tablets or mobile devices.

Thanks for the recommendation. I hope to not be a leech soon as I start to continue to learn more stuff.

6351bb No.929

>>923
I'm still getting a good grasp on python. But I'm having loads of fun with the pygame library. Check it out! (You can deploy on mobile devices! :P)

3d6fa2 No.930

923:

I hope I am replying correctly because this board makes no sense to me. The reply window should open near what i'm replying to.

Sounds like you might like d3. It's a Javascript library and mostly used for data visualizations but also has been used for games, and I think it would be great for that. d3js.org

bb41db No.933

>>930
>>929

Thanks, I appreciate it. Both options look great.

105479 No.993

File: 1420096796136.png (2.9 KB, 586x80, 293:40, result.png)


VJOYINTERFACE_API SHORT __cdecl GetvJoyVersion(void);
VJOYINTERFACE_API BOOL__cdecl vJoyEnabled(void);
VJOYINTERFACE_API PVOID__cdeclGetvJoyProductString(void);
VJOYINTERFACE_API PVOID__cdeclGetvJoyManufacturerString(void);
VJOYINTERFACE_API PVOID__cdeclGetvJoySerialNumberString(void);


cout <<"Detected VJOY…\n";
cout <<"\tVendor: "<<(const char*)GetvJoyManufacturerString()
<<"\n\tProduct: "<<(const char*)GetvJoyProductString()
<<"\n\tVersion Number: "<<(const char*)GetvJoySerialNumberString()<<endl;


Gives me the first character of every string when it should be the entire string. I just want to print out the entire thing.

3e6080 No.994

What's with the else? This little piece of code could be a bit more simpler

105479 No.1040

File: 1420588191298.png (72.48 KB, 673x671, 673:671, figured.png)

>>993
Resolved it. Just in case anyone else was scratching chins about it.
The character array looked like {v, \0, o, \0, y, \0, … }

efa0ea No.1043

File: 1420597297577.jpg (17 KB, 640x480, 4:3, 1384804364699.jpg)


efa0ea No.1044

File: 1420597324654.jpg (10.7 KB, 320x272, 20:17, Bale_oooh.jpg)

Check em'!

a9f4e3 No.1066

How do I achieve an image like this, procedurally?

I know I need Worley (/cellular) noise, but my actual question is, how would I color it like this?
Should I use a fill algorithm, which changes color every time it finds a new 'area' to fill?

a9f4e3 No.1067

File: 1421429601196.png (264.82 KB, 512x512, 1:1, flagstone.png)


a9f4e3 No.1069

>>1067
>>1066
nevermind, as I suspected there's a simpler way which is simply to give every point used in voronoi a color. duhhhh

cool

cb8954 No.1080

>>1044
Nice dubs!

105479 No.1182

I have some code in C++ that has a lot of repeated arithmetic operations, and the goal is to have it perform as fast as it can before I (maybe) have to inline some assembly. However I'm not aware of automatic compiler optimizations.
So would assigning a variable and calculating a variable once (per iteration) be significant in the fight for miliseconds or something the compiler handles automatically?

		if (leaf1 <= leaf2) {
rqueue[i] = rqueue[(i << 1)+1]; //Swap parent with leaf1 (overwrite).
rqueue[(i << 1)+1] = temp; //Put in parent data at leaf.
i = (i << 1)+1;
}
else if (leaf1 > leaf2) {
rqueue[i] = rqueue[(i << 1)+2]; //Swap parent position with leaf2.
rqueue[(i << 1)+2] = temp;
i = (i << 1)+2;

38ff68 No.1211

How can I force a batch script to run as admin?
Two methods I've done are notify the user to right-click the script and click 'Run as Administrator', and create a script in Autohotkey that will run a batch file of the same name as admin. (the batch file will also run the AHK script, but only if it's not elevated)
Is there a better way to do this or are those my only options?

c05542 No.1212

>>1211 use linux, run sudo in script

4c2d61 No.1223

Hey guys,
In Python I'm pinging google to check the network.

import os
import time
hostname = "google.com"
response = os.system("ping -c 1 " + hostname)


def tester():
time.sleep(2)
if response == 0:
print(str(hostname), ' is up!')
else:
print(str(hostname), ' is down!')

while True == True:
tester()

So this returns 0 if the network responds and an error code if it doesn't. I stole this code right from StackOverflow.
Now, I wanna modify it. I'd like it to return the ping response time in milliseconds so I can cause the program to do different things depending on the speed of the network, specifically controlling GPIO ports on a Raspberry Pi. I've read the man ping page but I didn't see an option there. I've done a good bit of Googling and I haven't found a thing.
tl,dr: How do I make ping speed a variable in Python? If not Python, can another language do it?

f7f3cd No.1249

>>1182
I'm not sure about compiler optimisations but your code duplication was bugging me.

int index = (i << 1) + (leaf1 <= leaf2 ? 1 : 2);
rqueue[i] = rqueue[index];
rqueue[index] = temp;
i = index;

23fb63 No.1255

>>1182
use a profiler before you begin to optimize

de1345 No.1256

>>1223
bash/awk might be quicker and dirtier:
ping_time=$(ping -qnc5 test.com | awk -F/ '/rtt/{print $5}')
if [ -z "$ping_time" ]; then something fucked up, do something about it; fi
if [ "${ping_time%.*}" -gt 500 ]; then your network is slow, do something about it; fi

965916 No.1257

>>1223
You're gonna need to get the stdout from os.system (not sure hoe that works in python) and parse it for the time.

4c2d61 No.1261

File: 1423455107208.jpg (21.6 KB, 500x375, 4:3, insidePi.jpg)

>>1223
>>1257
Yeah I figured it out about an hour ago.
Ended up going with the subprocess module to run stdout back into Python.

def pingout():
ping_process = subprocess.Popen(["ping", "-c", "1", hostname], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
pingp = str(ping_process.stdout.read())
print(pingp)

From there I used regex to find the ping and assigned it to a variable.
Thanks guys.
Pic is the finished project before assembly.

4d47e9 No.1268

I'm starting to learn web development. I have checked at different frameworks and languages and my bet is Flask. Simple and fun in my eyes, and I'm a Pythonfag, enough said.

My question is, should I use jQuery with it? Almost every question I see on StackOverflow is replied and upvoted to use jQuery, even if the OP says that can't use that, asking for a native implementation. I'm asking this instead of a bunch of questions of how implement some forms, loading screens and other fancy shit.

8f4592 No.1343

>>911
>>912
>a hour

77d524 No.1372

File: 1424355590074.jpg (37.95 KB, 304x304, 1:1, 432.jpg)

trying to scrape this website but it has some wierd tags i dont know how to scrape
http://www.prx.org/search/users?advanced=advanced&commit=Search&keyword%5Bwith_all_of_these_words%5D=&location=&page=1&searchFor=users&select_type%5Bavailable_for%5D=any&select_type%5Bequipment%5D=any&select_type%5Brole%5D=any&select_type%5Bskill%5D=any

and my code at the moment, i feel like im fucking butchering it
import requests
from bs4 import BeautifulSoup

# add &start=10 to the end of link for next page
url = "http://www.prx.org/search/users?advanced=advanced&commit=Search&keyword%5Bwith_all_of_these_words%5D=&location=&page=1&searchFor=users&select_type%5Bavailable_for%5D=any&select_type%5Bequipment%5D=any&select_type%5Brole%5D=any&select_type%5Bskill%5D=any"
url_page_2 = '&page= ' + str(1)





r = requests.get(url)

soup = BeautifulSoup(r.content)

links = soup.find_all("a")

for link in links:
print "<a href='%s'>%s</a>" % (link.get("href"), link.text)

g_data = soup.find_all("div", {"class": "column span-14"})

for item in g_data:
print item.contents[2].find_all("div", {"class": "name"})[0].text

# print item.contents[0].find_all("p", {"class": "phone"})[0].text
#try:
# print item.contents[1].find_all("li", {"class": "primary"})[0].text
#except:
# pass


#try:
# print item.contents[1].find_all("p", {"class": "phone"})[0].text
#except:
# pass

0b5d35 No.1629

File: 1426031756806.png (48.78 KB, 1327x354, 1327:354, del.png)

g++ is giving me crap about a derived template class instantiating and throwing a class from a base template class.

In file included from slist-client.cpp:1:0:
slist.hpp: In instantiation of 'void Searchable_List<T>::replace(T, int) [with T
= int]':
slist-client.cpp:33:22: required from here
slist.hpp:46:32: error: invalid use of 'class Linked_List<int>::Out_Of_Range'


I'm not sure what sort of syntax requirement I tripped over, but in the base class
throw Out_Of_Range

has no issues. This sounds like something easily google-able, but with the results I'm getting, I'm probably not hitting the right keywords.

8b7723 No.1630

>>1268
you can use JQuery with it, it will make your js scripts be more easy to write and manipulate DOMS, etc.
Well, the only thing I wanted from JQuery is to handle AJAX through all PHP scripts than reloading them numerous times.

ce6cee No.1639

File: 1426094711599.gif (977.26 KB, 500x300, 5:3, 1416346733483.gif)

My brain has short circuited trying to figure this out, I just know it's simple but I can't think straight anymore.

I guess this is more of a math question:

I have a variable that goes from 1 to 100. I want to pass it through an algorithm so that 1 returns 1 (doesn't have to be precise) but 100 returns 1000, and anything inbetween works similarly.

Every time I think I get it, I end up with an algorithm where 1 returns 10.

b465b9 No.1640

>>1639


foo() {
return (n < 10) ? n : n * (n / 10);
}

105479 No.1644

>>1629
Resolved it.

Compiler kind of complaining that the blank classes Underflow and Out_Of_Range weren't using templates. They're moved out of the class declaration section and in the derived class, it is no longer prefixed with this ->.

9f4f16 No.1664

>>1639

y = mx + b
1 = m + b
1000 = m100 + b

999 = 99m
m = 111/11
b = -100/11

float foo(float n)
{
return n*111.0/11.0 - 100.0/11.0;
}

dff7cb No.1670

>>1639

lookup lerp

86ba4e No.2139

File: 1429419418887.jpg (145.58 KB, 547x547, 1:1, 1420209773113.jpg)

How would I program range in python?

I'm trying to create myself a IP address class flash card type game.

8dd6df No.2147

How would I vertically flip text in a 2d array in java?


105479 No.2208

;; Programming Exercise 12
;; Check for structural equality of a list.
;; (a, b = lists to compare)
(defun structurally-eq (a b)
(cond (and (a b);both lists are empty.
t)
(xor (a b) ;only one of the lists are empty.
f)
(and ('(cdr a) '(cdr b)) ;first of both is an atom.
(structurally-eq (cdr a) (cdr b)))
(xor ('(cdr a) '(cdr b)) ;only one of first out of both is an atom.
f)
(else
(and (structurally-eq (car a) (car b)) ;recursion over the car of each list
(structurally-eq (cdr a) (cdr b)))));recursion over the cdr of each list
)

I get *** - SYSTEM::%EXPAND-FORM: '(CDR A) should be a lambda expression, which I don't understand why.


e5373f No.2214

>>2208

Why have you quoted those cdrs?


105479 No.2216

>>2214

Mostly because the language confuses me. I looked up my error on stackoverflow and there was a mention to add a '.

But off here

https://en.wikibooks.org/wiki/Common_Lisp/First_steps/Beginner_tutorial

I don't have a clear idea of what quote is for.

(There's another error like "variable AND has no value" if I remove it.)


105479 No.2224

>>2208

;; Check for structural equality of a list.
;; (a, b = lists to compare)
(defun structurally-eq (a b)
;both lists are empty
(cond ((and (eq nil a) (eq nil b)) t)
;only one list is empty.
((xor (eq nil a) (eq nil b)) nil)
;if the `car` part of both lists is an atom
((and (atom (car a)) (atom (car b)))
(structurally-eq (cdr a) (cdr b)))
;one of the car parts of the list is a sub-list.
((xor (atom (car a)) (atom (car b))) nil)
;otherwise recursion over 'car' and 'cdr' of both lists.
((and (structurally-eq (car a) (car b))
(structurally-eq (cdr a) (cdr b)))))
)

Okay, after some rest and breakfast, got it; kind of, because I thought f was for false, but it gave me "COND: variable f has no value" before I swapped out the f's with nils.


6ecc5f No.2229

>>2214

he's trolling


b930d8 No.2346

Really quick Javascript question here:

Is there any kind of performance difference or any kind of benefit/handicap to doing one above another:

thing.other.object.related.inside.outside.a = 1;
thing.other.object.related.inside.outside.b = 2;
thing.other.object.related.inside.outside.c = 3;
thing.other.object.related.inside.outside.d = 4;
thing.other.object.related.inside.outside.e = 5;

var thevalue = thing.other.object.related.inside.outside;
thevalue.a = 1;
thevalue.b = 2;
thevalue.c = 3;
thevalue.d = 4;
thevalue.e = 5;


94743a No.2349

>>2346

>Is there any kind of performance difference or any kind of benefit/handicap to doing one above another:

Fair warning: I am not a JS wizard

You'd have to benchmark it to be sure, but in general, the second way should be somewhat faster (in unoptimized JS),

since it removes the need to look up 'thing.other.object.related.inside.outside' each time.

JIT compilers (i.e. Google's V8) could (probably) do that optimization themselves, though.


b930d8 No.2351

>>2349

>in general, the second way should be somewhat faster (in unoptimized JS), since it removes the need to look up 'thing.other.object.related.inside.outside' each time.

That's what I was thinking about, thanks


1db1f8 No.2354

I can't wrap my fucking head around javascript and how shit works really.

I have several inputs: radio buttons, list boxes, text boxes (none of them have ID), I need to do a function to validate they are not empty .

so

 <script type="text/javascript" >		function validar()
{
var aux=document.getElementsByTagName("input");
}
</script>

that's all i got of my function so far, but I have zero idea how to check if every input has no text or nothing has been selected.


3957d4 No.2359

>>2354

probably something like aux.isEmpty() or getText() or whatever. i'm sure the answer is just a google search away.

but before you write javascript eyecandy make sure your website has a working fallback mode with pure html and css.


b4eda8 No.2365


2f67ce No.2370

>>2354

getElementsByTagName() returns an Array.

I'm not sure if javascript has a foreach loop like java, but I guess you could do something like

for (var i = 0; i < aux.length(); i++) if (aux[i].value == '') alert('error');


579b13 No.2406

How do I make a GUI from scratch in ruby?


eea7ff No.2407


c4e870 No.2518

>>901

>facepalm

back to reddit


7448df No.2522

>>1040

Nigger do yourself a favor and right click the window border of your console, click properties and change the font to something schwayer than that


8fde94 No.2540

hey all

i'm using the following code to convert rgb to hex

'{:02x}{:02x}{:02x}'.format(r,g,b)

Now I need to be able to convert from hex back to rgb. I've seen some weird ways of doing this with ord and map but I was wondering if anyone could think of a simple way to do it with format()

thanks in advance


0672dd No.2553

Hey guys. I can't get out of a shitty regex+PHP situation, figured I'd ask you.

Short story: I have a few regexes which I'm using to get data from whois responses. But in 95% of cases, they're not picking up anything even if the same text (newlines stripped, commas stripped, only whitespace - I'm getting it by printing it after I've retrieved and stripped it) on regex101.com gives me the correct matches.

In another case it returns the correct match…and text I'm not interested into.

This does not return anything, even if it should:

preg_match('~[Registrar|Registrar Organization]:\s*(.*?)(Sponsoring|Registrar|\(|Name|\[)~si',$text,$registrar_name);

While this returns date, time and "Expire Date:" string:

preg_match('~Expir.*?Date:\s*([[:digit:]]*-[[:digit:]]*-[[:digit:]]*)~si',$text,$expir_date);

I've tried looking at $return_array[0] and [1], also checking with var_dump().

Error checking returns in ALL CASES preg_no_error.

Haven't found anything useful on stack overflow, and my googlefu didn't help either.

Any of you has an idea as to what I'm doing wrong?


df291d No.2589


/* Enter your own Javascript code here... */
/* You can include JS files from remote servers, for example: */
/* load_js("http://example.com/script.js"); */

// put 8archive.moe links after every post
var intros = getElementsByClassName("intro");
var 8archive_anchor = document.createElement("a");
8archive_anchor.appendChild(document.createTextNode("Archive"));
var board = window.location.pathname.slice(1);
board = board.slice(0, board.indexOf('/'));
var threadNo = window.location.pathname.slice(window.location.pathname.lastIndexOf('/')+1, -5);
var 8archive_url = "http://8archive.moe/"+board+"/thread/"+threadNo;
for (var i = 0; i < intros.length; i++) {
var postNo = intros[i].firstElementChild.id;
8archive_anchor.setAttribute("href", 8archive_url+"/#"+postNo);
intros[i].appendChild(8archive_anchor);
}


5e0fc7 No.2601

>>2589

help please?


5e0fc7 No.2603

>>2589

help please?


5e0fc7 No.2604

>>2603

>>2601

please ignore accidental duplicate


3421a2 No.2654

>>2589

1. don't use js

2. debug each variable. print them out or inspect them, figure out which one doesn't get set properly.

1. don't use js


bba1f5 No.2663

What the hell does RAII mean and why do people talk about it constantly like it's hot shit when talking about C++?

I've been reading a bit on it and, from what I understood, I think it means that resources are allocated during initialization of objects, and it is destroyed once the scope is exited.

What's so special about that and why does it warrant a fancy name? I thought it was the point of stack-based allocation, and while I thought C did the same exact thing, apparently it doesn't. Why isn't C's stack based allocation considered RAII?


4b5057 No.2673

>>2663

RAII is not just removing stack memory at the end of scope, I'd say every language does that.

RAII is about automatically calling destructor functions of objects when you hit the end of the scope they're defined in.

An equivalent in C would be automatically calling fclose on a FILE* at the end of scope.


f8d284 No.2687

writing a small tile-based game engine. I can't quite figure out why I can't list the rows after I've generated them. Any ideas would be much appreciated, I feel it's stupid simple.


#!/usr/bin/python2.7
from random import randint
import os
import sys
import time
def gentile():
global tid
r1 = "."
r2 = "o"
seed = randint(0,10)
if seed <= 9:
tid = r1
if seed == 10:
tid = r2
def main():
width = 10
height = 10
termwidth = width * 2 + 1
print "-" * termwidth
count = 1
for i in range(height):
rows = []
rows.append("\n ")
for i in range(width):
gentile()
rows.append(tid)
print(rows[i]),
count = count + 1
print "\n"
print "-" * termwidth
count = 0
for i in range(height): #Can't even
print(rows[count:count + 10]),
print "\n"
count =+ 1
main()


4e6067 No.2691

>>2687


for i in range(height):
rows = [] # <- Because 'rows' is local to the 'for' loop here.
# You must declare it outside of the loop.
rows.append("\n ")
for i in range(width):
gentile()
rows.append(tid)
print(rows[i]),
count = count + 1


f8d284 No.2692

>>2691

Thank you! ended up figuring it out myself, it's going along well though, added in a player and making him move at the moment!


df291d No.2700

>>2654

Thanks, I got it to work now

>1.

why?


cc5f6f No.2713

>>2700

(not him) JS is a really shitty language, but if you want to do client-side scripting you pretty much have to use it. Use it if you need it, otherwise stay away from it


bafe7e No.2716

>>1640

>n * (n / 10)

Why use a parenthesis at all? Multiplication and division are commutative

It's the same as n*n/10


1e167c No.2717

>>2716

just use 0.1 * n * n and ignore floating point


bda8f8 No.2729

QT or GTK?


ec051b No.2731

>>2729

Qt is much nicer to work with. It's not even a fair comparison. GTK is kind of shitty. However, Qt is best used with C++, so if you're adamantly anti-C++, then maybe GTK would be better.

I'll also through in that wxWidgets is a really nice toolkit, especially if you want to use a higher-level language. It has pretty good bindings to Python, Ruby, Perl, and even Common Lisp.




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]