# broccoli

98 questions

1

925

views

### Angular ViewChild custom sort selector

I'm learning about angular ViewChild currently, but I seem to be missing something when using ViewChild to select custom reference variables from the DOM. In my template I have two tables: I am attempting to target them with a sort for each: @ViewChild('eventTable') eventTableSort: MatSort; @ViewChi...
Broc Broccoli

2

326

views

### How reliable is server side detection of flash?

In answering a question on stack overflow, one person recommended using the following code to detect flash server-side, he pointed out that it does not work in safari: if (strstr($_SERVER['HTTP_ACCEPT'], 'application/x-shockwave-flash')){$hasFlash = true;} Testing for Flash capability on the serv...
broccoli_soup

1

221

views

### ddply for transforming data

I've the following test data frame. id1 val A 1 A 1 A 1 A 1 B 2 B 2 B 2 B 2 I would like to transform it to a data frame as shown below. id1 val A 1 A 1 A 2 A 2 B 3 B 3 B 4 B 4 What I've done is to first find the count of the number of times A & B occur, in this case...
broccoli

1

878

views

### Using OAuth2 with iOS 7

Does anyone know a reliable library I can use to allow OAuth authentication within my iOS7 app? I've been searching for the last 2 days and can't find anything that works.
Choppin Broccoli

1

331

views

### Gnuplot--set label for points that exceed data range

My question about how to automate placing labels at the edge of a plot for data points that exceed the range of plot. This would be done for points that are outliers that, if plotted, skew the scale of the plot such that the plot is no longer useful, but still need to be noted. For example, let's...
chocolate.broccoli

1

399

views

### gnuplot--iteration to obtain variables in datafile

Let's say that I've got data called 'myData.dat' in the form x y 0 0 1 1 2 2 4 3 8 4 16 5 I need to find the following things from this data: slope for points 0 to 5 1 to 5 2 to 5 3 to 5 4 to 5 y-intercept for the same pairs equation for the line connecting the same pairs Then I need to plot t...
chocolate.broccoli

2

107

views

### Probabilistically Sample from an Array in Perl

I have an array in Perl and I would like to draw samples from it in a probabilistic manner. For example in R the function sample does it for me, e.g. x = c('a','b','c','d') sample(x,size = 2,prob = c(0.1,0.4,0.4,0.1)) The above code would return b,c more often. How do I do the same in Perl. Is there...
broccoli

1

221

views

### Trouble viewing Diffie-Hellman parameters (p,g,Y) in TLS exchange

I have the following output (selections from total output posted) and am trying to figure out how view the Diffie-Hellman parameters established during the handshake. From my understanding (via RFC 5246), these parameters should be viewable in the ServerKeyExchange message but I'm having some diffic...
broccoli

1

260

views

### Getting a “Can't resolve variable of class” error when trying to access header variable

I have a container std::map map; in an a6.hpp header file but when I try to access map in my source file, I get a 'Can't resolve variable or class' error. I have a #include 'a6.hpp' line but it's still giving me this error. Could someone help?
Broccoli Kang

1

156

views

### React-Redux: Passing arguments from handler to action creator

I have scoured the web and various sources; none seem to apply to my question. The closest might be this (which doesn't have an answer): React + Redux function call So: I am attempting to pass arguments along to one of my action creator fields, a function called update which will determine if the b...
broccoli_rob

1

0

views

### How to read files in a concurrency safe manner in an asp.net webpage?

I need an asp.net webpage to read some text from a file stored on the same server as the webpage, will the following code result in a concurrency error if several people visit the webpage at once and thus several requests to read the file are generated: string fileText = System.IO.File.ReadAllText(R...
broccoli_soup

4

87

views

### Ubuntu Splitting a file into three files with a third of the number of total lines in each

I have a simple ascii text file with a string in each line, something like aa1 aa2 ab1 ... with a total of N lines. I know I can use the split command to split it out into a fixed number of lines per file. How do I specify the number of files I want to split it into and let split decide how many lin...
broccoli

1

317

views

### Mathjax/Matplotlib font in Jupyter

I'm making a plot using Matplotlib in Jupyter. The issue I'm having is that Mathjax renders math font using the default Maplotlib font (Dejavu Sans, I believe). I want to use Times New Roman, so this issue makes my plot have two different fonts. I've included a short example that highlights the i...

1

1.5k

views

### Where is JBOSS_HOME variable set for Intellij

So I'm trying to run JBoss server in Intellij, but there's a conflict between JBOSS_HOME path that Intellij reads from somewhere and the actual path to Jboss folder that is set in Run/Debug Configuration. The Run/Debug Configuration Jboss path used to be the same as JBOSS_HOME, but it has changed,...
Broccoli

1

84

views

### Issue modifying map from goroutine func

scores := make(map[string]int) percentage := make(map[string]float64) total := 0 for i, ans := range answers { answers[i] = strings.ToLower(ans) } wg := sync.WaitGroup{} go func() { wg.Add(1) body, _ := google(question) for _, ans := range answers { count := strings.Count(body, ans) total += count s...
Disco Broccoli

3

125

views

### Perl regular expression extract array elements

I have a file with several rows of text. Each row contains a text array that is represented as follows ['ABC','D EF','XYZ'] ['MNO','P','QR ST'] ['A'] ... Notice, some of the words within quotes have spaces between them. I'm reading it into a perl script that looks like below while(){ @tmp = split /...
broccoli

1

618

views

### R data.table applying a function to subset of columns based on parameters from a list

Assume I have the following data.table z = data.table(val1 = 1:11,val2 = 3:13). In addition to this, I have a list of parameters which looks as follows lambda = list(c(2,1),c(4,2)). What I'm trying to accomplish is to apply a transform to both columns of the data.table as follows val1 = val1^param1...
broccoli

1

131

views

### R, Getting the top in every category from a data frame?

I have the following data frame id,category,value A,21,0.89 B,21,0.73 C,21,0.61 D,12,0.95 E,12,0.58 F,12,0.44 G,23,0.33 Note, they are already sorted by value within each (id,category). What I would like to be able to do is to get the top from each (id,category) and make a string, followed by the se...
broccoli

2

93

views

### R, Using reshape to pull pre post data

I have a simple data frame as follows x = data.frame(id = seq(1,10),val = seq(1,10)) x id val 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 I want to add 4 more columns. The first 2 are the previous two rows and the next two are the next two rows. For the first two rows and last two...
broccoli

1

64

views

### Blocking a shell script's execution flow until prior processes finish?

I've a list of jobs that I want to run in parallel and I call them all from one master script. Here is an example echo 'Starting jobs' job1 & job2 & job3 & # I want to wait until job1, job2 & job3 finishes on the multi core box echo 'Now I can proceed' How do I do this?
broccoli

3

892

views

### Rake task executing twice when only called once

I've written a very simple rake task to try and locate the source of this problem. namespace :foo do task bar: :environment do puts 'RUNNING' end end When executed in the console rake foo:bar the output is: RUNNING RUNNING This occurs when I execute any rake task. Has anyone encountered anything lik...
Broc Broccoli

3

879

views

### R generating a sparse matrix

I have a large file with the following format which I read as x userid,productid,freq 293994,8,3 293994,5,3 949859,2,1 949859,1,1 123234,1,1 123234,3,1 123234,4,1 ... It gives the product a given user bought and its frequency. I'm trying to make it into a matrix which gives all the productid's as co...
broccoli

2

337

views

### Arduino Look-alikes and Ubuntu

I had a general question about coding with Arduino Uno-R3 on Ubuntu. I'm thinking of getting one ebay. I do see a lot of similar ones (not arduino branded) but at lower price. I intend to use it by plugging it into ubuntu 12.04 and fix some simple sensors on it. Do these non-branded 'arduino'-like b...
broccoli

1

14k

views

### R using dcast to widen a data frame

I have the following data frame z
broccoli

1

1.5k

views

### R data.table and kmeans clustering

I'm not even sure if this is possible with data.table. I have a data set that looks like the following. Its a data frame, but I later convert to a data.table, called x id xcord ycord a 2 3 a 3 4 a 3 3 a 9 10 a 8 9 b 1 3 b 1 2 b 8 19 b 7 21 I want to identify two clusters per id, and that is...
broccoli

1

271

views

### R fitting a polynomial on data

I have some data synthetically generated from a function which is shown below. fn
broccoli

2

1.1k

views

### Hashing function for mapping integers to a given range?

I've a set of integers each of which have 8,9 or 10 digits in size. I've millions of them. I want to map each one of them to an integer in the range of 1 to 1000. I cannot do a simple mod on the integers as there are systemic biases in the way these numbers have been issued (for example even numbers...
broccoli

1

1.3k

views

### R ggplot2 fonts issue

I'm trying to get the xkcd fonts working in R with ggplot2. However I'm running into some issues. Here is what I have done so far. 1) Installed the 'Humor Sans' font from the xkcd site in the directory ~/.fonts 2) Installed the 'extrafont' package. This installation worked smoothly. 3) Load the libr...
broccoli

6

43.6k

views

### Removing an item from an array in Objective-C

This question might seem easy, but I'm looking for the most efficient and memory friendly way. Let's say I have an array of Person objects. Each person has a hair color represented by an NSString. Let's then say I want to remove all Person objects from the array where their hair color is brown. H...
Choppin Broccoli

3

3.4k

views

### Trapping signals cleanly in Perl

I have a simple Perl script that simply prints a line of text to stdout. What I want to accomplish is that while this script runs, if I (or someone else) issues a signal to that process to stop, I want it to trap that signal and exit cleanly. The code I have looks like the following #!/usr/bin/perl...
broccoli

2

219

views

### Getting at grouping term from within ddply function?

I have the following example data frame x id val a 1 a 2 a 3 b 2 b 4 b 9 I have a simple function that I apply while doing my SAC. Something like, f.x
broccoli

2

783

views

### Co-occurrence matrix using SAC?

I have the following data frame 'x' id,item,volume a,c1,2 a,c2,3 a,c3,2 a,c4,1 a,c5,4 b,c6,6 b,c1,2 b,c3,1 b,c2,6 b,c4,4 c,c2,5 c,c8,6 c,c9,2 d,c1,1 e,c3,7 e,c2,3 e,c1,2 e,c9,5 e,c4,1 f,c1,7 f,c3,1 The first column is the id of a customer, the second column is the id of an item that customer bought...
broccoli

1

106

views

### Fast data.table filtering

I've a use case where I want to rapidly filter data tables repeatedly. I've a feeling that if I use a simple filter like df[val>0,] the scan is O(N), but if I simply set the val field as a key then I should be able to filter faster, but not sure how. As an example I've done the following a sorted da...
broccoli

1

404

views

### R check sort order in two lists

This is turning out to be bit of a challenge. I've three vectors x, y & z x = c('a','b','c','d','f','m','n') y = c('b','c','f') z = c('b','a','n') x is my superset. It specifies the order in which the elements a,b,c... etc should appear. What I want to do is to be able to tell if a vector follows th...
broccoli

3

1.9k

views

### R .C interface: Passing multidimensional arrays

I've written up a function 'foo' in C that I want to call from an R program. The function takes in as input a matrix and does some operations on it, (say add 1 to each element). While it is easy to a single vector as .C('foo', n=as.integer(5), x=as.double(rnorm(5))) with foo implemented as void foo...
broccoli

2

4.3k

views

### Pandas filling missing dates and values within group

I've a data frame that looks like the following x = pd.DataFrame({'user': ['a','a','b','b'], 'dt': ['2016-01-01','2016-01-02', '2016-01-05','2016-01-06'], 'val': [1,33,2,1]}) What I would like to be able to do is find the minimum and maximum date within the date column and expand that column to have...
broccoli

2

11.9k

views

### Conditionally change panel background with facet_grid?

I'm using the 'tips' data set in ggplot2. If I do sp = ggplot(tips,aes(x=total_bill, y = tip/total_bill)) + geom_point(shape=1) + facet_grid(sex ~ day) The plot comes out fine. But I now want to change the panel background for just the plots under 'Fri'. Is there a way to do this? Even better, ca...
broccoli

1

452

views

### Request for declined permissions. Unity for Facebook

Been trying to request for declined permission with FB.login('Scope') but it redirects me to the login page again. After logging in, it prompts me with a 'You have already authorised APPNAME.' FB.login doesn't support 'auth_type'. Does anyone have any solutions to this problem? Thanks~ May the forc...
Dion Broccoli

2

80

views

### R merging several contingency tables into one

I have the following list of contingency tables structure(list(1 = structure(c(1L, 1L, 1L, 0L, 1L, 0L), .Dim = 2:3, .Dimnames = structure(list( c('a', 'b'), c('x', 'y', 'z')), .Names = c('', '')), class = 'table'), 2 = structure(c(1L, 1L, 0L, 1L), .Dim = c(2L, 2L), .Dimnames = structure(list(...
broccoli

1

78

views

### @Injected @ManagedBean gets reinitialized despite of @ApplicationScoped annotation

I am writing a simple JSF application for converting currencies. There is a Rates class which holds the data, Currencies class for managing requests and Manage class for adding new currencies. My problem is: I want the currencies to be persisted as a property of Rates class hence my use of @Applica...
Broccoli