A function (also called a procedure, method, subroutine, or routine) is a portion of code intended to carry out a single, specific task.
2
votes
1answer
67 views
Single function to read one, read all, or set
I have the below function, it is designed so I can call:
$object->temp('one', 1); //add the key `one` to the temp array with value 1
$object->temp('two', 2); //add the key `two` to the ...
0
votes
2answers
73 views
Refactoring functions that generate string with random letters, numbers or mixed chars?
The bellow functions are used to generate a string with random characters, and they have a parameter to specify the string length.
The string can be composed of letters, numbers or a conjunction of ...
2
votes
2answers
42 views
Naming of overloaded methods - singular or plural? [closed]
This question is about your opinions and/or existing conventions.
Let's say I have an object Basket that store various items in some private property (Basket._items). Now, I want to have a couple of ...
2
votes
1answer
58 views
Arduino based SNES controller wireless transmitter/reciever, code questions
I am building a transmitter and reciever pair for two SNES controllers, as I don't like using long extension cords to get the controllers to reach the couch. I'm using atmega328p's for the avr's, ...
2
votes
2answers
167 views
Best practice for converting minutes and seconds in seconds
I have 2 input fields to input the duration of a CD song. The first input is for minutes and the second is for seconds
When submitting the form, I must insert in the db the duration either in seconds ...
2
votes
1answer
49 views
Is it safe to cast a pointer to non-void function into a pointer to void function?
I thought it was a good idea to use this in my C++ projects:
class CRAIICall
{
public:
typedef void (WINAPI * FnType)(HANDLE);
CRAIICall(HANDLE h, FnType fun)
: m_h(h), m_fun(fun)
...
1
vote
1answer
55 views
How to improve a file access permission/deny function?
I've quickly made a function to deny or allow access to files that are only used thru Ajax Calls.
Key Generator
/**
* Generate a key for file access permission
*
* Function that returns a key to ...
3
votes
1answer
53 views
How to improve function to detect the mime type using an agnostic method?
This function is used to get the mime type of any given file. The intended purpose was to have it working within any of our servers that vary from the latest PHP version down to PHP 4.
/**
* Get the ...
2
votes
1answer
86 views
How can this function to get a remote file improve?
I've prepared a function using cURL to get a remote file to the local storage:
/**
* cURL - Get Remove File
*
* Function using CURL the get a remote file to the local storage.
*
* @param str ...
2
votes
2answers
54 views
Is this function properly structured, leading to a secure row insertion?
I have the following function to insert a new row into a table:
/**
* Insert row into the designated table
*
* Function to add a new row into the designated table
*
* @param str $table ...
2
votes
1answer
58 views
How to optimize function that checks if a directory is empty when having over a million files inside?
I have the following function to confirm if a directory contains files:
/**
* Check if the directory is empty
*
* Function to ascertain if the specified directory contains files.
* Comparing to ...
3
votes
1answer
55 views
How does this function look?
What do you think of my function. It is used to change a cyrillic word with a stress marker into the same cyrillic word but with the stress marker seperately represented as a number. As I want to ...
4
votes
3answers
155 views
C Split function review
I started learning C a week ago, and here is my implementation for the split function:
char** my_split(const char* str, char delim, int* size)
{
int index = 0, start;
char** results = NULL;
...
-1
votes
1answer
34 views
How to convert this PHP function to display dropdown list instead of checkboxes? [closed]
function get_question_categories($queston_cat = array()){
$return_str = '';
if(get_option('ptthemes_question_cat_selection_flag'))
{
$cat_exclude = get_inc_categories("cat_exclude_");
...
1
vote
2answers
71 views
How to improve this PHP function to confirm the presence/create directories?
While preparing an automated process to manipulate files, I've made the following function to check for the base directory and sub-directories presence, as to allow or deny the remaining code to be ...