lainchan / λ
What are you working on?
Jane Doe · 2017-04-28 10:43
I ain't gonna lie, I have a C question concerning a project I'm working on and thought I might as well start a personal programming projects thread.
What are you working on?
Does it serve a purpose or is it just for fun and practice?
Post some code you are particularly proud of, want critique on or need help with!
SHODAN · 2017-04-28 10:59
So, still OP here with my question. I am working on a little daemon that runs on my laptop and periodically polls a website for its status. I make and record music and sometimes this annoys my neighbors, so I want to provide a website for them where they can just click a button and then a notification pops up on my desktop telling me that I'd better be quiet.
When I start the server, at first it reliably shows me notifications, but after it has been running for a while, although everything else seems to run smoothly, the notifications just don't show up anymore. I am writing in C, using libnotify to send notifications. Below is the relevant code, I hope someone can help me.
If you are interested in the project, I can post more details. My endgame is getting my daemon to make a smartbulb cycle through colors when a complaint is registered, so I can't miss it, however, first I want to get the notifications to work.
// server-error.c
#include <stdio.h>
#include <libnotify/notify.h>
#include <stdbool.h>
#include "server-error.h"
void server_error (enum errors e)
{
// This function gets called whenever something goes wrong
// that affects the proper execution of the program
// initiliazing libnotify if it isn't already
if (!notify_is_initted()) {
notify_init("Laut Server");
}
static bool nvar_initialized = false;
// Using static variables to keep the notifications
// in memory. I read somewhere you should reuse noti-
// fications, but I do admit that I don't really know
// what I am doing here exactly
static NotifyNotification *n_sock_err;
static NotifyNotification *n_thread_err;
static NotifyNotification *n_curl_err;
if (!nvar_initialized) {
n_sock_err = notify_notification_new("Laut Server", "A socket error occurred", "messagebox_critical");
n_thread_err = notify_notification_new("Laut Server", "A threading error occurred", "messagebox_critical");
n_curl_err = notify_notification_new("Laut Server", "Failed to connect to remote server", "gnome-netstatus-error");
notify_notification_set_timeout(n_sock_err, NOTIFY_EXPIRES_NEVER);
notify_notification_set_timeout(n_thread_err, NOTIFY_EXPIRES_NEVER);
notify_notification_set_timeout(n_curl_err, NOTIFICATION_EXPIRY); // This might seem wrong or weird at first glance, but NOTIFICATION_EXPIRY is defined in server-error.h (see below)
nvar_initialized = true;
}
fprintf(stderr, "ERROR: ");
// Up to some point, the notifications in the switch
// statement below show up on the desktop, but after a while
// they stop. One notification can pop up multiple
// times, so I think it has something to do with the
// amount of time that passes between calls to
// notify_notifications_show(...), rather than the
// variables like n_sock_err going stale after being used once
switch (e) {
case ERROR_SOCKFD:
fprintf(stderr, "Failed to create socket sockfd");
notify_notification_show(n_sock_err, NULL);
break;
case ERROR_BIND:
fprintf(stderr, "Failed to bind to sockfd");
notify_notification_show(n_sock_err, NULL);
break;
case ERROR_ACCEPT:
fprintf(stderr, "Failed on accept()");
notify_notification_show(n_sock_err, NULL);
break;
case ERROR_READ:
fprintf(stderr, "Failed to read from asockfd");
notify_notification_show(n_sock_err, NULL);
break;
case ERROR_SRV_THREAD:
fprintf(stderr, "Failed to create server thread");
notify_notification_show(n_thread_err, NULL);
break;
case ERROR_ALARM_THREAD:
fprintf(stderr, "Failed to create alarm thread");
notify_notification_show(n_thread_err, NULL);
break;
case ERROR_CURL:
fprintf(stderr, "Failed to connect to remote stat server");
notify_notification_show(n_curl_err, NULL);
break;
}
fprintf(stderr, "\n");
}
void server_message (enum message m)
{
// This function gets called whenever something
// happens that it would just be nice to know about
// It basically is the same as server_error(...)
if (!notify_is_initted()) {
notify_init("Laut Server");
}
static bool nvar_initialized = false;
static NotifyNotification *n_shutdown_msg;
static NotifyNotification *n_alarm_status_msg;
if (!nvar_initialized) {
n_shutdown_msg = notify_notification_new("Laut Server", "", NULL);
n_alarm_status_msg = notify_notification_new("Laut Server", "", NULL);
nvar_initialized = true;
}
fprintf(stderr, "NOTICE: ");
switch (m) {
case MSG_SERVER_SHUTDOWN:
fprintf(stderr, "Server shutting down");
notify_notification_set_timeout(n_shutdown_msg, NOTIFY_EXPIRES_NEVER);
notify_notification_update(n_shutdown_msg, "Laut Server", "Server Shutting down", "application-exit");
notify_notification_show(n_shutdown_msg, NULL);
break;
case MSG_DONE:
fprintf(stderr, "Server has shut down cleanly");
notify_notification_set_timeout(n_shutdown_msg, NOTIFICATION_LONG_EXPIRY);
notify_notification_update(n_shutdown_msg, "Laut Server", "The server has shut down", "application-exit");
notify_notification_show(n_shutdown_msg, NULL);
notify_uninit();
break;
case MSG_ALARM_STARTED:
fprintf(stderr, "A signal was received, alarm routine started");
notify_notification_set_timeout(n_alarm_status_msg, NOTIFY_EXPIRES_NEVER);
notify_notification_update(n_alarm_status_msg, "Laut Server", "An alarm signal was received", "dialog-warning");
notify_notification_show(n_alarm_status_msg, NULL);
break;
case MSG_ALARM_ENDED:
fprintf(stderr, "You acknowledged the signal, alarm routine ended");
notify_notification_set_timeout(n_alarm_status_msg, NOTIFICATION_EXPIRY);
notify_notification_update(n_alarm_status_msg, "Laut Server", "The alarm signal was acknowledged", "answer-correct");
notify_notification_show(n_alarm_status_msg, NULL);
break;
}
fprintf(stderr, "\n");
}
// server-error.h
#ifndef SERVER_ERROR_H
#define SERVER_ERROR_H
#define NOTIFICATION_EXPIRY 4000
#define NOTIFICATION_LONG_EXPIRY 500000000
enum errors {
ERROR_SOCKFD,
ERROR_BIND,
ERROR_ACCEPT,
ERROR_READ,
ERROR_SRV_THREAD,
ERROR_ALARM_THREAD,
ERROR_CURL
};
enum message {
MSG_SERVER_SHUTDOWN,
MSG_DONE,
MSG_ALARM_STARTED,
MSG_ALARM_ENDED
};
void server_error (enum errors e);
void server_message (enum message m);
#endif
cdr · 2017-05-09 20:06
Unfortunately I dont know how to help you OP since im relatively new to programming but I can share what im working on, though it isnt very complicated.
Im working on a Touhou themed version of pong that uses health bars instead of score. currently Reimu and Cirno are the only playable characters but I plan on adding many more.
0x3F · 2017-05-10 05:52
wow, i wasnt expecting this thread to be empty.
i haven't yet started working on it, but i want to fix up MPDroid so that it actually is able to stream music from my mpd server instead of having to use vlc to actually listen to the stream like i do now.
i also want to make a fork of clover that points to lainchan instead of 4chan, since overchan is soykaf
Apoc · 2017-05-10 06:00
I'm interested in learning Cuda C. Has anyone here tried it? How good a hardware rig do you need?
Tank · 2017-05-10 06:43
I'm working on developing a machine code development environment; it's reasonably unlike anything I've ever seen or read of. I've a website, so I'll link to it in this thread, when I finish it.
>>1033
>wow, i wasnt expecting this thread to be empty.
I was too busy working on my project.
Roger Pollack · 2017-05-10 06:47
Assorted gamedev and gfx stuff.
Its an utter pain.
Spike Spiegel · 2017-05-10 08:30
>>934
I'm working on the projects listed here:
https://lainchan.jp/%CE%BC/res/32.html
Most notably I just started https://lain.city
FILLER · 2017-05-10 15:22
>>786
Difficult to tell without seeing the rest of the code. Does it stop posting notifications after a certain time period or after a certain amount of messages received? Do you have any debugging active while the daemon is running to watch what it is doing?
Knuth · 2017-05-10 21:51
I've been working on a programming language / compiler for the past few months. It's pretty much just C++ with a GC but currently only the C features work, I wish I was more creative. It currently works for a few simple programs. I've been taking a break from programming for about a month though and haven't really felt like working on it.
Recently been thinking about starting work on a computer algebra system as well. I wouldn't abandon the language but I want to start a new project...
Mitnick · 2017-05-11 02:30
>>1059
>It's pretty much just C++ with a GC
Eh, what can I say, I don't want to be rude but it doesn't sound exciting at all.
Some anon recently, somewhere, said that C++ would be much better if it hadn't been originally basedn on C, and I completely agree.
But it's great that you are working on stufff, keep it up. I've always been too intimidated to make a compiler and design a language.
Nobody special · 2017-05-11 06:04
I have multiple projects going on. Some are dumb proofs of concepts, like implementing coroutines or currying in C, others are things that I would find useful, like a ttrss implementation in go or adding vi operators to zsh.
>>1033
> i want to fix up MPDroid so that it actually is able to stream music from my mpd server
It already works. If you can't do it, there's a problem with your conf.
Donna Hawthorne · 2017-05-11 07:45
I am just about done wrapping up my string library I wrote for C: https://github.com/toddgaunt/libstx
All that needs to be finished are the man pages and a few more tests.
After than I plan on making a new programming language with LLVM. It is a lisp/C hybrid that looks like so:
(use io)
(define (main (argv #str) void)
(let ((a u8 10) (b u8 20) (c *file) (F 10#u8 (1 2 3 4 5 6 7 8 9)))
(map (\ ((x *u8) void) ((set (* x) (+ (* x) 2)))) F)
(io:print "%s %uz" (* argv), (len F))
(set c (io:open "/path/to/file"))
(close c)
(exit 0)))
And the C equivalent would be:
C
int
main(int argc, char **argv)
{
uint8_t a = 10
uint8_t b = 20
FILE *c;
uint8_t F[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
c = a + b;
for (int i=0; i<10; ++i) {
F[i] += 2;
}
printf("%s %zu", *argv, (sizeof(F) / sizeof(*F)));
c = fopen("/path/to/file");
fclose(c);
exit(0);
}
Basically it is a typed lisp with pointers and manual memory management. The basic types are 'u8'-'u64' and 'i8'-'i64', usize, isize, bool, void, f32, f64, strC, str8, str16, and str32.
The special notation I want to address is the '#' character and the '\' character.
'#' is a "fat-pointer" aka a pointer that stores both the address and the number of contiguous elements owned by it after the first address. Say there is a "fat-pointer" named "foo". (* foo) is to dereference the contents, and (# foo) dereferences the stored length.
'\' is just notation stolen from haskell as a shorter way to declare a lambda.
Splicer · 2017-05-12 14:51
"Officially" (as in, if anyone in real life asks me) I'm learning about artificial language
processing, but actually I'm just (re)writing a program to keep track of porn.
It's very helpful to have a specific goal in mind.
The last version worked, but it wasn't very "usable," so as an experiment, I threw together
some CGI scripts so that I could use it from firefox. The weird part is, even though my mini-website
was ugly, clumsy, slow, and couldn't even use all of the features of the original program (web
development is *really* not my thing), it felt somehow more useful than before, as if I'd completely
rewritten the program instead of just slapping on some wrapper scripts.
I got two things from this:
1.) "Usable" apparently means that the program remembers what you're doing
and
2.) It makes some broad assumptions about where you're going to go from there
So with this in mind, the new version integrates some shockingly complicated-to-implement features that
actually do very little in practice, like macro expansion of tags (e.g. you can tell it to add "cat_(ears|tail)" to
add both "cat_ears" and "cat_tail" to some file).
Roger Pollack · 2017-05-12 15:58
>>786
I know it's pretty late for a reply, but there's no error handling for notify_notification_show in your code. You should check it's return value and provide it with a double pointer to an actual GError structure instead of NULL so you can find out if it's that function that's failing, and why.
Turner · 2017-05-12 17:33
>>1044
The notifications seem to stop after a certain amount of time. This is the first time I've use libnotify and it seems to be quite sparsely documented and I haven't had time yet to dig deeper into this issue. I hoped it might be a fairly common problem, but it doesn't seem to be.
Netrunner · 2017-05-12 17:38
>>1107
Yeah, I figured as much, but didn't find time yet, see >>1108
Neuromancer · 2017-05-15 01:50
>>1106
LOL I'm already picturing your TED talk
"The future of porn is metanarrative: the process of enjoying the porn has become its own journey. At StainLabs we're curating a selection of porn trained on YOUR behaviour : eye dilation, brain activity, shuddering, type of jerking motion, hopw much you hate yourself afterwards and project it onto image board posts... we're optimizing your experience to deliver the perfect masturbation session EVERY time.
emph · 2017-05-15 03:25
Writing code using weird Lisp (Racket) macros that involve a lot of unicode. I imagine that the code looks pretty alien to programmers used to non-Lisps. In fact, it doesn't even resemble Common Lisp or clojure.
Here's my typed lambda implementation:
(define-typed-syntax lam
[(_ (x:id) e) ⇐ (~→ A B ~!) ≫
[[x ≫ x- : A] ⊢ e ≫ e- ⇐ B]
--------
[⊢ (λ- (x-) e-)]]
[_ ⇐ (~not #f) ≫
--------
[≻ (chk #,this-syntax)]]
[(_ (x:id) e ~!) ≫
#:with α (make-exis)
#:with β (make-exis)
#:do [(context-push! #'α #'β #'(Marker α))]
[[x ≫ x- : α] ⊢ e ≫ e- ⇐ β]
#:do [(context-pop-until! (~Marker (~Exis= #'α)))]
--------
[⊢ (λ- (x-) e-) ⇒ (→ α β)]])
queue · 2017-05-15 12:07
>>1162
Nah m8, proper machine learning is still a few years off for me; this version is based on what I've learned so far about SAT solvers (tl;dr version: it will be able to roughly understand what a "cat girl" is in terms of other tags).
Unfortunately, it's getting pretty big, so I probably won't be done with this version before the year is out. I dream of a better world where everyone stops dumping whole *boorus into single zip files with half the tags missing.
Anonymous · 2017-05-15 17:01
>>1164
Interesting, however while it means some sort of mathematical correctness in the representative sense, I believe the amount of keyboard macros you have to configure/remember to use stuff like that might break my coding flow/pace.
Pulse · 2017-05-15 22:26
>>1164
It barely resembles lisp, it looks more like haskell, maybe embedded in scheme just because of the (define-typed-syntax ...) and (context-push! ...) and that sort of obvious sexprs.
However, it looks really nice, I wish I understood what's going on there.
All in all, racket looks really interesting. I might give it a try.
t · 2017-06-01 14:16
>>1025
>Touhou pong
Sounds pretty cool mate, are you hosting the project anywhere?
I've just finished off a program to visually edit dialogue graphs, store them as json files, and share flags between dialogue modules.
Hiro Protagonist · 2017-06-17 19:12
>>1070
How are you even going to implement the fat pointer.
Will you have a hash map with the array id and its length, or are you going to implement lexical scope and have with it local hash map of array id and length?
Special Agent Bob · 2017-06-18 00:36
>>785
>What are you working on?
Right now I'm writing up some zsh / python scripts to help me learn web dev.
>Post some code you are particularly proud of
One of my previous projects was an autonomous robot's vision module. Nothing I've worked on since has been as exciting or difficult to work on. It's funny to look back on, I never expected programming a robot to find colored rocks in a park would have so many problems attached to it. But in the end it worked! The vision code I wrote helped our robot find colored rocks in a park / world full of visual noise.
Here is the opencv c++ code (a lot of things i would do different now) that the robot used to identify colored rocks in a park, guide the robot to the target, and pick it up.
Video of program output https://youtu.be/x6Dsqha9JPM?t=34
#include "ObjectDetection.h"
using namespace cv;
using namespace std;
void ObjectDetection::setVariables(int addweight_whites_ , int addweight_blues_, int addweight_reds_,
int whiteMinArea_, int whiteErodeArea_,
int blueMinArea_, int blueErodeArea_)
{
addweight_whites = addweight_whites_;
addweight_blues = addweight_blues_;
addweight_reds = addweight_reds_;
whiteMinArea = whiteMinArea_;
whiteErodeArea = whiteErodeArea_;
blueMinArea = blueMinArea_;
blueErodeArea = blueErodeArea_;
}
Mat ObjectDetection::FindStuff(Mat& Input, bool showStitch){
Point np = Point(-1,-1);
vector <int> wa, ba, ra;
Robot_XY = np;
curr_wp = np;
curr_bp = np;
curr_rp = np;
currPoint = np;
string whiteStr = "white";
string blueStr = "blue";
string redStr = "red";
Mat Cache, getBlues, getReds, Objfound;
Scalar getWhitesColor = Scalar(255,255,255);
Scalar getBluesColor = Scalar(255,100,0);
Scalar getRedsColor = Scalar(0,100,255);
Objfound = Input.clone();
getBlues = Mat(Input.size(), Input.type());
Perform_ImgAdjust(Input, getBlues, getReds);
Cache = Perform_GetBlobWhite(Input, addweight_whites);
Perform_ErodeDilate(Cache, whiteErodeArea, whiteMinArea, getWhitesColor);
vector <Point> wpArray = Perform_Contours(Objfound, Cache, whiteMinArea, getWhitesColor, wa);
getBlues = Perform_GetBlobBlues(getBlues, addweight_blues);
Perform_ErodeDilate(getBlues, blueErodeArea, blueMinArea, getBluesColor);
vector <Point> bpArray = Perform_Contours(Objfound, getBlues, blueMinArea, getBluesColor, ba);
getReds = Perform_GetBlobReds(getReds, addweight_reds);
Perform_ErodeDilate(getReds, blueErodeArea, blueMinArea, getRedsColor);
vector <Point> rpArray = Perform_Contours(Objfound, getReds, blueMinArea, getRedsColor, ra);
SortFoundPoints(wpArray, bpArray, rpArray, wa, ba, ra);
Point currPoint = CheckThreePoints(curr_wp, curr_bp, curr_rp);
Robot_XY = CheckCurrPrev(currPoint, prevPoint, hitCount, hitCountlimit);
ApplyCrosshair(currPoint, Objfound);
Perform_UI(Objfound);
if (hitCount > hitCountlimit) {hitCount = hitCountlimit;}
else if (hitCount < 0) {hitCount = 0;}
if (dc > cl) {dc = cl;}
else if (dc < 0) {dc = 0;}
if (tc > cl) {tc = cl;}
else if (tc < 0) {tc = 0;}
if (Robot_XY.x <= 0 || Robot_XY.y <= 0){
Robot_XY = np;
}
ApplyMarker(curr_wp, whiteStr, getWhitesColor, wa, Objfound);
ApplyMarker(curr_bp, blueStr, getBluesColor, ba, Objfound);
ApplyMarker(curr_rp, redStr, getRedsColor, ra, Objfound);
ApplyString(Objfound, currPoint);
cout << " hits " << hitCount << " | " << wp_count << " " << bp_count << " " << rp_count << endl;
wa.clear();
ba.clear();
ra.clear();
wpArray.clear();
bpArray.clear();
rpArray.clear();
return Objfound;
}
[/code]
I'll post the definitions to the rest the functions if anyone wants.
word · 2017-06-18 01:39
>>1034
You can do cuda c with any nvidia card made in the last 4 years afaik.
Also, you might be interested in doing cuda c on nvidia jetson boards.
Sabo Engle · 2017-06-18 02:23
>>1034
If it's possible for the function to be accelerated by gpu chances are you will see an improvement in your out of the box gpu vs cpu
Unsigned · 2017-06-18 03:13
A simple porn clearner for reddit and imgur
https://gist.github.com/Alquimerico/a294431f18139eb24191b406b7da4f5b
I use this plugin to block in chrome
https://chrome.google.com/webstore/detail/block-site/eiimnmioipafcokbfikbljfdeojpcgbh
Cat Mother · 2017-06-22 22:10
>>1033
If you finish that Clover fork, be sure to put it on the play store, I'd be very interested!
dictionary · 2017-06-24 09:54
I just installed unity and Ill be having some fun trying to make some games during my vacation. After my vacation, ill start working with ruby on rails so i might check it out a little bit.
Sven · 2017-06-28 00:19
What are you working on?
Currently on a pokemon clone for a 16bit machine in C, it makes use of procedural audio, only the standard lib, and a hand full of plain text files. Started as a challenge but later turned into a tutorial, it covers the entire design process of the program while explaining my C abuse and why it's needed.
Does it serve a purpose or is it just for fun and practice?
Just for fun, have a friend interested in learning so giving it to him after.
Unsigned · 2017-07-11 00:25
Got bored, made up a program that implements an array using an n'th order polynomial.
Pretty terrible, only gets close to accurate for n < 12 or so
Splicer · 2017-07-11 01:35
set up a vpn, socks proxies, tor bridge,znc and an email server.
working on caldav / carddav for the email server.
think i'm going to make a tinytinyrss server next, though i'll miss newsbeuter.
feels great to be in charge of my own soykaf for once in my life.
Nell · 2017-07-19 21:28
Lately I've been writing all sorts of small programs with a cool C lib I found called "libmill", as well as experimenting with some stuff from libc I never gave an in depth look into. One of these programs I ended up using was a small pastebin clone:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <signal.h>
#include <setjmp.h>
#include <libmill.h>
#define tcpstr(S, STR) tcpsend(S, STR, sizeof(STR) - 1, -1)
static jmp_buf jmp;
static int jmp_true = 0;
static void catch_usr1(int signo)
{
jmp_true = 1;
longjmp(jmp, 0);
}
static void rand_chars(char *buf, size_t size, size_t n)
{
assert (n <= size);
bzero(buf, size);
int i, c, byte = 0;
FILE *fp = fopen("/dev/urandom", "r");
if (!fp)
return;
for (i = 1; i <= n; i++) {
do {
c = fgetc(fp);
} while (!isalnum(c));
buf[byte++] = c;
}
fclose(fp);
}
static coroutine void paste(tcpsock as)
{
char filename[4096], chars[7];
rand_chars(chars, sizeof(chars), 5);
snprintf(filename, sizeof(filename),
"/home/upload/p/%s.txt", chars);
char buf[20480]; // 20 kib
bzero(buf, sizeof(buf));
tcprecv(as, buf, sizeof(buf), now() + 3000); // 3 secs
if (strlen(buf) == 0) {
tcpstr(as, "error: nothing to send\n");
goto cleanup;
}
FILE *fp = fopen(filename, "w");
if (!fp) {
tcpstr(as, "error: couldn't upload file\n");
} else {
fprintf(fp, "%s", buf);
fclose(fp);
snprintf(filename, sizeof(filename),
"https://gandas.us.to/p/%s.txt\n", chars);
tcpsend(as, filename, strlen(filename), -1);
}
cleanup:
tcpflush(as, -1);
tcpclose(as);
}
int main(void)
{
ipaddr addr = iplocal(NULL, 6969, 0);
tcpsock ls = tcplisten(addr, -1);
if (!ls) {
perror("fatal: failed to open listening socket");
return 1;
}
if (signal(SIGUSR1, catch_usr1) == SIG_ERR) {
perror("fatal: couldn't install SIGUSR1 handler");
return 1;
}
tcpsock as;
setjmp(jmp);
while (!jmp_true) {
as = tcpaccept(ls, -1);
if (!as)
continue;
go (paste(as));
}
tcpclose(ls);
return 0;
}
Hong, Guil Dong · 2017-08-03 07:23
Writing a bot in py3 to manage my mini NAS server. I only just got back into programming so I'm working on this with the intent to have something that will add a little bit of pride to my daily life.
Planned features:
- automatically back up downloads to NAS
- sort files into folders based on type (image, pdf, animated gif, video w/ sound, text, music, etc.)
- mass file download, upload and autonaming by using arguments for keyword and quantity (e.g. Shinkai_wall_15, glitch_gif_7, etc.)
- provide user interface so my non-tech roommates and any visitors won't accidentally fuarrrk up everything on my NAS
- text-based manual storage and browsing
- notify me by email/SMS when specific files or folders are accessed
Even though it'll have productive use, it's mostly for practice and improvement - I highly doubt it'll be much more efficient than standard filebrowsers unless users are running a command line interface. But I thought it would be a neat little ongoing project, and I would vastly prefer something I'd done myself. Oh, and it's based off the Superintendent AI from Halo: ODST, complete with specific emotes for whether it's on standby, initializing an action, completed an action, encountered an error, or querying the user.
Sadly not sharing the code because all I have right now is the beginnings of the user interface, literally just accepting input and outputting situational text. But even if it's slow going, I'm still making progress!
Just another Random Lainon · 2017-08-03 18:10
Playing with my friend's visual novel engine, hoping to make something entertaining and to also help him improve it at the same time.
Just another Random Lainon · 2017-08-08 19:49
>>785
I wanted to practice some Go, and since I noticed there are tools for manipulating images in the standard library, I decided to make a program that converts images to ASCII art. Its main goal is to write them straight to the terminal, but I'm planning to add more output modes so that it's possible to use it on chans and forums that support constant width fonts and colored text. On terminals, colored output is achieved through ANSI escape sequences. I'm quite pleased with the results so far.
John Doe · 2017-08-08 20:54
>>2841
wow that's way better output than libcaca can do.
Did you use the methods that were posted in the lainzine?
Unidentified · 2017-08-08 23:15
>>2841
really nice, lainon. makes me want to make a BBS chan with ASCII images.
Fred Nurk · 2017-08-08 23:19
Ive been fuarrrking with go a bit and have most of a password-store web ui. Its probably not a very good idea but w/e i just need to make a the frontend bit.
Other than that ive been doing hacker rack questions as i hate my self. I also kinda want to write some stuff in C not sure what yet tho.
Acid Burn · 2017-08-09 07:37
>>2843
No, those were for structure-based ASCII art, what I'm doing is completely tone based. The algorithm is probably much simpler than what's used in libcaca too, there is no dithering for instance. The lack of dithering makes the results more smooth in my opinion, but I think it looks good mainly because it uses a bit higher resolution and anti-aliased font of my terminal.
John Peters, You Know, The Farmer · 2017-08-13 00:59
Currently trying to implement a polynomial using a linked list in C, but am somehow getting seg faults.
Here's the node:
struct Node
{
int Coefficient;
int Exponent;
PtrToNode Next;
};
typedef struct Node* PtrToNode;
typedef struct Node* Polynomial;
And here's the method that has the seg fault in it:
void
InsertIntoPolynomial(Polynomial Poly, int Exp, int Coeff)
{
int curr_exp, next_exp;
PtrToNode Temp;
struct Node* toInsert;
printf("Starting to insert...\n");
/* Allocates enough space for one new entry in the polynomial */
toInsert = (struct Node*) malloc( sizeof(struct Node) );
/* Initializes fields we know enough about to initialize */
toInsert-> Coefficient = Coeff;
toInsert-> Exponent = Exp;
toInsert-> Next = NULL;
printf("Printing coefficient: %d\n", toInsert->Coefficient);
printf("Printing soykaf: %d \n", Poly->Next);
/* Nothing in the polynomial */
if(Poly->Next == NULL)
{/* Insert the polynomial into the header and quit method */
printf("Test");
Poly->Next = toInsert; return;
}
PtrToNode Iterator = Poly->Next; /* Iterator points to the first
entry in the polynomial now */
/* Inserting exponent is greater than the current largest exponent */
if(Exp > Iterator->Exponent)
{
printf("Test2");
Poly->Next = toInsert;
toInsert->Next = Iterator;
return;
}
/* Otherwise... */
while(Iterator->Next != NULL)
{
/* No problems here (yet */
}
/* If you didn't find somewhere to insert the power of x,
insert it at the end
*/
Iterator->Next = toInsert;
}
int main()
{
Polynomial p;
Initialize(p);
printf("Address of p: %d\n", p);
InsertIntoPolynomial(p, 10, 50); /* Leads to seg. fault */
}
Attached is the output. Is there anything that immediately jumps out as a source of the seg fault?
Thanks in advance
藤原純一 · 2017-08-13 02:11
>>2905
That's rather convoluted. What does Initialize() do?
John Peters, You Know, The Farmer · 2017-08-13 02:13
>>2907
My bad... Should have included it
Initialize is below
void Initialize(Polynomial p)
{
p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);
}
Something I noticed is that p->Next changes values during and after it's in Initialize(p)
> convoluted
Dang... That's the opposite of what I was going for. Any suggestions for style?
John Peters, You Know, The Farmer · 2017-08-13 02:32
>>2907
Found the error: I didn't realize that I was assigning the malloc call to a copy of the Node* I passed in. I fixed it by passing in a Polynomial* into the function (though passing by reference would have worked as well)
Now it's time to implement addition!
Zero Cool · 2017-08-13 09:45
>>2908
>Any suggestions for style?
The function you posted is pretty big for something that's just supposed to construct a list. Doesn't look to me like you need to sort them.
These are some macros that I've written recently for a generic linked list.
#define LIST(t, name) \
struct name##_cons_t { \
t car; \
struct name##_cons_t *cdr; \
}; \
\
struct name##_cons_t* name##_cons(t el, struct name##_cons_t *rest) { \
struct name##_cons_t *tmp = (struct name##_cons_t*)calloc(1, sizeof(struct name##_cons_t)); \
tmp->car = el; \
tmp->cdr = rest; \
return tmp; \
}
#define list_iter(t, var, head) for (t *var = head; var != NULL; var = var->cdr) For example, your program could be implemented like this.
struct polynomial {
int coefficient;
int exponent;
};
LIST(struct polynomial, polynomial);
struct polynomial_cons_t *p;
int main(void) {
p = polynomial_cons((struct polynomial){10, 50},
polynomial_cons((struct polynomial){5, 14},
polynomial_cons((struct polynomial){1, 17},
polynomial_cons((struct polynomial){5, 19}, NULL))));
list_iter (struct polynomial_cons_t, it, p) {
printf("%d * x^%d + ", it->car.coefficient, it->car.exponent);
}
puts("0");
return 0;
} I'm certainly no C expert though, this is just the way I would've done it. If you want to look at the generated C code, try using "cpp" to run the preprocessor first.
Dujour · 2017-08-15 04:43
What are you working on?
www.mezchan.com
Creating a chan site from the ground. Its functional but still early days. It uses Cassandra as a db and strips metadata from most media. Trying to focus on flexibility so i can eventually add more features. First place im posting about it heh
Roger Pollack · 2017-08-15 18:26
>>2937
Why are you using Cassandra?
list · 2017-08-16 00:12
>>2943 I had already written some wrappers and i've never found the performance anything but great. For instance media is normally streamed from rows in a blobs table.. unless cached.
Dr. X · 2017-08-16 20:04
I'm doing a practical exercise; I'm working on implementing the algorithms from an AI textbook.
Moore · 2017-08-17 11:43
I'm working on improvements on a Discord plugin for Weechat ( https://github.com/khyperia/weechat-discord ).
I've had to learn Rust for the purpose. It's being a fun ride.
Joey · 2017-09-22 07:43
I've made a program to print the discrete approximations of Hilbert curve in ASCII last night. The output looks like this:
$ ./hilbert 2
,-.
| |
| |
$ ./hilbert 4
,-. ,-.
| | | |
| `-' |
| |
`-. ,-'
| |
--' `--
$ ./hilbert 8
,-. ,-. ,-. ,-.
| | | | | | | |
| `-' | | `-' |
| | | |
`-. ,-' `-. ,-'
| | | |
,-' `-----' `-.
| |
| ,---. ,---. |
| | | | | |
`-' ,-' `-. `-'
| |
,-. `-. ,-' ,-.
| | | | | |
| `---' `---' |
$ ./hilbert 16
,-. ,-. ,-. ,-. ,-. ,-. ,-. ,-.
| | | | | | | | | | | | | | | |
| `-' | | `-' | | `-' | | `-' |
| | | | | | | |
`-. ,-' `-. ,-' `-. ,-' `-. ,-'
| | | | | | | |
,-' `-----' `-. ,-' `-----' `-.
| | | |
| ,---. ,---. | | ,---. ,---. |
| | | | | | | | | | | |
`-' ,-' `-. `-' `-' ,-' `-. `-'
| | | |
,-. `-. ,-' ,-. ,-. `-. ,-' ,-.
| | | | | | | | | | | |
| `---' `---' `-' `---' `---' |
| |
`-. ,---. ,---. ,---. ,---. ,-'
| | | | | | | | | |
,-' `-. `-' ,-' `-. `-' ,-' `-.
| | | | | |
| ,-. | ,-. `-. ,-' ,-. | ,-. |
| | | | | | | | | | | | | |
`-' `-' | `---' `---' | `-' `-'
| |
,-. ,-. | ,---. ,---. | ,-. ,-.
| | | | | | | | | | | | | |
| `-' | `-' ,-' `-. `-' | `-' |
| | | | | |
`-. ,-' ,-. `-. ,-' ,-. `-. ,-'
| | | | | | | | | |
--' `---' `---' `---' `---' `--
Meddler · 2017-09-22 07:56
Trying to learn socket programming on linux wrote a server + a client capable of transporting a file from the server to the client now I am trying to make a RAT with linux client and wingdows server not expecting to infect the world with this but having a starting point if I do decide to make a rat is good.
H.R. Giger · 2017-09-22 10:32
>>3636
Why aren't you taking the log2 as argument?
Tyrell Wellick · 2017-09-22 10:50
>>3647
Hadn't really crossed my mind, but thank you, it's a good idea. I'll modify the program accordingly. Right now it just prints an error message if the argument is not a power of two with positive exponent.
dictionary · 2017-09-22 12:25
I'm trying to learn Discrete Math so I can understand and consummate Intro to Algorithms. I then want to make a data structure library in C. In the meantime I'm suffering through the boredom that is front-end webdev of a "theme" website.
>>2847
That sounds like a really fun idea.
cdr · 2017-09-22 14:49
>>3650
You can definitely write a data structure in C without discrete math. Discrete math is mostly used for proving correctness of your algoritms, but if you're using something popular like merge sort then you're probably fine.
Make a linked list if you've never done one in C before, or if you have, try out a skip list, those are always fun
null · 2017-09-22 17:09
>>3651
I've made a linked list before (like every other schmuck), but a skip list seems like a good time. Thanks, lainon.
I'm still going to learn discrete math so when I build more complex algorithms, I can ensure they're not producing incorrect results.
Anonymous · 2017-09-24 14:11
a knowledge base for all positive knowledge that exists in the world
Hououin Kyouma · 2017-09-27 01:03
Just finished a small bash-script to manage your todo/done-lists. (source code : https://github.com/ilzichio/todo-script), gif is the script in action
After you delete tasks with "del", they automatically append to your done-list, which can be viewed by typing "bash todo.sh done"
Jean Dupont · 2017-09-27 16:16
>>1169
Do you have a link to a github repo? I probably wouldn't be much help, but it sounds like a cool project and I'd be interested in seeing the code
fsociety · 2017-09-28 03:22
>>3769
Thats awesome! I recently started (over) a project very similar but in C.
Emmanuel · 2017-09-30 11:48
I finished a script that deletes all .ovpn files in current directory, goes to vpngate.net and downloads a random one and then connects to it using openvpn.
Now I'm focused on a small website that gets an Instagram's user most recent posts and posts them in my website.
>>3769
This is pretty cool! I was thinking in doing something like this for a Python bot but it's not a priority now.
Linda Lee · 2017-11-01 14:12
>>3789
No repo, sorry. I'm usually pretty disorganized, but I think this project holds the record for "most schizophrenic" to date.
There are three different, incompatible versions right now (in JavaScript, C, and bash), so I probably won't share until I have this mess sorted out.
If you're interested, though, here's the last version:
> https://myfile.org/y9U1P3c8ba/tm7.tar.gz
Building it requires an inhuman amount of patience, pmake, and OpenSSL (or GNU TLS, if you prefer).
Incognito · 2017-11-01 19:28
https://github.com/rlt3/lua-with-macros
I've been working on adding macros to Lua. About to start on reader macros today. I started this project to get my four pull requests for the free Hacktoberfest t-shirt but I've been having too much fun. I planned to stop after having simple C-like define macros. After reader macros I can't think of any features that wouldn't simply be improvements, so that'll be a good place to end the project anyway.
if · 2017-11-04 10:34
I'm going to build my own development environment.
I'll study the source code of diff, tr, sed, virtualenv...
And rewrite those in a way I can use.
In fact the goal is to be able to create a bubble for each programming language I use. A place in my home directory where I'm sure nothing will be fuarrrking around with the system.
And output stuff like: standalone binaries. With fuarrrking embedded dependencies.
And I'm gonna have a web scraper that monitors for new updates of dependencies.
But I'm still thinking about it. I want to end up with the most simple platform for programming.
let · 2017-11-10 05:30
>>2841
That looks sweet, even better than that bootleg android app
John Peters, You Know, The Farmer · 2017-11-11 04:39
I really want to get several projects off the ground for once:
I have two ideas atm I want to implement:
Text Editor for Haskell
-I really want to make a GUI application, and this seems like a project of decent size.
-Some features I want to include are syntax highlighting, basic customization options, and several emacs features, like multiple windows and keybindings. I plan on writing it in either C or C++ as I'm most comfortable with those two.
Calculator (TI-84 Style)
-I often find myself needing a calculator, and really don't like the online scientific calculators .
-Desmos is fine for graphing, but I would really like to be able to plot diff eq's and other cool stuff
-To challenge myself further, I'll probably try to do stuff like implement fixed-point addition, scientific notation, graphing solutions to differential equations, and unit conversion
I think I'l implement the text editor first, and I'm currently going through this tutorial:
https://viewsourcecode.org/snaptoken/kilo/index.html
as I'm finding it to be a decent introduction to capturing some of the quirks that come with text-editing (like disabling commands such as C-c, C-v, and so on).
If anyone has any resources on building text editors, I would love to have them! Specifically, I'd like to be able to have my text editor by lightweight, but effective at processing large files. Any little bit helps!
Boris Grishenko · 2017-11-23 13:53
>>2841
You reminded of one talk I watched not so long ago:
SIGGRAPH 2010 Presentation: Structure-Based ASCII Art
https://www.youtube.com/watch?v=dBMf14KGgIg
() · 2017-12-15 04:50
Trying to make an anonymous social network where people can create groups, post images/webms and can integrate with bots possibly written in Lua or Perl (for data mining and moderation)
Using C++ with restbed to make the server I prefer C but the framework is too good. I don't think the project is complete enough to post here
It is supposed to be a revival of a closed non free social network called Candid I am still in contact with some of the old users and they might start using my project if I make a pretty enough android client for it
As my first big project the program's structure is a mess my biggest regret is putting a global gSet structure (which stores all the settings) inside a class now I have to get an instance of the singleton class then do this whenever I want to get a setting inst->gSet.home.c_str()
J.C. Denton · 2017-12-15 14:01
Made a helpful log function in C for large projects. This will log the file name and line number from where the log message came from.
C
#include <stdio.h>
#include <stdarg.h>
void print_log(const char *file, unsigned int line, const char *format, ...);
#define log(msg, ...) print_log(__FILE__, __LINE__, msg, ## __VA_ARGS__)
void print_log(const char *file, unsigned int line, const char *format, ...)
{
char buffer[1024];
va_list args; //list to store additional parameters
va_start(args, format); //store parameters after 'format' variable
vsprintf(buffer, format, args);
printf("|f:%s|l:%04d|%s\n", file, line, buffer);
va_end(args); //clean up
}
int main()
{
log("HELLO WORLD!");
log("%s %s", "HELLO", "WORLD");
return 0;
}
Judge Fang · 2017-12-15 21:04
>>5681
I spy with my little eye a buffer overflow. Use vsnprintf() or vasprintf().
Spike Spiegel · 2017-12-16 17:00
>>5691
>buffer overflow
It depends what I will pass as a argument, but yeah I should change it as it won't force me to complicate this function in any way.
cond · 2017-12-19 20:03
>>5681
why not do it like this?
#define log(msg, ...) printf("|f:%s|l:%04d| " msg "\n", __FILE__, __LINE__, ## __VA_ARGS__) seems a bit less convoluted
nil · 2017-12-20 12:58
>>5765
Well my version allows me to change/expand the way I log the message in a easy way, like write the log to a file and not STDOUT (or even send the message in a TCP/IP stream using sockets). Sure I could also do the same thing in a muli line define but I prefer to enclose it in a function call. I guessing it’s a matter of preferences.
Anonymous · 2017-12-20 16:00
>>5769
true, also your version can use strings that are not literals in the sourcecode, which would be a rather unnecessary restriction
Cutter · 2017-12-22 21:38
>>5769
dprintf or fprintf would let you log wherever you like.
>>5770
I'm not sure I understand what you mean. Could you provide an example?
Hagbard Celine · 2017-12-23 10:46
>>5797
Say you wanted a program that can print its messages in different languages, you could for example choose a format string dynamically depending on language settings. Since the automatic string concatenation in >>5765 only works on literals, that wouldn't work
Nguoi La · 2017-12-23 15:45
One of my contacts set up an Excel spreadsheet with analytics for his business and now wants to turn it into a proper application. He told me the Excel sheet does things big companies buy SAP licenses for.
Does anyone know what he could be referring to? I'm familiar with some of Excel's financial functions but honestly I don't understand this domain very well. I don't want to get into something that's way over my head.
Zero Cool · 2017-12-23 20:06
>>5806
>Does anyone know what he could be referring to?
It sounds like someone wrote a bunch of macros in Visual Basic for Applications.
>One of my contacts set up an Excel spreadsheet with analytics for his business and now wants to turn it into a proper application.
How does the rest of the company feel? If the workers have been using a spreadsheet for years and it's working fine then getting them to switch to something else will flop. Make sure it will fix a specific problem andadd value to the company, not just make the boss happy.
[spoiler]On the other hand if you have no stake in the success of the company and are just doing this as a kind of contractor then creating dumb useless soykaf to make the boss happy might be the best path for you.[/code]
null · 2017-12-24 12:22
>>1162
>how much you hate yourself afterwards
I honestly don't understand this meme. Are there really people who hate themselves after fapping or is it indeed a meme?
I mean, if you don't feel satisfied and relaxed afterwards, why do it? It's like saying you would hate yourself after eating. That's a mental disorder.
Aristóteles Amadópulus · 2017-12-25 20:11
>>5808
Yeah I'm an independent contractor in this context. I'm not sure how big his company is or whether his employees rely on familiar Excel workflows. I'm sure there are libraries out there that can extract data from Excel files so I can make it work if required.
It seems he just wants a prettier interface on top of the whole thing. I told him I'm not good at designing graphical interfaces but I could handle the back end. I thought about using a database for the business data with a schema based on the spreadsheet, Python programs to calculate whatever business information is required and a web API that serves the information as JSON so that a front-end developer can easily get all business analytics data and render it however he wants.
I haven't actually started working on this though. He said he'd get back to me and hasn't contacted me yet. If we decide to move forward with this, I'll post my progress here. Merry christmas.
HELIOS · 2017-12-25 20:59
First time looking at Ruby and I'd like to reimplement this in it
https://gist.github.com/anonymous/57e98d1dc695d10792e1c9a067271a3d
As far as I understand it could pretty much go 1 for 1, with some differences in syntax.
Is there anything I should be aware of before I start?
I understand, for instance, that for Luna in Ruby you need to do intervals in separate threads?
Also understand that if you were to scale the number of tasks running in intervals you'd have to spawn a thread for each task which seems bloaty?
Would it be better to appoint blocks/callbacks to Luna along with their intervals;
then with a single thread run any block/callback eligible for a run?
⍕ · 2017-12-27 17:23
>>5841
https://github.com/looca1/chunker
Done and done. To answer my own question, yes, spawning only one 'hook' thread which runs callbacks is probably better.
Also realized that you likely gain a little bit of a boost by separating callbacks and the checkup of their intervals;
because you only have to look through a single array of integers instead of properties of a key => val object containing both a closure and its interval.
Cat Mother · 2017-12-29 17:29
>>5878
reuploaded
had an embarrassing overwriting issue, fixed it and some other stuff once I had time for it
it's a cool little thing, actually used it while working ON IT lol
Y.T · 2017-12-29 17:38
>>5814
Leftover religious guilt plus alt-right chan-tard propaganda telling them that masturbation is unmanly.
Turing · 2017-12-29 22:33
>>5841
>>5878
>>5921
Good job.
t · 2017-12-30 10:54
>>5927
thanks
hope it's useful
Joe Bloggs · 2017-12-31 09:04
currently working on a raytracer
going to be taking a class on computer graphics next semester but I thought I might fuarrrk around with it now
it is super slow and parsing .nff files is annoying
its a fun winter project for a brainlet like myself
Liet Kynes · 2017-12-31 09:25
>>785
I'm trying to put together my own imageboard, just for fun and to see if I can succeed.
I want it to work like this:
Thread is a folder with the Thread number, in the folder is the thread html, xml(stores the posts) and another folder for content uploaded to that thread.
I am going to avoid using javascript, any tips?
Also I'd like to use python with it as well...
Lord Nikon · 2017-12-31 12:37
>>5938
>I am going to avoid using javascript, any tips?
Make the basic functionality available without JS and allow posting without verification nonsense, and you have a solid start.
Splicer · 2017-12-31 12:40
>>5938
>any tips?
Don't pay attention to technologies.
As long as they are efficient use them like you would any other tool.
The color of a hammer's handle should never matter.
Dozer · 2017-12-31 20:08
>>5938
Are you using the file system as the database? That's pretty cool. Why XML though? I think JSON is going to result in a much cleaner schema; just because you're avoiding Javascript doesn't mean you should avoid JSON as well.
I'd model the imageboard as a collection of boards, which are a collection of threads, which are a collection of posts.
Tomohisa "Tom" Kanezaki · 2018-01-27 09:43
I have a sequence of sorted integers and I'm looking for the best way to find the greatest one that's lower or equal to a query term. What do?
Of course one way is a binary search, but is there any reasonable (preferably succinct) data structure or algorithm that allows to solve in O(1) time? The sequence is static.
Iverson · 2018-01-27 10:49
>>6426
>What do?
https://docs.python.org/3/library/bisect.html#searching-sorted-lists
>O(1) time?
Not in the general case because insertion sort would become linear in the number of comparisons.
Zhora · 2018-01-27 14:10
>>6427
In the general case I could have, say, a precomputed table mapping all possible arguments (lower than min of the sequence, middle values, higher than max) to the corresponding sequence element. The key is that the sequence is static and I can precompute some indexing to help at query time. My issue is what sort of indexing to use (a table like that would be colossal).
Thanks tho :-)
The Oracle · 2018-01-27 14:45
>>6428
>In the general case
>mapping all possible arguments
This is a contradiction. A general case algorithm has to work on arguments which form an arbitrary set, e.g. uncountable. As soon as you go with "all possible arguments" you've given up on the general case.
>to the corresponding sequence element
This is simply memoization and can be applied to an arbitrary pure function. It won't magically change the underlying lookup to O(1).
let · 2018-01-27 16:19
>>6430
>general case
Indeed you can assume the sequence is finite. Should have mentioned that before, sorry.
And I'm fine with a preprocessing step in arbitrary complexity, I only need to do quick lookups, not to modify the sequence after I've indexed it once.
In fact the insertion sort argument (if I got it right) implies querying in O(1), inserting (again in constant time), then being able to immediately query again in O(1), which is not the case I mean.
dictionary · 2018-01-27 21:48
>>6432
>I'm fine with a preprocessing step in arbitrary complexity, I only need to do quick lookups
A memoizing cache will keep the original cost of the first use of an argument, but will give you amortized O(1) over a sufficiently large number of repeats of the same argument.
https://docs.python.org/3/library/functools.html#functools.lru_cache
Gyula Kovacs · 2018-01-28 05:02
>>6432
You can use a lookup table. An element of the lookup table would point to an index in the sorted array, which contains the number that is lower or equal to the query.
John Doe · 2018-01-28 05:06
>>6447
Alternatively, you might be able to molest the union-find data structure enough to do this but only in near constant time.
nibble · 2018-01-28 13:58
>>6438
Caching would make sense.
>>6448
This is a good idea. Thanks lains.
setq · 2018-01-28 22:25
>>6448
Union-find operates on nodes with fields, it doesn't concern itself with the step of going from a value to the node holding that value field.
z. · 2018-02-04 14:52
>>785
I am currently practicing docker-compose by packaging a simple application I wrote as a Docker container, deployable with docker compose.
Next step is docker swarm, in order to set up a small cluster at home.
Yamaoto Toshi · 2018-02-04 17:56
GTPv2 decoder/encoder.