PHP: Can I pipe curl output through gunzip using built in curl functions?

I’m working on a script that downloads large files, decompresses them, and then parses the contents, inserting data I like into sql. I upgraded this script to work in a multi-threaded type way, where it is downloading one file, decompressing another file, and parsing another file all at once. But alas, I’m getting bottlenecked by the hard drive.

With the help of ##php, I realized I can use the following command to pipe output of curl directly to gunzip to cut my disk i/o in half (excluding SQL):

curl | gunzip -c > /large_temp_files/large_file

Tested and confirmed, this method writes the uncompressed data directly to disk without writing compressed data first.

So my question is, is there any way I can pipe the data like that using php’s build in curl functions? For regular files, you can open a file pointer and set that pointer as one of the curl_setopt options, to download the file to disk rather setting the data to a variable. These are 5 GB files so that’s not going to work. All my other code uses the built in functions for my http requests, so I’d like to stick with doing it that way if possible, for consistency and readability.

Determining response codes from void functions OOP

I am trying to create a Put endpoint using rest. Let’s say that under the link


I am trying to add a new address (if that id doesn’t exist) or I’m trying to update it if it does already exist.

My application has several layers Controllers, Services, Models and Repositories. Given the fact that the business layer decides if an update or an add is required (this logic takes place in the service layer and below), how would the controllers be able to find out if an update or an add happened and return the correct status codes (201 for resource created, 204 if just an update has occured)?

My only ideas are to return some sort of result object, but that doesn’t feel particularly correct. For the cases where the service methods are not void, they usually return DTOs.

Can a language with some set of higher-order functions like map, fold and filter but without recursion or iteration be Turing complete?

I was reading this article and was wondering if there is any finite set of higher-order functions like map, fold or filter such that they could empower a language to be Turing complete even without having explicit constructs for recursion or iteration. Obviously the higher-order functions would be implemented with recursion or iteration, but the requirement is that recursion or iteration could not be directly exposed to the programmer. That is to say, recursion or iteration can be baked in a finite set of pre-defined, built-in higher-order functions, but the language must not have an explicit construct for iteration or recursion. The set of higher-order functions can be arbitrarily large, but must be finite.

Alternatively, if the answer is no, which is the biggest set of problems that could be computed by such a language? Is that set a known set (eg. equivalent to pushdown automaton)?

How is semaphore used to implement monitor x.wait() and x.signal() functions?

I don’t understand how semaphore is used to implement x.wait() and x.signal() functions in monitor in the code provided by the reference book “operating system concepts”

All what i understand that x.wait() must increment the entry queue by one and in x.signal() decrement the entry queue by one

But that doesn’t seem the right answer


semaphore mutex; // (initially = 1) semaphore next; // (initially = 0) int next_count = 0;  //each function f   wait(mutex); … body of F … if (next_count > 0) signal(next); else signal(mutex);    //for each condition variable x   semaphore x_sem; // (initially = 0) int x_count = 0;  //x.wait()   x_count++; if (next_count > 0) signal(next); else signal(mutex); wait(x_sem); x_count--;     //x.signal()    if (x_count > 0) { next_count++; signal(x_sem); wait(next); next_count--; } 

Sum of finite cosine functions

Is it possible to apply trigonometric conversion on multiple sum of cosine functions ?

I have a sum like this:

cos(a1pi) + cos(a2pi) + cos(a3pi) + ... + cos(a10pi)

The coefficient values ak can be integer or floating point value. Generally trigonometric conversions are developed on sum of two cosine functions.

Appropriate structure for keeping large number of similar functions

I have a class that gets initialized with an array of lambda functions. These functions then get called in another method:

class MyClass   def initialize(funcs)     @my_funcs = funcs   end    def call_funcs_with_arg(arg)     @my_funcs.each {|f| }   end end 

Only certain type of functions are acceptable as input (they all need to follow the same signature). There are some ‘built-in’ functions but I also want to allow custom functions. I put my built-in functions into a module called MyFunctions. So the usage can be something like this:

custom_function = lambda {|arg| p arg} func_caller =[MyFunctions::FUNC_1, MyFunctions::FUNC_2, custom_function]) func_caller.call_funcs_with_arg('hello') 

I have some doubts about the way I structured this code. The part I’m not sure about is 1. whether a separate module is appropriate for these functions. Should they just live inside MyClass class? It feels like I’m bloating the class, as the list of the functions can grow quite a bit. But then if they live separately like this, it feels like I’m separating something pretty integral to the functionality of MyClass (it can function without MyFunctions module but usually you would want these built-in functions.

2. The secondary question is about using ruby lambdas. I picked this format somewhat arbitrary, but I could equally use actual methods or procs. Are there considerations of using one as opposed to another? At the moment my module looks like this.

module MyFunctions   FUNC_1 = lambda { |j| p "not #{j}" }   FUNC_2 = lambda { |j| p "definitely #{j}" }   ALL_FUNCS = [FUNC_1, FUNC_2] end 

Finally, it’s pretty common to use all functions from the module. At the moment I have a helper constant ALL_FUNCS that returns an array of all lambdas.The way I have it written however, means that everytime I add a new FUNC_* I need to add it to that array, which is a bit ugly. 3. Is there a way to get something like “all other constants” from that module? Something like:

ALL_FUNCS = all_constants_except_this_one


Compact Hausdorff space is metric if there countable separating continuous functions

Proposition:Let $ X$ be a compact Hausdorff space. Suppose there are countable real valued continuous functions $ \{f_n\}$ separating $ X$ (i.e., for all $ x, y \in X$ with $ x\not =y$ , $ \exists k:=k(x,y)$ , $ f_k(x)\not =f_k(y)$ ). Let $ d(x,y):=\sum_{n=1}^\infty \frac{min\{|f_n(x)-f_n(y)|, 1\}}{2^n}$ ,then $ X$ is metrizable by $ d$ .

I want to prove that, for all open set $ U$ , there exists $ B(x;r)$ s.t., $ B(x;r)\subset U$ and for all $ B(x;r)$ , there exists an open set $ U$ s.t.,$ U\subset B(x;r)$ . Here, $ B(x;r):=\{y\in X| d(x,y)<r\}$ . i know $ B(x;r)\supset \bigcup _n \{y; |f_n(x)-f_n(y)|<r\}$ , but riht term is not open.

How to prove this proposition?

angular service for centralizing common grid functions

I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks for the sort, filter, group functions of the grid. 90% of the grids I have are a very simple CRUD grid with next to no validation or business logic involved.

As a result, I have to write the following code (Typescript) over and over for each grid:

 public initData(): void {     this.gridData = process(, this.gridState);   }    public onStateChange(state: DataStateChangeEvent): void { => (group.aggregates = this.aggregates));     this.gridState = state;     this.gridData = process(, this.gridState);   }    public groupChange(grp: GroupDescriptor[]): void {     this.groups = grp;     this.gridData = process(, this.gridState);   }    public sortChange(srt: SortDescriptor[]): void {     this.sort = srt;     this.gridData = process(, this.gridState);   }    public filterChange(fltr: CompositeFilterDescriptor): void {     this.filter = fltr;     this.gridData = process(filterBy(, this.filter), {       group: this.groups,       sort: this.sort     });   } 

this is obviously in the component class behind each grid.

What I am wondering is, Can I move the functions to a service so that I don’t have to rewrite them for each component? Additionally, should I create them as static so that there is only one or should I instantiate a new “service” for each component?

Just wondering what others think about this