randy newfield

1

votes
2

answer
2.3k

views

Incrementing pointers of pointers

I'm trying to figure out how i would go about incrementing a pointer of pointers to point at a value i want. This is essentially an array of pointers to cstrings and i want to increment the pointer to point at xx pointer. For insistence in my current application if i want to point at the fifth point...
randy newfield
1

votes
3

answer
91

views

string literals/escapes

I am wondering if there is some sort of string prefix so that the cstring is taken as is without the need of my escaping all the characters. I am not 100% sure. I remember something about prefixing the string with the @ symbol ( char str[] = @"some\text\here"; ) and you would not need to escape any...
randy newfield
3

votes
1

answer
1.8k

views

How to split a range into N parts

I am wondering how to split a range into N parts in ruby, While adding them to a hash with a zero based value for each range generated. For example: range = 1..60 p split(range, 4) #=> {1..15 => 0, 16..30 => 1, 31..45 => 2, 46..60 => 3} I've read How to return a part of an array in Ruby? for how to...
randy newfield
2

votes
3

answer
2.7k

views

How to run multiline bash commands as sudo

I am trying to launch an application that needs many switches in order to operate so I have multi lined them using the \ operator. Now I need to run this application as well as some exports to be ran as another user. What I am currently attempting to do is sudo -u user bash
randy newfield
4

votes
1

answer
6.7k

views

static compile of libcurl apps linux C (missing library)

//to-long-didnt-read -> missing lgssapi_krb5 library and can't seem to find it i am having trouble statically linking libcurl using one of they're test applications. ive read forums and someone said issue the "curl-config --libs" command and include all those libraries, but the command only returns...
randy newfield
2

votes
1

answer
788

views

Dynamic port forwarding libssh C

I am looking for a solution/way to implement the dynamic port forwarding functions built into ssh (also known as the -D option). I have been reading for the last day, and I can't seem to find a reliable library to aid in this. I found ssh.net which is a C# library, but its dynamic port forwarding is...
randy newfield
2

votes
3

answer
862

views

Mapping array values to hash with incrementing key name

I have an array of strings that are hex color codes like so: ["#121427", "#291833", "#4B2E4D", "#5D072F", "#BB2344", "#ED9F90"] and I want to convert them into a hash with distinct key name where there is a distinct name "color" and then a integer value which increments as it transverses the array a...
randy newfield
2

votes
1

answer
332

views

Self made ruby timer inside thread

I am attempting to create a session timeout system for a client/server networking project. What happens is the client connects and as it authenticates the server creates a session object that holds the timeout, the session id, and a thread handle. From here the client sends a keep alive packet every...
randy newfield
4

votes
2

answer
276

views

Split an array of strings into an array of arrays of strings

I am looking for a way to split this array of strings: ["this", "is", "a", "test", ".", "I", "wonder", "if", "I", "can", "parse", "this", "text", "?", "Without", "any", "errors", "!"] into groups terminated by a punctuation: [ ["this", "is", "a", "test", "."], ["I", "wonder", "if", "I", "can", "pars...
randy newfield
2

votes
1

answer
74

views

variable is a substring of variable bash

I am trying to see if a user entered input is contained in a space delimited list. interfaces=`ls /sys/class/net | awk '{ ORS=" "; print; }'` # Loop until valid input for interface is received while [[ -z "$interface" || ! "$interfaces" =~ "$interface" ]] do echo -n "Select the interface ( "$interfa...
randy newfield
3

votes
5

answer
10.2k

views

POSIX threads and global variables in C on Linux

If I have two threads and one global variable (one thread constantly loops to read the variable; the other constantly loops to write to it) would anything happen that shouldn't? (ex: exceptions, errors). If it, does what is a way to prevent this. I was reading about mutex locks and that they allow e...
randy newfield
2

votes
1

answer
744

views

Ruby mechanize clicking divs

I'm trying to search a page for divs containing a specific class and then click on them. Each of these divs containing the class have a onclick event on them. My current code looks like so, home_page = agent.get('http://mysite.com') home_page.search(".//div[@class='arrow up']").each do |i| i.click...
randy newfield
3

votes
2

answer
2.2k

views

C Linux Bandwidth Throttling of Application

What are some ways I can try to throttle back a send/sendto() function inside a loop. I am creating a port scanner for my network and I tried two methods but they only seem to work locally (they work when I test them on my home machine but when I try to test them on another machine it doesn't want t...
randy newfield
6

votes
1

answer
4.3k

views

Size of class in bytes

Is there a method to see the size of allocated memory for a class in ruby? I have built a custom class and I would like to know its size in memory. So is there a function with the likeness of sizeof() in C? I am simply trying to initialize a new class like so test = MyClass.new and trying to find a...
randy newfield
2

votes
0

answer
68

views

How to get answers to natural language questions from freebase?

I have massive amounts of natural language questions in the format of "Subject-entity [tab] relationship [tab] Object-entity [tab] question" as follows: www.freebase.com/m/01jp8ww www.freebase.com/music/album/genre www.freebase.com/m/01qzt1 Which genre of album is harder.....faster? www.freebas...
randy newfield
3

votes
1

answer
121

views

Spawn vs Select for socket handling in Crystal

Which would preform better for handling many socket connections in Crystal? Spawning a new fiber for each connection passing it the accepted socket object. This would allow the built in async IO handler to switch context between sockets when new data is available to be read. Implementing a standard...
randy newfield
2

votes
0

answer
47

views

Fine resolution delays

Is there a better method than sleep in Ruby to implement fine/high resolution delays? I am wanting to implement the DHT11 sensor protocol in pure ruby and I can not get consistent delays with the native sleep method. The delays in question are as high as 20 milliseconds down to 40 microseconds. To t...
randy newfield
2

votes
1

answer
2.1k

views

Joining array of strings into a quoted comma-separated list

If I have a array of strings like so: arr = ["one", "two", "three"] How would I convert it into a backtick-quoted comma-separated string like so: "`one`, `two`, `three`" I have accomplished it using three calls like so: arr = arr.join "`, `" arr = arr.prepend "`" arr = arr += "`" but I was wondering...
randy newfield
1

votes
2

answer
12k

views

pthread_kill doesnt kill thread C linux

i am making a small project which will be incorporated into larger project. basically what it does is keeps track of threads that are created by way of adding them to a main struct which keeps track of what the thread does (its main function) and its pthread_t id. the other struct keeps track of the...
randy newfield
6

votes
2

answer
17.7k

views

Allow ssh incoming/outgoing and blocking all outgoing besides specific ports

I am trying to create iptable rules that will allow incoming and outgoing ssh connections, and then allow outbound connections to specific ports, then finally drop anything that doesnt match. These are the rules I have come up with, the SSH rules work, but when I tunnel into the box I cant seem to a...
randy newfield
2

votes
1

answer
188

views

Timers and Sleep on windows

I am trying to port some linux code that uses nanosleep() and get_clocktime() to windows. As far as I have read there really isn't that many performance timers on windows and there are no real sleep functions other than Sleep(). I found QueryPerformanceCounter and QueryPerformanceFrequency on window...
randy newfield
3

votes
2

answer
177

views

Freeing pointers

This is just a general question, but for example on windows, if i create a pointer to a hostent struct to use with gethostbyname() do i have to dealocate memory of that pointer or is it handled for me. I am under the assumption that since I did not specifically call malloc on it that it is not my jo...
randy newfield
5

votes
1

answer
4.6k

views

passing structs to functions as void pointers

I'm trying to pass a pointer of a struct to a function but when I try to access the struct the last variable inside the struct is missing 1 byte off its memory address causing anything using that variable to segfault. typedef struct { pthread_t tID; int tType; }sThread; sThread threads[MAX_THREADS];...
randy newfield