Previous thread: What are you working on Sup Forums?
/dpt/ - Daily Programming Thread
Why is JS so cancerous? What the fuck is wrong with all those wrappers
#include
#include
#include
// Lists must have a value member and a next pointer
template
struct is_list
{
template
struct helper;
template
static std::false_type has_next(...);
template
static std::false_type has_value(...);
template
static std::true_type has_next(helper *);
template
static std::true_type has_value(helper *);
typedef decltype(has_next(nullptr)) next_tester;
typedef decltype(has_value(nullptr)) value_tester;
static const bool value = next_tester::value && value_tester::value;
};
template
struct is_list : std::false_type {};
size_t print_list(...)
{
std::cout
I love C++!
Working on our in house Netty based Back-end architecture.
Write a program in your favorite language to create and print a cyclical list. So far we've had submissions in C, C++, Python, and Haskell
That is beautiful
Working with this Indian guy.
He had done database with like 10 tables where all of them had like 20 columns, he said it was not normalized by design choice.
We are moving to new platform which has new db with over 100 tables which is normalized properly.
He told me it sucks because it's over normalized.
Is that guy actually retarded or is there really some benefit to having everything in one fucking table?
can i import libraries or instantiate objects (from different classes) inside a class without a main in java?
of course
hey guys, working on some Python exercises, and I solved one but I don't understand quite how it works. here is the assignment:
>Write a function called cumsum that takes a list of numbers and returns the cumulative sum; that is, a new list where the ith element is the sum of the first i+1 elements from the original list. For example:
>>> t = [1, 2, 3]
>>> cumsum(t)
>[1, 3, 6]
and my solution:
t = [1, 2, 3, 4]
def cumsum(x):
b = []
for i in x:
a = x[0:i]
b.append(sum(a))
return b
print(cumsum(t))
I don't really understand the "a = x[0:i]" part. I thought slicing x[y:z] started the slice at y and went up to, but NOT INCLUDING, z. So in my code, when it's running through the second element, i=1, it should slice to [0:1] meaning just the first element... Where am I getting this wrong?
thanks
He sounds pretty retarded. The only reasons not to normalize your tables are laziness and stupidity. He sounds like he's right in the middle
>cumsum
I'll give you some cumsum if you know what I mean
cumSumOnMe();
Your logic is fucked.
>not you.CumSum(me) disgusting
alright, so how exactly?
Fails whenever the input list is not an enumeration from 1 to n.
fixd
def cumsum(x):
sum = 0
out = []
for i in x:
sum += i
out.append(sum)
return out
You denormalize when you get a perfomance hit due to joins and shit. In 99.99% cases, you don't need it. In remaining 0.008% cases, denormalizing won't help anyway.
Rate my FizzBuzz, Sup Forums
#include
#include
#define spc(x, xs, c) \
((x) % (xs) == 0 ? (c) : ' ')
#define ch(m, i, c) \
(*((m) + (i)) != 0 ? (c) : ' ')
#define pc(c) putchar(c)
void character(size_t xw, size_t xl, size_t space, char c, const int* matrix)
{
size_t x;
for (x = 0; x < xw; ++x)
pc(spc(x, space, ch(matrix, 0, c)));
for (; x < xl; ++x)
pc(spc(x, space, ch(matrix, 1, c)));
for (; x < xl + xw; ++x)
pc(spc(x, space, ch(matrix, 2, c)));
for (; x < xl * 2; ++x)
pc(spc(x, space, ch(matrix, 3, c)));
for (; x < xl * 2 + xw; ++x)
pc(spc(x, space, ch(matrix, 4, c)));
}
void line(size_t xw, size_t xl, size_t space, const char* str, const int* matrix)
{
size_t x;
while (1) {
character(xw, xl, space, *str++, matrix);
if (*str == '\0')
break;
for (x = 0; x < space; ++x)
pc(' ');
}
pc('\n');
}
void fizzbuzz(size_t size, size_t thick, size_t space, const char* str)
{
int matrix[] = {
1, 0, 1, 1, 1,
1, 0, 1, 0, 0,
1, 1, 1, 1, 1,
0, 0, 1, 0, 1,
1, 1, 1, 0, 1
};
size_t xw = thick * space;
size_t xl = size * space;
size_t yw = thick;
size_t yl = size;
size_t y;
for (y = 0; y < yw; ++y)
line(xw, xl, space, str, matrix);
for (; y < yl; ++y)
line(xw, xl, space, str, matrix + 5);
for (; y < yl + yw; ++y)
line(xw, xl, space, str, matrix + 10);
for (; y < yl * 2; ++y)
line(xw, xl, space, str, matrix + 15);
for (; y < yl * 2 + yw; ++y)
line(xw, xl, space, str, matrix + 20);
}
int main()
{
fizzbuzz(3, 2, 2, "*");
return 0;
}
/dpt/ is this a good implementation of random numbers?
#include
/** fuckUpBit
* Send an electrical signal to the int'th bit of the char. The
* specific strength of the signal should cause future read
* operations on the bit to yield uniformly inconsistent results. (I
* know this is physically possible, but I don't know how to do it
* in C.) */
void fuckUpBit(char*, int);
/** random
* Return a random number generated using electrical noise. */
int random(void) {
static int fuckedUp = 0;
static int source;
if (!fuckedUp) {
int i, j;
for (i = 0; i < sizeof(int); i++)
for (j = 0; j < CHAR_BIT; j++)
fuckUpBit(((char*)&source) + i, j);
fuckedUp = 1;
}
return source;
}
In Haskell, this is just
cumsum = scanl1 (+)
Oops I forgot source should be static volatile int, not just static int
cool, I see now. Thanks!
import sys
import os
#test.py
def q(question):
return input(question)
def wrong():
os.remove("test.py")
sys.exit()
if not q("Please enter a user name in alphabetic characters only \n>").isalpha:
wrong()
if q("Please enter you favourite RBG primary colour \n>").lower() not in ['red','green','blue']:
wrong()
that's even gayer than
you.CumSum(me)
>>>/reddit/
Fixed for volatile-correctness:
#include
/** fuckUpBit
* Send an electrical signal to the int'th bit of the char. The
* specific strength of the signal should cause future read
* operations on the bit to yield uniformly inconsistent results. (I
* know this is physically possible, but I don't know how to do it
* in C.) */
void fuckUpBit(volatile char*, int);
/** random
* Return a random number generated using electrical noise. */
int random(void) {
static int fuckedUp = 0;
static volatile int source;
if (!fuckedUp) {
int i, j;
for (i = 0; i < sizeof(int); i++)
for (j = 0; j < CHAR_BIT; j++)
fuckUpBit(((volatile char*)&source) + i, j);
fuckedUp = 1;
}
return source;
}
Cyclical, as in if I keep incrementing over it it just starts again, so for a 20 element list, list[21] is list[1]?
Please repost the Python version. I'm working on my own, want to compare.
Put a print(i) in your for loop and you will know immediately
Useless meme challenge.
Name a better challenge
Cold turkey isn't how you fix addictions, it's by overcoming yourself.
Challenges are retarded unless they're for educational purposes.
Showing that you can use arbitrary constructs, functions, and state doesn't mean you're a good programmer.
I am just trying to LIMIT IT, not outright stop it.
i was brainwashed a a kid to want to be involved in the tech industry and I was only shown enduser packages and products with no understanding of how to actually make or reverse engineer any of what I interacted with, why do I still want a job in the tech industry.
I have no education in this only what I was brainwashed into wanting to do when I was a kid
so should I kill myself what hope is there in my life
Lol, learn. Fascination with end user products is what drives people to any career. If you find out you don't like it after a valid try out, consider something else.
what?
Besides, the 'tech industry' is very diverse. I thought I wanted to make video games when I was younger, and I just ended up on a different path.
i must gitgud then
I did make video games when I was younger, in highschool I made flash games
Hey guys I'm more on the operations side of things but I'm learning Python and Ansible to up my devops game.
For my first real project I want to write a script that uses my area's GeoIP list and scans each IP in the area for the most commonly used ports that are open (maybe even checks for exploits) and then lists the IPs in various text files named "Port 3389 Open" or something of that nature. How difficult do you think this would be for a beginner?
Also obviously will utilize nmap and most likely nmap scripts to do the scanning so I won't have to write those.
Cyclical array in Python (again):
pastebin.com
I'm toying with an edge detection program using genetic algorithm.
How retarded is this?
>the 'tech industry' is very diverse
Yeah, a huge sea of diverse white men
DETECT THESE EDGES
*unzips dick*
>genetic algorithm
Also known by its other name: "stupid search"
Is there a way to access datatypes that are not concurrency safe through channels in golang without making it look fucking retarded and more complex than simple mutexes
docs.opencv.org
Alternatively, if you're just looking for pixels along edges (rather than keeping track of which pixels belong to the same edge) why don't you just
>create a copy of the image
>blur it with a small radius
>subtract blurred copy from original
>threshold pixel values
no, it's "stupid automatic search", which means you don't have to do much work, just sit back and let the algo take control.
Writing libc on FASM.
(labels
((helper (orig remaining)
(if (not remaining) (helper orig orig)
(lambda ()
(cons (car remaining)
(helper orig (cdr remaining)))))))
(defun circular-list (&rest args) (helper args args)))
(defun print-circular-list (cl n)
(when (> n 0)
(let ((pair (funcall cl)))
(print (car pair))
(print-circular-list (cdr pair) (1- n)))))
What is your opinion on recruiters?
I made a LinkedIn account last night and I already got mail from two recruiters. Should I bite or find a job by myself?
All those examples can be assumed to be slow. Why do you trust C++ anymore?
If you've worked in any sort of high performance computing you'd know it's a very useless feature.
Amdahls law is in full effect here. And unlike most CS on speed things it's a rather constraining law.
You have to keep it in mind when you build a parallel system for speed. Important for clusters as well as single machines.
But again as I said. If you really don't care I'm sure it's a plus if you ignore cache stomps that might occur (which shouldn't be a big deal if what you're using this for is rather slow loop iterations).
Lel it don't fucking work.
(print-circular-list (circular-list) 4) ; stalls out forever
>Atom
>ASM
Oh god
Look up the rep instruction for str_len (and other string-related functions), could be useful
No one has any advice on this?
An empty circular list doesn't make any sense you dumbass. What exactly did you expect it to do.
>meme
Use
>I guess you assumed..
No I know how these systems work. The problem with these systems is that either you're handling the absolutely most trivial case of not having any data sharing. In which case assigning work to an existing thread pool has always been there. Adding this just complicating the other circumstance that is when you have data sharing and this kind of system simply can't be sufficient unless there's some super advanced code analysis I haven't heard of. Basically if you can teach the compiler to do the job of the programmer well enough you would see gains. I don't deem that all that likely though. You might get there through profiling the program and feeding it back repeatedly. Which certainly would be interesting but it's usually not sufficient for software in general as you don't really stop developing/maintaining software anymore.
That looks delicious. What is it? Is that raw salmon?
i was gonna ask on the stupid questions thread, but this seems like a better thread to ask in.
i bought an RGB keyboard that is controlled only through the FN key there is no software ofr it. it has preset colors and animations on it. i want to try and code some different animations and colors onto it.
how would i go about this? what would i need?
is this too difficult for someone who has never done anything like this to do?
thanks
It's difficult to measure difficulty. And beginner is very vague. So people can only really answer when they feel it'd be impossible.
To me it sounds entirely feasible. I haven't done geoip stuff but I assume it's either easy or there's a good library for it.
>STOP DOING FUN THINGS THAT I DON'T LIKE
It's literally for educational purposes. A lot of programmers on here are young CS students or hobby programmers, and doing challenges is fun
Nice job anons
Depends on which keyboard it is. I'd start by googling the keyboard make and model, looking for some kind of software documentation. If it doesn't expose some way to change the colors through software, you might be able to hack some kind of microcontroller onto it, but that's probably a bit more involved than you're looking to do.
It sounds rather intractable. You'd need to write a driver for the keyboard in the best case.
In the worst case the color stuff is implemented in HW and you'd have to reverse engineer that part of it. Which may be easier but it's not programming it's more about electronics.
And creating an interface for it might be a challenge unless you also write a new driver that handles transmitting color codes.
Thanks. I believe there is a few companies that have IP databases that I will have to use.
>implementing a data structure is fun
>trying new things in programming when you're a student is not fun
>implementing a data structure is ever fun
>implementing a data structure is not always struct instead
>being this addicted to closures
In C when implementing hashtable. Should you make it hold size of the slot value and have fixed sized slots or just put void pointer there?
Who are you quoting?
Not that guy but unless it's your first or second datastructure it really isn't fun. It's a very concentrated programming problem where what I enjoy, engineering, is completely absent.
If you enjoy typing in code and running it that's fine. I'd consider you an odd case.
When I read your post, I thought you were an idiot who was illiterate. Then I reread your post, and now I think I'm an idiot who is illiterate
lern 2 greentext, newboy
What do you enjoy doing then?
Typing boilerplate?
Writing your own shit is the only time programming could actually be considered "fun".
>lern 2
its the RK Pro104. ive searched for software but i cant find anything. yeah i wouldnt even know where to begin with that.
yeah that definitely sounds really difficult.
>your own shit
How is your typical datastructure your own shit?
I enjoy systems programming.
>fun
Uh, it all depends on what you need. If the value is not directly accessible via hash but is actually a pointer to the value, then obviously that's going to be slower, but sometimes it may be what you want anyway.
>it are hte whomst art thou quoting meme
>When I read your post, I thought you were an idiot who was illiterate. Then I reread your post, and now I think I'm an idiot who is illiterate
I'm not the guy who originally said the thing, I just thought I'd make fun of it.
>defun
>defstruct
>using defun instead of defstruct to implement a data structure
>probably means you use a message passing paradigm where the object is a closure and the messages are parameters to the closure
>borf
github.com
This is a good library.
You can look at what they do if you want.
>stb
>good
senpai...
>implementing lists in List Processing Language
(print '#1=(1 2 3 . #1#))
I'd like to see your defstruct version.
>
>It's a very concentrated programming problem where what I enjoy, engineering, is completely absent.
That depends on the kind of data structure you're implementing.
Non-exhaustive list of data structures which are generally heavily engineered by necessity:
>open-addressing hash table with double hashing
>database (technically a data structure, if you think about it, albeit a very big one)
>general purpose directed graph
>language evaluation tree
>simulated electrical circuit
If I'm one of 3 in a class of 25 getting A's on all my programming projects then that must mean i could be above pajeet programming, right?
>programming classes
>i could be above pajeet programming
No.
>>database (technically a data structure, if you think about it, albeit a very big one)
kek
Post your last assignment requirements.
>on all my programming projects
name three
No, it means that your study is Pajeet tier.
String str = "test1";
Pattern pattern = Pattern.compile("1\b");
Matcher matcher = pattern.matcher(str):
return matcher.find();
why does this return false?
Every regex tester says this should find the "1" and work
This guy has it right: Classes are for weak willed liberal pansies. You're probably a smelly millennial. If you've had any contact with higher education you're corrupted with poopy pajeet blood. Real men are strong and don't need school to program good.
(loop with circ = '#0=(1 2 3 . #0#)
do (princ (pop circ)))
nothing serious, its an IT degree but the class made me enjoy programming. I figured getting A's meant I might have a knack for it.
the last project was just a c# interface for a user to do queries on a database. The program needed to sort entries, return certain entries, without affecting the db and things like that.
>this exists
>i bothered to spend 12 lines of code reinventing it
wow i am literally the best at doing nothing but waste time 24/7
Don't be sad, there's barely any use for ciruclar lists.