/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

gna.org/projects/grub4dos/
floating-point-gui.de/
twitter.com/AnonBabble

First for lisp

First for AS3
function tracef(str:String, ... args):void {
var newStr:String = "";
if (str.search(/%[ions]/) != -1 && args.length > 0) {
var arr:Array = str.split(/(%[ions])/);
for (var i:int = 1; i < arr.length; i++) {
if (args.length > 0) {
var t:Object;
switch(arr[i]) {
case "%i":
for each (t in args) {
if (t is int || t is uint) {
arr[i] = t;
args.splice(args.indexOf(t), 1);
break;
}
} break;
case "%s":
for each (t in args) {
if (t is String) {
arr[i] = t;
args.splice(args.indexOf(t), 1);
break;
}
} break;
case "%n":
for each (t in args) {
if (t is Number && !(t is int || t is uint)) {
arr[i] = t;
args.splice(args.indexOf(t), 1);
break;
}
} break;
case "%o":
for each (t in args) {
if (t is Object && !(t is int || t is uint || t is String)) {
arr[i] = t;
args.splice(args.indexOf(t), 1);
break;
}
} break;
default: break;
}
}
}
for each (var p:String in arr) newStr += p;
}
else newStr = str;
trace(newStr);
return;
}
function isPSquare(n:int):Boolean
{
if(n == 0) return false;
var i:int = 1;
while(true) {
if(n < 0) return false;
if(n == 0) return true;
n-=i; i+=2;
} return false;
}
function eratosthenes(limit:int):Array
{
var primes:Array = new Array();
if (limit >= 2) {
var sqrtlmt:int = int(Math.sqrt(limit) - 2);
var nums:Array = new Array(); // start with an empty Array...
for (var i:int = 2; i

Well the Europeans who have actual lives are busy at work, and the NEET burgers are still sleeping in mommy's basement.

I'm waiting until it's time to go to the dentist so I can get back to work and stop shitposting on /dpt/ how about you, OP?

nth for C++
#if defined(_WIN32)
#include
#include
#include
#include
#include
#include
#include

int main(int argv, char **argc)
{
if(!argc[1] || !argc[2] || !argc[3]) throw "CLI Argument error: invoke with 'alarm h m s' ";
int hour = atoi(argc[1]);
int min = atoi(argc[2]);
int sec = atoi(argc[3]);
struct {int h; int m; int s;} tm_alarm;
tm_alarm.h = hour; tm_alarm.m = min; tm_alarm.s = sec;

int sleepTime = 5;
bool alarm = false;
do {
::Sleep(sleepTime*1000);
time_t time = std::time(0);
struct tm *tm_now = localtime(&time);
if((tm_alarm.h) tm_hour) &&
(tm_alarm.m) tm_min) &&
(tm_alarm.s) tm_sec)) {
::PlaySound("Invalid link for BOING sound, replace with a link for custom music", NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);
alarm = true;
for(int i = 0; i < 100000; i++) printf("ALARM\t ALARM\t ALARM\t ALARM\t ALARM");
}
}while(!alarm);
}
#else
throw "Unsupported operating system";
#endif

Europeans aren't human though. Australians on the other hand...

Just made a thingie that extracts window handle and OpenGL context from SFML and injects QML engine on top of it, pretty satisfied with the results and it could easily work with SDL and GLFW as well.
The only downside is that there's no Qt event loop so you need to manually process events from your framework's event loop and propagate them to the QML proxy so that components can receive them.

...

I basically don't have a problem with being sensitive to other people, but what's with the over the top obsession with political correctness in many programming communities?

American PC culture. It doesnt exist outside the western world.

nah, programming has like.. supernatural pc culture, it doesn't reflect general western culture at all.

>he hasn't been to your average liberal college campus

yes, I have, that's why I'm so weirded out about how it's even worse in a lot of github groups and so on

They think that the only reason more women and minorities aren't in programming is because the cis white men create "toxic atmospheres".
Actually, nobody fucking cares who you are or what you look like as long as you:
1) Write good code
2) Don't start every other sentence with "As a woman/person of colour/LGBTQ..."

It just so happens that the people shouting the loudest about the inequalities are simply unable to do either of these relatively simple things.

What could be worse than the communist tumblrinas crying about men in tech while enrolled in some useless shit like latina dance theory

the people that actually write programs to segregrate and censor social and general media. They do it for free

#include
#include
#include
#include

constexpr auto SleepTime = 5u;
constexpr auto BeepCount = 1000u;

int main(int argc, char **argv)
{
if (argc < 4) {
std::printf("Usage: %s h m s\n", argv[0]);
return 0;
}

int h = std::atoi(argv[1]),
m = std::atoi(argv[2]),
s = std::atoi(argv[3]);

while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime * 1000));

time_t time = std::time(nullptr);
struct tm *now = localtime(&time);

if (now->tm_hour == h
&& now->tm_min == m
&& now->tm_sec

>Write program to automate getting RSS feeds for animu
>Scrapes anichart.net's internal API
>Searches nyaa, finds releases of that series
>Adds rss feed to rutorrent
>Works fine
>After a couple of months, anichart changes their internal API; it breaks
>Have to rewrite a good chunk of it
>Works fine again
>A couple of months later nyaa dies
God fucking dammit. Why can't this program just stay working?
I'm sick of rewriting this shit. This program was supposed to help me save time.

How do I learn to write nice and readable code? If I write much code it gets unreadable

Hi guys
/* Question: What is proctecteed access specifier?
* Ques: How does protected acceess specifier govern accessibility
* Ques: of members for derived class and friends of derived class
* Ques: and user of derived class?
*/
#include
class Base{
protected:
int prot_mem;
public:
Base() = default;
Base(int l):prot_mem(l){}
};
class Derived:public Base{
public:
friend void foo();
void bar();
Derived() = default;
Derived(int x):Base(x){}
};
/* bar can access prot_mem */
void Derived::bar(){
std::cout

What are these "Avatars" you are using? Lol...

Stop using meme languages, that'll sort out 90% of the ugliness right off the bat.

That won't work for a standalone function, the friend void foo() inside of derived is as if it was a class member that had no definition and only declaration.

Yes! Memes! I love them too!

That's a "Meme Macro" as we call them... Not a "Standalone Function".

>What are u saying bro?

Fixed it my fucking bad
friend void foo(Derived&);

Nice freaking Meme my "Bro".

Why does it loop forever?
#include

int main()
{
int result[4];
for (int number_current_matches = 0, i = 1; number_current_matches < 4;
i++)
{
//printf("Matching %d\n", i);
int sum_multipliers = 0;
for (int j = 1; j

This.
Incompetent assholes are trying to gain unfair advantages by riding the SJW/feminist bandwagon.

I need help with my C programming course.

The exercice is asking me to load up a set of data in a matrix of 30x12

Said matrix can be of one data type only but in each element I need to save two variables.

I'm at loss here, I know how to build up the matrix but how else do I make sure it saves two dinstinct variables in one element of a different data type?

I cannot use any record array.

Are the values integral?
If so just use bit packing.
Say the values are in range 0-65k, you can just use 32-bit integer and pack each variable in the lower & higher 16 bits.

bump from yesterday...
does anyone here know anything about x86?
specifically, x86 real mode?
or more specifically, how to disable write-protection on shadow-ram?

Array of structs.

If you can't use structs then use a 32 bit field, with the upper 16 bits for v1 and lower bits for v2.
That's properly autistic though.

Two variables an integer and a float(which is expressed in %).

But I need to save these data in the matrix remember.

Something along the lines of.
void set(uint32_t *val, uint16_t high, uint16_t low)
{
*val = ((uint32_t)high > 16;
*low = val & 0xFFFF;
}

I forgot to link the post:

You can have an array (or matrix) of structs, user.

A struct is a datatype btw, either you're not telling us something or your exercise is trying to be smart but is poorly worded and you can take advantage of it.

bump

>Why does it loop forever?
It doesn't.

struct {
int anInteger;
float aFloat;
} data[30][12];

Use a better language which doesn't allow looping.

Inb4 you bring up some stupid shit about Turing Complete programming languages being bad.

Fuck off

...

Not "bad". Just shit.
user, what.

Why can't operating systems boot other operating systems?

Imagine if you're in nautilus or whatever and you double click an EFI file and it's like "WARNING: This is a boot-time application. It can be run, but requires an unconditional transfer of all hardware control. Stop this operating system and launch [filename]? [No (default)] [Yes]"

Does anyone here has Lynda.com premium account? I need one exercise files for one course

The guy who torrented it fucked up big time

I only need someone to dl one exercise files

I'm working on a remake of Space Station 13 but in sepples with SDL2 and using Lua for modding/customization. There's really nothing right now but I'm working on collisions. I'll put it on memehub once I get collisions and stuff done.

Because there is a lot of hardware initialisation and kernel-level stuff that happens when an operating system boots up. There isn't a way an operating system can pass that shit off to something else easily.

something something interrupts

Wrong thread.

>/dpt/ - Daily Programming Thread
>What are you working on, Sup Forums?
I'm pretty sure I am in the correct thread. I am programming and the OP was asking what I am working on.

can you imagine the fucking riots

"TECH SUPPORT WHENEVER I CLICK GRUBX64.EFI MY COMPUTER CRASHES TO THE BOOT MENU"

"gg no re"

"did you actually read the warning that popped up before you clicked ok"

"WHAT THE FUCK IS READING"

they can.
look up grub4dos.

I'm working on a minimalist versatile 2D game framework with C89 and SDL, it will pretty much be a bare bones data-oriented implementation of the ECS paradigm, but with an OOP-like interface, plus some really basic and essential component types like things that can have an animated sprite and a position on the screen and perform a behavior on a schedule, worlds that can be made out of tiles that can have various flags and sometimes be animated, a togglable system for checking collisions, etc. I'll then extend it with RPG elements and create one of those sentimental RPGs that people play for the story and aesthetic (e.g. Off, Lisa, Undertale, Yume Nikki, Mother 3, etc). Except I'll majorly shit it up. Then it'll be like a joke.

>gna.org/projects/grub4dos/
>Expired certificate
That's just sloppy. Anyway, thats an extension to grub. It's not a ""real"" full-blown operating system.

So I'm designing an Entity Component System for a small project in MonoGame and I'm wondering where does the implementation of specific interactions go? Say for instance I have a missle entity with an EffectComponent that makes the blow up effect. If the EffectComponent has a Draw method do I check some sort of EffectType or how do I go about differentiating different component types that are under the same component? Do I implement a MissleEffectComponent as a sub class of the EffectComponent and have it handled there instead?

Other than the algorithm being totally dumb, inefficient and ungeneralizing, you don't want to do this:
int result[4];
printf("%d", result);

that would just print the address of the array and not the array itself (hint: you need a loop for that too).

Also, why not printing the perfect numbers on the fly? You wouldn't even need an array then.

>SS13
Man that game was fun, the only bad thing really was the awful BYOND framework shit.

If I said #pn would that mean anything to you?

>#pn
No idea what that is. Is it some kind of IRC server?

It was a long shot, never mind.

You could have the type of effect to produce be an element of the EffectComponent's state, in the same way, for example, that your core component probably has state like where its entities are on the screen.

To create an adjacency matrix graph in Java could I use a two dimensional (nxn) array to store the arraylists that store the edge & vertex objects?

Also how would the method look within an edge class that gets each of the endpoints within graph?

Any help is appreciated?

Telegram Chatbot which learns from interaction based on trigger - response
in Python hosted in GAE
>chntybot
if anyone is interested

In an adjacency matrix, you don't need arraylists at all. You could have a two dimensional array of size NxN, and each cell would store any data you want to store under the edge between those two vertices, or null if there is no such edge. Then you could have an additional one dimensional array of size N that stores any data you want to store under the vertices themselves.

To find the endpoints of an edge within the graph, just look at the two indices into the two dimensional array you used to get to the edge, and there's your endpoints. In fact, under an adjacency matrix representation, it's generally assumed you use the endpoints to look up edge data, not the other way around.

Why? I don't understand what you are trying to do here senpai

int[] weights;

weights = new int[n * n];

addEdge(i, j, w)
{
weights[i * n + j] = w;
}

Let's make lists for every language of tasks, which can't be solved efficiently in these languages, /dpt/!
I'll start:

>Prolog
>Anything practical

im using the 4x2chan python api to get posts, but all of the posts are missing their newlines

Sup Forums is the same thing and the posts come with their newlines just fine, but the 4x2chan api seems to be fucking it up

What is wrong with this?

import glob
import os
from random import choice
from string import digits
from random import randint

extensions = ['.jpg', '.png', '.gif', '.jpeg', '.webm']


def random():
new_ext = extensions[randint(0, 4)]
return '14{0}'.format(''.join(choice(digits) for i in range(11))) + new_ext


for meme in extensions:
meme_folder = os.getcwd()
rename = glob.glob(meme_folder + '*' + meme)
for thing in rename:
new_name = meme_folder + random()
while os.path.isfile(new_name):
new_name = meme_folder + random()
else:
os.rename(thing, meme_folder + random())

My Anti-Archieve CIA script

blog post time!
I finally figured out how to disable write protection on shadow-rom.
turns out the bits that control it are hidden somewhere deep in the chipset's northbridge configuration space. that sucks since I have to write chipset-specific code now.
next problem, the dos memory chain somehow corrupts immediately after my program terminates. it's fine before the final return instruction, then suddenly the last block's Z is set to M for some reason and it ends up including rom code in the memory chain.
ugh why does this shit have to be so fucking complicated.

Newb here, why does python behave like this:

>>> 0.1+0.2
0.30000000000000004
>>> 0.1+0.3
0.4
>>> 0.1+0.4
0.5
>>> 0.1+0.2
0.30000000000000004
>>> 0.1+0.1
0.2


I understand that small values are added and such. But why 0.1 + 0.2 gives retarded results, and other sums give normal results?

Read IEEE 754

Because they're doubles.

floating-point-gui.de/

But that would be autistic.

Computers are autistic.

hey I like this. makes me want custard too for some reason.

did you get raped by a computer

nvm solved it myself incase no one cares

for some reason 4x2chan uses tags for their newlines instead of 4chans tag

I don't want to talk about it.

in python, do you think bitwise operators for dividing by 2 / multiplying by 2 and adding 1 are faster than the typical instructions? i'm going to be implementing heapsort

You need parentheses around your bindings list.

Doesn't cripplechan have an API?

0.1 is a repeating sum in binary. like, how 1/3 in decimal is 0.333333333333333.

.1 in decimal is .000110011001100110011, etc. This stuff is binary, with only a certain amount of floating point precision.

Vices aren't inherently wrong, they're just conducive to wrongs. For example, a gluttonous, greedy slob can still be a good person, it's just harder for him than it would be if he gave up gluttony, greed, and sloth.

wat

Trying to create an algorithm which will convert any undecidable problem into a decidable one.

this is a test post, ignore it

Currently trying to get my instruction fetcher for my processor working...

Instructions are variable length from 1-4 words in length. After all words are read it raises a 'done' signal and a finished instruction tuple is made available (PC, Instruction, Instruction_size, AccessOOB) for the decoder, which transforms the tuple into a much larger tuple of control signals. Every stage of the processor gets one of these 'signal wavefronts' before it goes on the next stage.

If the decoder decodes a branch instruction, the fetcher's currently executing fetch is invalid and it must pause execution.

Currently having issues with it working in the fully pipelined manner I expect (request for instruction word at the next address is fetched as soon as the previous value is made available). It's waiting until the next cycle to send the next request and set the 'done' flag. It's starting to piss me off, Verilog is a nightmare. I know exactly what I want, but the language is so unintuitive and baroque I'm having difficulty realizing the hardware I envision.

acknowledged

What?

>like, how 1/3 in decimal is 0.333333333333333.
It's not though. 0.333333333333333 isn't the full number.

GCC 7.1 ReleasedGCC 7.1 ReleasedGCC 7.1 ReleasedGCC 7.1 Released

AWW FUCK YEAH NIGGA

It's shit though. Even my "toy" compiler is better.

>>> 0.1+0.2
0.30000000000000004
>>> round((0.1+0.2),3)
0.3
>>> print "{:.9f}".format(0.1+0.2)
0.300000000
>>> print "{:.8f}".format(0.1+0.2)
0.30000000
>>> print "{:.7f}".format(0.1+0.2)
0.3000000

a work around if formatting is the issue, not a work around if accuracy is an issue.

ebin

Will gcc ever get the apple's block extension support for C?