text:
Q: unison / rsync getting copies of changed files So the place where I'm working at has a nifty little Red Hat Enterprise server and a tape backup system that they want me to get working backing up the large amounts of video content and resources produced by the company.
The desired situation would be to keep a local copy of all the data on said Red Hat server and then copy all changed files to tapes which will then be sent offsite.  I know that I can use either unison or rsync for the initial local data backup but what I need to know is if there is a way to get a list of only the changed files which will then be copied (in full) to the tape.
I've found several possible solutions through auditing software but they all seem to require a kernel recompile (which is not feasible right now).  I also was promised that unison could do this "out of the box" but I haven't figured out how.
Is there a solution to my presented question or am I going about this at a fundamentally wrong way?  Any help/advice would be appreciated!
Cheers!
-Russell C

A: I would use a backup program like Bacula to do this. It keeps a database of your backups so it don't need to compare file sizes and time stamps against already backed up files like rsync.
If you want to use rsync, you could use find to find files changed after your last backup, write this to a file and read the file names to copy from this file with rsync's --files-from option. This opens timing issues, though.

A: Whats wrong with the normal rsync output?
/tmp # ls -l ra
total 8
-rw-r--r-- 1 phemmer unix  5 2011/02/09-16:42:49 adsf
-rw-r--r-- 1 phemmer unix 29 2011/02/09-16:49:41 date

/tmp # date > ra/date

/tmp # rsync -Haxv  ra rb
building file list ... done
ra/date

sent 180 bytes  received 42 bytes  444.00 bytes/sec
total size is 34  speedup is 0.15

Just pipe rsync out somewhere rsync ... 1>/path/to/log and then parse through the log for the list of files changed
P.S. You do not want to use unison for this. Unison is a 2-way rsync, for backups you want 1-way.


text:
Q: Clustering on a data set with mixed variables I have a data set consisting of $n$ elements with $d$ features for each element ($x_{i,f}$ means the value for the f-th feature of the i-th element).
I would like to cluster this data set into $k$ clusters.
One problem I have is that one feature is a nominal one and another is a discrete ordinal one. As an example consider elements which have the following features:

*

*$x_{i,1}$ : the height of a person

*$x_{i,2}$ : the weight of a person

*$x_{i,3}$ : country where the person lives

*$x_{i,4}$ : nr. of friends the person has

Is it ok to use a simple k-means algorithm with an euclidian distance measure?
I would introduce a indicator variable $\delta$ with the following meaning for feature $x_{i,3}$:
$$\delta(i,j) = \begin{cases}   0,  & \text{if }x_{i,3} = y_{j,3}\text{,}\\
   1, & \text{else.}\end{cases}$$
So two objects $i$ and $j$ have no distance for their third feature if this feature is the same (same country) and 1 otherwise.
Or do you know a better way to do a cluster analysis in this case?

redpajama_set_name: RedPajamaStackExchange


text:
Q: Docker-compose - passing environment variables to Flask using script This my project strcuture at host:
   set_env_vars.sh
              dev/
                 docker-compose-dev.yml
                 /services/
                          web/
                             .env-dev?  <------
                             project/
                                    config.py
                                    api/
                                       resources/
                                                auth.py

set_env_vars.sh
export SPOTIFY_CLIENT_ID=my_id
export SPOTIFY_CLIENT_SECRET=my_secret
export SPOTIFY_REDIRECT_URI=http://localhost
export SPOTIFY_CACHE_PATH=/project/api/auth/spotify/.cache

which I run like so:
$ source ./set_env_vars.sh

docker-compose-dev.yml
services:

  web:
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID}
      - SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET}
      - SPOTIFY_REDIRECT_URI=${SPOTIFY_REDIRECT_URI}
      - SPOTIFY_CACHE_PATH=${SPOTIFY_CACHE_PATH}

config.py
class DevelopmentConfig(BaseConfig):
    SPOTIFY_CLIENT_ID = os.environ.get('SPOTIFY_CLIENT_ID')
    SPOTIFY_CLIENT_SECRET = os.environ.get('SPOTIFY_CLIENT_SECRET')
    SPOTIFY_REDIRECT_URI_ = os.environ.get('SPOTIFY_REDIRECT_URI')
    SPOTIFY_CACHE_PATH = os.environ.get('SPOTIFY_CACHE_PATH')

auth.py
from project.config import DevelopmentConfig

sp = spotipy.Spotify(auth_manager=spotipy.oauth2.SpotifyOAuth(
      DevelopmentConfig.SPOTIFY_CLIENT_ID,
      DevelopmentConfig.SPOTIFY_CLIENT_SECRET,
      DevelopmentConfig.SPOTIFY_REDIRECT_URI,
      scope=DevelopmentConfig.SCOPE,
      cache_path=DevelopmentConfig.SPOTIFY_CACHE_PATH))

But I'm getting the following error:
spotipy.oauth2.SpotifyOauthError: No client_id. Pass it or set a SPOTIPY_CLIENT_ID environment variable.

What am I missing?

A: This certainly looks like you need to pass the variables with the SPOTIPY_ spelling, as per the docs.
However I also noted that your code repeats the same variable names several times.  Possibly this could lead to typos as you try to maintain the same variable names across several files.
A simpler way to approach this might be to have the variables contained in a .env-dev file:
SPOTIPY_CLIENT_ID=my_id
SPOTIPY_CLIENT_SECRET=my_secret
SPOTIPY_REDIRECT_URI=http://localhost
SPOTIPY_CACHE_PATH=/project/api/auth/spotify/.cache

Then load these in your docker-compose-dev.yml file:
services:
  web:
    env_file:
      - .env-dev

Then in your Python code you could do:
import os, DevelopmentConfig

sp = spotipy.Spotify(auth_manager=spotipy.oauth2.SpotifyOAuth(
      os.environ.get('SPOTIPY_CLIENT_ID'),
      os.environ.get('SPOTIPY_CLIENT_SECRET'),
      os.environ.get('SPOTIPY_REDIRECT_URI'),

      scope=DevelopmentConfig.SCOPE,

      cache_path = os.environ.get('SPOTIPY_CACHE_PATH')))

This method has less repitition, although loading of a configuration bypasses your config.DevelopmentConfig object for these variables.
However this method avoids loading the variables into the host's shell, and instead sets them inside a specific service.  It also separates secerts so you can commit docker-compose.yml to source control.


text:
Q: How to reinstall Terminal? While fixing package dependencies, the terminal application went missing, and now I cannot locate the application. Is there a way to reinstall the terminal application?

A: Well you can do with Ubuntu Software Center or (if you have it) the Synaptic Package Manager.
Just type terminal in the search box of either application, and you'll get what ever you want.
Another way to install it in the Software Center is to click:

A: Press Ctrl+Alt+F1 (to enter a virtual console), log in with with your account and install the package gnome-terminal with the command:
sudo apt-get install gnome-terminal

When you type passwords into a text-only virtual console, you don't see anything on the screen. That's normal.
Return to Unity (or whatever other desktop environment you're currently running) by pressing Ctrl+Alt+F7.

A: The Middle Way
This totally non-graphical way, and this totally graphical way, are both excellent. But there is a third way, too.
Ubuntu comes with another (simpler) graphical terminal program that you can fall back on!
If you cannot use the Terminal (for users of other Ubuntu flavors, this applies to the Konsole, Xfce4 Terminal, and LXTerminal, too), you can still use xterm.
Press Alt+F2, type xterm, and press Enter.

Here you can install gnome-terminal with apt-get:
sudo apt-get update && sudo apt-get install gnome-terminal

You'll notice my command is a little different from Bruno Pereira's. Having recently performed lots of package management, you may not need to run sudo apt-get update. (Unless your dependency problem was from apt-get and you didn't run it with update before, then you definitely need to.) You can decide.

Ubuntu's xterm is very basic in style. As far as I know, there's no GUI way for xterm to scroll back, save history, change font and font size, or anything like that. The actual shell's capabilities will of course be the same as in any Terminal, since it's still bash. (Or whatever you set it to be.)
Alternatives
If you have a longer-term problem of any kind with the GNOME Terminal, you can use xterm, but it is not as friendly and (in some ways) not as sophisticated as GNOME Terminal.
If you continue to have trouble getting GNOME Terminal working but you're able to install software in general, you can install:

*

*Xfce's terminal – xfce4-terminal

*LXDE's terminal – lxterminal
You should not use Konsole for this, however, unless you already have KDE installed. Installing it usually pulls in lots of KDE-related packages as dependencies.

A: You can install it using a single command,
it actually works for me..
You can also try using software center by searching the item in your peppermint device.
sudo apt-get update && sudo apt-get install gnome-terminal


text:
Q: CSS position of divs without id Is there a way to position or style divs without knowing the id?
<!DOCTYPE html>

Red DIV

Blue DIV

A: The best way to target elements is with ids or classes, but you can use :nth-child

#main > div {
  background-color:coral;
  width: 40%;

  float: left;
}
#main > div:nth-child(2)  {
  background-color: lightblue;
  width: 60%;

  float: right;
}

Red DIV

Blue DIV

A: #main div:nth-of-type(1) { background-color: red; }

#main div:nth-of-type(2) { background-color: blue; }


text:
Q: IntelliJ VCS is combining projects on GitHub Every project I now create in IntelliJ is getting mixed up with a previous one when I try to push it to GitHub.  They all end up in a single repo. I was previously able to share the projects and commit and push without problem.  Now, something has changed and I don't know how to fix it.
I created a new project checkGitPush to trace the problem and find the following issues.  "Enable Version Control" did not show up on the VCS menu.  I can commit locally, but when I try to Share the Project to GitHub, I get this message:
Project is Already on GitHub
Following remotes are already on GitHub

(It then lists three separate projects)
When I look on GitHub, all these projects are getting put into the bottom-most project listed on the message.
Any suggestions are appreciated.
I am on a Windows laptop with IntellJ IDEA Community Edition 2019.2

A: Make sure there is no .git folder in any parent directory of the one you are using for your new project:
c:\
  path\
    to\
      .git
      some\
        new_project\

Here new_project would be part of the Git repository located in C:\path\to, and possibly linked to a GitHub repo: type git remote -v in command line to confirm it.
Removing that .git\ folder (or at least moving it, saving it elsewhere) would allow you to create an independent project, which could be linked to its own GitHub repository, following for example "CheatSheet - Setup Github on Visual Studio Code"

A: Looks like you create new projects inside an existing git repository. So IDE detects there is a git root above the project and registers it. As a result, new files become part of the existing repository.


text:
Q: Switching between a test database and production database? What is the best way to easily switch from a test database to a production database in vb.net and MySql, when all MySql connection strings are currently hard coded?

A: Take the time to move them to a configuration file. It might be a little more work now, but over the life of the project you will make up that time.

A: Migrate the hard coded connection strings into a config file.
It's certainly not a difficult procedure.

A: I currently use two options.
1) Take advantage of web.config transformations. It allows you to easily define your test and production environments, and will recompile the web.config file based on Visual Studio's build configuration. I outline this a little in my blog here.
2) If you can't go that "advanced", add your configurations into your connectionStrings section of your web.config in the following naming conventions:

*

*databasename.DEV

*databasename.PROD

Once this is complete, you can create a simple function that pulls the proper connection string based on the environment on the server. For instance, if the current server's name is X, then pull the connection string from the PROD profile, otherwise use the DEV profile. It makes for a little extra work, but allows to keep everything in a single config file but still changes things without having to comment/uncomment various sections in your web.config file.


text:
Q: Saving and Loading an NSMutableArray I want my app to work so that when a user presses a "save" button, an NSMutableArray of strings (the array is called "names") inputted from a textfield will be saved. Naturally I also then want to be able to load the NSMutableArray any time I close/reopen the app.
Right now my save button is an IBAction "save". So in my implementation file I have:
- (IBAction)save:(id)sender
{
    NSArray *paths =  NSSearchPathforDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex:0];
    NSString *fileName = [NSString stringWithFormat:@"%@/myArray", docDir];
    [NSKeyedArchiver archiveRootObject:names toFile:fileName];
}

First of all, does this seem like it should work? Because multiple times my app crashed when I tried to then press the save button. Second am I right to be creating the file path in the IBAction? Or should I be creating it somewhere else (e.g. under viewDidLoad)?
Second, how and where should I be loading my saved NSMutableArray ("names")?
Many thanks!

A: You are missing few concepts here, first as already said by Zaph are you sure that names objects conforms to NSCoding protocol?
If yes those line of codes should do the trick:
- (IBAction)save:(id)sender {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = paths.firstObject;
    // Add to the path a new directory just to keep things ordered
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"AppData"];
    // If the directory doesn't exist it creates one
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory]) {
        NSError *error;
        [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            NSLog(@"Error creating directory %@",error.localizedDescription);
        }
    }
    NSString * path = [documentsDirectory stringByAppendingPathComponent:@"names.arc"] ;
    //Check if the file alredy exist, if does we remove it or the file manager will trigger an error (it doesn't overwrite automatically)
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        [[NSFileManager defaultManager] removeItemAtPath:path error:nil] ;
    }
    // Pass the object that you want to archive, if it is a collection the object inside must support NSCoding protocol
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:<#ObjectsConformToNSCoding#>];
    // Saving to the path
    [data writeToFile:path atomically:YES];

}

[UPDATE]
As pointed out by Zaph all the errors should be handled correctly or bad things could happen.

A: The message: "Thread 1: breakpoint 3.1" indicated the program has hit a breakpoint. A breakpoint can be set accidentally or on purpose by clicking on  the line number in the Xcode editor. Breakpoints are used to stop the program execution to allow thew developer to examine the state of execution at that point. Then the program can be resumed.
A breakpoint is not a crash.
Also a a blue colored arrow over the line number is a breakpoint indicator. You can remove it by dragging it to the right or disable it by clicking on (it will dim) or just continuing (Menu Debug:Continue).
To see all breakpoints look at the breakpoint navigator: Command-7.
It is worth the time reading the Xcode documentation WRT debugging.


text:
Q: Monte Carlo Simulation in Excel for Non-normal Distributions I would like to simulate the performance a baseball player.  I know his expected performance for every future year and the standard deviations of those performances (based on regression analysis).  At first, I was thinking of using the NORMINV(RAND(),REF,REF) function in excel, but the underlying distribution of baseball players' performances is dramatically right skewed.  Is there a way that I can perform this sort of analysis in Excel or some other free or low-cost software?  The end-goal here is for the simulation to use the right skewed distribution.  Thanks very much.

A: R has lots of tools to do this sort of analysis, though you'd have to look through the docs to figure out how to use it.  R is free, at least for non-commercial use.

A: If you have a cumulative distribution table (that is evenly spaced and sufficiently detailed) then you can easily generate random values from this distribution in Excel by looking up a uniform random number generated by RAND() in your distribution table and take the corresponding "x-axis" value.
=OFFSET($A$1,MATCH(RAND(),$B$2:$B$102),0)

A1 is the cell just above the table of "x-axis" values.
B2:B102 is the cumulative distribution table.
This is a simplified example. Some small modifications may be needed to handle edge-cases and adjust for biases.
If you have enough empirical data you should be able to create the cumulative distribution table.


text:
Q: How to speed up Ruby script? Or shell script alternative? I have a Ruby script that does the following to a text file:

*

*removes non-ASCII lines

*removes lines containing "::" (two colons in a row)

*if there is more than one ":" present in the line (which aren't directly next to each other), it only keeps the strings on both sides of the last colon.

*removes leading whitespace

*removes unusual control characters

The problem is, I'm working with files that have ~20 million lines, and my script says it'll take ~45 minutes to run.
Is there a way to majorly speed this up? Or, is there a significantly quicker way to handle this in shell?
require 'ruby-progressbar'

class String
  def strip_control_characters()
    chars.each_with_object("") do |char, str|
      str << char unless char.ascii_only? and (char.ord < 32 or char.ord == 127)
    end
  end

  def strip_control_and_extended_characters()
    chars.each_with_object("") do |char, str|
      str << char if char.ascii_only? and char.ord.between?(32,126)
    end
  end
end

class Numeric
   def percent_of(n)
    self.to_f / n.to_f * 100.0
   end
end

def clean(file_in,file_out)
    if !File.exists?(file_in)
        puts "File '#{file_in}' does not exist."
        return
    end

    File.delete(file_out) if File.exist?(file_out)
    `touch #{file_out}`

    deleted = 0
    count = 0

    line_count = `wc -l "#{file_in}"`.strip.split(' ')[0].to_i
    puts "File has #{line_count} lines. Cleaning..."

    progressbar = ProgressBar.create(total: line_count, length: 100, format: 'Progress |%B| %a %e')

    IO.foreach(file_in) {|x|
        if x.ascii_only?
            line = x.strip_control_and_extended_characters.strip
            if line == ""
                deleted += 1
                next
            end
            if line.include?("::")
                deleted += 1
                next
            end
            split = line.split(":")

            c = split.count
            if c == 1
                deleted += 1
                next
            end
            if c > 2
                line = split.last(2).join(":")
            end

            if line != ""
                File.open(file_out, 'a') { |f| f.puts(line) }
            else
                deleted += 1
            end
        else
            deleted += 1
        end

        progressbar.progress += 1
    }

    puts "Deleted #{deleted} lines."
end

A: Here is one of your big problems:
if line != ""
  File.open(file_out, 'a') { |f| f.puts(line) }
end

So your program needs to open and close the output file millions of times because it is doing that for every single line.  Each time it opens it, since it is being opened in append mode, your system might have to do a lot of work to find the end of the file.
You should really change your program to open the output file once at the beginning and only close it at the end.  Also, run strace to see what your Ruby I/O operations are doing behind the scenes; it should buffer up the writes and then send them to the OS in blocks of about 4 kilobytes at a time; it shouldn't issue a write system call for every single line.
To further improve the performance, you should use a Ruby profiling tool to see which functions are taking the most time.

A: You can improve the speed by changing your String additions to variations on:
class String
  def strip_control_characters()
    gsub(/[[:cntrl:]]+/, '')
  end

  def strip_control_and_extended_characters()
    strip_control_characters.gsub(/[^[:ascii:]]+/, '')
  end
end

str = (0..255).to_a.map { |b| b.chr }.join # => "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

str.strip_control_characters
# => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

str.strip_control_and_extended_characters
# => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

Use the built-in gsub method along with the POSIX character-sets instead of iterating over the strings and testing each character.
As @Myst said though, monkey-patching is rude. Use refinements, or create some methods and pass in the string:
def strip_control_characters(str)
  str.gsub(/[[:cntrl:]]+/, '')
end

def strip_control_and_extended_characters(str)
  strip_control_characters(str).gsub(/[^[:ascii:]]+/, '')
end

str = (0..255).to_a.map { |b| b.chr }.join # => "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

strip_control_characters(str)
# => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

strip_control_and_extended_characters(str)
# => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

Moving on...
`touch #{file_out}`

is a problem too. You're create a sub-shell every time that runs, executing touch then tearing it down which is a slow operation. Let Ruby do it:
=== Implementation from FileUtils
------------------------------------------------------------------------------
  touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)

------------------------------------------------------------------------------

Updates modification time (mtime) and access time (atime) of file(s) in list.
Files are created if they don't exist.

  FileUtils.touch 'timestamp'
  FileUtils.touch Dir.glob('*.c');  system 'make'

Finally, learn to benchmark code as you develop. Take the time to think of a couple ways to do something, then test them against each other and find out which is the fastest. I use Fruity, because it handles issues that the Benchmark class doesn't, but do one or the other. You can find a lot of tests I did here for various things by searching SO for my user and "benchmark".
require 'fruity'

class String
  def strip_control_characters()
    chars.each_with_object("") do |char, str|
      str << char unless char.ascii_only? and (char.ord < 32 or char.ord == 127)
    end
  end

  def strip_control_and_extended_characters()
    chars.each_with_object("") do |char, str|
      str << char if char.ascii_only? and char.ord.between?(32,126)
    end
  end
end

def strip_control_characters2(str)
  str.gsub(/[[:cntrl:]]+/, '')
end

def strip_control_and_extended_characters2(str)
  strip_control_characters2(str).gsub(/[^[:ascii:]]+/, '')
end

str = (0..255).to_a.map { |b| b.chr }.join

str.strip_control_characters   # => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"
strip_control_characters2(str) # => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"

str.strip_control_and_extended_characters   # => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
strip_control_and_extended_characters2(str) # => " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

compare do
  scc { str.strip_control_characters }
  scc2 { strip_control_characters2(str) }
end

# >> Running each test 512 times. Test will take about 1 second.
# >> scc2 is faster than scc by 10x ± 1.0

and:
compare do
  scec { str.strip_control_and_extended_characters }
  scec2 { strip_control_and_extended_characters2(str) }
end

# >> Running each test 256 times. Test will take about 1 second.
# >> scec2 is faster than scec by 5x ± 1.0

A: There seem to be only to possible approaches to optimizing this:

*

*Concurrency.
If your machine is a Unix/Linux based machine that has a multi-core CPU, you can take advantage of the multi-cores by using fork, dividing up the work between different processes.
Multi-threading might not work as well as you'd expect with Ruby, since there's a GIL (Global Instruction Lock) that prevents multiple threads from running together.

*Code optimizations.
These include minimizing system calls (such as the File.open) and minimizing any temporary objects.
I would start with this approach before I moved on to fork, mainly due to the extra coding required when using fork.
The first approach requires a large rewrite of the script, while the second approach might be more easily achieved.
For example, the following approach minimizes some system calls (such as the File's open, close and write system calls):
require 'ruby-progressbar'

class String
  def strip_control_characters()
    chars.each_with_object("") do |char, str|
      str << char unless char.ascii_only? and (char.ord < 32 or char.ord == 127)
    end
  end

  def strip_control_and_extended_characters()
    chars.each_with_object("") do |char, str|
      str << char if char.ascii_only? and char.ord.between?(32,126)
    end
  end
end

class Numeric
   def percent_of(n)
    self.to_f / n.to_f * 100.0
   end
end

def clean(file_in,file_out)
    if !File.exists?(file_in)
        puts "File '#{file_in}' does not exist."
        return
    end

    File.delete(file_out) if File.exist?(file_out)
    `touch #{file_out}`

    deleted = 0
    count = 0

    line_count = `wc -l "#{file_in}"`.strip.split(' ')[0].to_i
    puts "File has #{line_count} lines. Cleaning..."

    progressbar = ProgressBar.create(total: line_count, length: 100, format: 'Progress |%B| %a %e')

    file_fd = File.open(file_out, 'a')
    buffer = "".dup

    IO.foreach(file_in) {|x|
        if x.ascii_only?
            line = x.strip_control_and_extended_characters.strip
            if line == ""
                deleted += 1
                next
            end
            if line.include?("::")
                deleted += 1
                next
            end
            split = line.split(":")

            c = split.count
            if c == 1
                deleted += 1
                next
            end
            if c > 2
                line = split.last(2).join(":")
            end

            if line != ""
                buffer += "\r\n#{line}"
            else
                deleted += 1
            end
        else
            deleted += 1
        end

        if buffer.length >= 2048
           file_fd.puts(buffer)
           buffer.clear
        end
        progressbar.progress += 1
    }

    file_fd.puts(buffer)
    buffer.clear
    file_fd.close
    puts "Deleted #{deleted} lines."
end

P.S.
I would avoid monkey patching - it's rude.

After posting this I read @DavidGrayson's answer, which pinpoints an issue with your code's performance in a much shorter and succinct answer.
I up-voted his answer, as I think you'll get a big performance gain from this simple change.


text:
Q: How to authenticate an iOS app in swift I was wondering how to authenticate api calls in swift to a custom service I made that authenticates users with active directory.  Currently my application stores an integer value, I want to post that to the service.
let thing = Int(emailTextField.text!)
// POST method goes here ...

A: I just authenticate my app with this piece of code.
if(isValidEmail && isValidPassword){
        print("sending to server for verification")
        let params = ["user" : ["email" : "\(email!)", "password" : "\(password!)"]]
        let url: String = "http://localhost:3000/users/sign_in"
        Alamofire.request(.POST, url, parameters: params, encoding: .JSON, headers: nil).validate().responseJSON{
            response in
            switch response.result{
            case .Success:
                if let value = response.result.value{
                    let jsn = JSON(value)
                    print("jsn: \(jsn)")
                    let authentication_token = jsn["authentication_token"]
                    if(authentication_token != nil){
                        let vc = self.storyboard?.instantiateViewControllerWithIdentifier("dasboardViewController") as! DashBoardController
                        self.presentViewController(vc, animated: true, completion: nil)
                    }
                }
                break
            case .Failure:
                break
            }
        }
    }

Make sure Alamofire is imported. I have rails server in the backend and this was tested in localhost. Also, Authentication is done using email and password instead of numbers, And it returns a json containing authentication_token field.


text:
Q: Importing Excel data into SQL Server 2005 Below SQL Query is fine when I execute in SQL Server 2008 but it is not working in SQL Server 2005.
SELECT * INTO "12-2014" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\ImportExcel\Test.xls', ['12-2014$'])

I am getting this error.
Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.
Can anyone help please?

A: this thread should help you.
essentially this:

First, I want to inform that, Import and Export Data (32-bit) is the
  default export tool when you right click a database to export data.
  Let's perform the following steps to export data from SQL Server to
  Excel with Import and Export Data (64-bit):

*

*Click Start, All Programs, Microsoft SQL Server 2008 folder, Import and Export Data (64-bit).

*In "Choose a Data Source" step, please choose "SQL Server Native Client" as Data source, and specify your Server name and Database,
  then click next.

*In "Choose a Destination" step, please choose "Microsoft Office 12.0 Access Database Engine OLE DB Provider", and then click "Properties…"

*In "Data Link Properties", under "Connection" tab, please fill out the Date Source (the excel file location, for example:
  D:\Temp\temp.xlsx); under "All" tab, please double click "Extended
  Properties", and input "Excel 12.0" (without quotation) as its
  property value, return to "Connection" tab and click "Test Connection"
  and we will receive a message stating the connection succeeded, click
  "OK".

*Click "Next" until the step "Select Source Tables and Views", please select the table you want to export there and then click
  "Next".

*Follow the wizard and finish the process.

  You can also refer to the following link which shows how to import
  data from Excel to SQL Server with screenshots:
http://hrvoje.piasevoli.com/2010/09/01/importing-data-from-64-bit-excel-in-ssis/


text:
Q: File processing: Combining multiple files with different number of columns and rows I have multiple tab delimieted files where only the two first columns are in common. I'm trying to combine them in one tab delimited file .
Example: let's say we have 3 files (file1, file2, file3) that we want to combine into file4.
(row and column names  are just for demonstration purposes and are not included in any of the files)
Input files =>
File1: 2 rows(r1,r2), 3 columns(c1,c2,c3)
    c1 c2 c3

r1  a  b  c

r2  d  e  f

File2: 3 rows(r3,r4,r5), 3 columns(c1,c2,c4)
    c1 c2 c4

r3  1  2  3

r4  4  5  6

r5  7  8  9

File3: 1 row(r6), 4 columns(c1, c2, c5, c6)
    c1 c2 c5 c6

r6  w  x  y  z

Output file =>
for all  3 files, the 2 first columns (c1, c2) have the same name
File4:
    c1 c2 c3 c4 c5 c6

r1  a   b  c  -  -  -

r2  d   e  f  -  -  -

r3  1   2  -  3  -  -

r4  4   5  -  6  -  -

r5  7   8  -  9  -  -

r6  w   x  -  -  y  z

What I'm trying  to do is: for each of the files add the needed empty columns so that all files have the same number of columns then reorder the columns with "awk" then use "cat" to stack them vertically. But I don't know if this is the best way or there is a more efficient way to do it.
Thanks,

A: The following essentially does the task. It essentially builds up a matrix entry which is indexed by the row and column names.
awk '(FNR==1) {
        for(i=1;i<=NF;++i) {
           if (!($i in columns)) { column_order[++cn] = $i; columns[$i] }
           c[i+1]=$i
        }
        next
     }
     !($1 in rows) { row_order[++rn] = $1; rows[$1] }
     { for(i=2;i<=NF;++i) entry[$1,c[i]]=$i }
     END {
        s="";for(j=1;j<=cn;++j) s=s OFS column_order[j]; print s
        for(i=1;i<=rn;++i) {
           row_name=row_order[i]
           s=row_name
           for(j=1;j<=cn;++j) {
              col_name = column_order[j]
              s=s OFS ((row_name,col_name) in entry ? entry[row_name,col_name] : "-")
           }
           print s
        }
     }' file1 file2 file3 file4 ... filen


text:
Q: MySQL: Select ALL with GROUP BY doesn't work I'm trying to select all columns from a database table and group it by one special column:
SELECT * FROM `table` GROUP BY `email`

But I get an error:
#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'gassupplytool.ggg_nitrogen.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

I have done it for years this way without getting any problems. In this case I am working on a foreign server. Can anyone help?


text:
Q: Compiling an Objective-C program I'm having problems compiling the following program. I'm using "gcc -framework Foundation inherit8.1m" and get the following errors. What am I doing wrong? Thanks.

ld warning: in inherit8.1m, file is
  not of required architecture Undefined
  symbols:   "_main", referenced from:
        start in crt1.10.5.o ld: symbol(s) not found collect2: ld
  returned 1 exit status

// Simple example to illustrate inheritance

#import <Foundation/Foundation.h>

// ClassA declaration and definition

@interface ClassA: NSObject
{
   int  x;
}

-(void) initVar;
@end

@implementation ClassA
-(void) initVar
{
  x = 100;
}
@end

// Class B declaration and definition

@interface ClassB : ClassA
-(void) printVar;
@end

@implementation ClassB
-(void) printVar
{
  NSLog (@"x = %i", x);
}
@end

int main (int argc, char *argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   ClassB  *b = [[ClassB alloc] init];

   [b initVar];     // will use inherited method
   [b printVar];    // reveal value of x;

   [b release];

   [pool drain];
   return 0;
}

A: Try renaming your source file to something that ends in just .m.  Your file has an extension of .1m which appears to confuse the compiler.

A: You've misnamed your file. It should be inherit8.m, not inherit8.1m.

A: I found it easier to use GNUmakefile on linux (not sure if this is your case).
I have a command line tool LogTest compiled from source.m:
> cat source.m
#import <Foundation/Foundation.h>

int main(void)
{
    NSLog(@"Executing");
    return 0;
}

> cat GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = LogTest
LogTest_OBJC_FILES = source.m

include $(GNUSTEP_MAKEFILES)/tool.make

> make
Making all for tool LogTest...
 Compiling file source.m ...
 Linking tool LogTest ...

> ./obj/LogTest
2009-05-17 20:05:36.032 LogTest[9850] Executing


text:
Q: In R, how do you make a loop stop when the output of the loops stops changing? I have a code like this:
library(igraph)
g <- make_empty_graph (2) %>%
  set_vertex_attr("a", value = 1) %>%
  add_vertices(2, color = 2, "a" = 2) %>%
  add_vertices(2, color = 4, "a" = 3) %>%
  add_edges(c(1,2, 2,1, 1,5, 5,1, 1,4 ,4,1)) %>%
  set_vertex_attr("xyz", value = 3)
plot(g)

for(i in 1:5) {
 print(V(g)$a)
 print(mean(V(g)$a == 1))
 print(i)

 V(g)$xyz = sapply(V(g), function(x) { NeighborList = neighbors(g, x) ; length(NeighborList[NeighborList$a == 2]) } )
 V(g)$a[V(g)$xyz==1]=2
if(time>5) {
 break
}
}

So, right now the command in the loop runs 5 times. But after i = 3, the proportion of nodes with a value of 1 for attribute "a"  stops changing. I want to change the loop so that it will automatically break if  the proportion of nodes with a value of 1 for attribute "a"  stops changing.
So instead of repeating the commands 5 times, I want it to repeat it 3 times(when the outputs stop changing) and break the loop.

A: I'm guessing V(g)$a is the value in question? If so, you could try this:
i <- 1
prev_value <- FALSE

repeat {
  print(V(g)$a)
  print(mean(V(g)$a == 1))
  print(i)

  V(g)$xyz = sapply(V(g), function(x) {
    NeighborList = neighbors(g, x)
    length(NeighborList[NeighborList$a == 2])
  })
  V(g)$a[V(g)$xyz == 1] = 2

  if (V(g)$a[i] == prev_value) {
    break
  }

  prev_value <- V(g)$a[i]
  i <- i + 1
}

This basically saves the value of the previous iteration and compares it to the value of the current iteration. If they're equal the loop breaks.


text:
Q: Define bbox for two different maps I have two different datasets:
library(tidycensus)
wp <- get_acs(geography = "tract", variable = "B02001_002",
                state = "NY",  county= "New York", geometry = TRUE, year = 2020)

bp <- get_acs(geography = "tract", variable = "B03002_004",
                state = "NY",  county= "New York", geometry = TRUE, year = 2020)

I would like to create a map, but I got this error message
bbox_w <- st_bbox(wp)
xrange <- bbox_w$xmax - bbox_w$xmin
yrange <- bbox_w$ymax - bbox_w$ymin
bbox_w[1] <- bbox_w[1] - (0.065 * xrange)
bbox_w[4] <- bbox_w[4] + (0.065 * yrange)
bbox_w <- bbox_w %>%
  st_as_sfc()

bbox_b <- st_bbox(bp)
xrange <- bbox_b$xmax - bbox_b$xmin
yrange <- bbox_b$ymax - bbox_b$ymin
bbox_b[1] <- bbox_b[1] - (0.065 * xrange)
bbox_b[4] <- bbox_b[4] + (0.065 * yrange)
bbox_b <- bbox_b %>%
  st_as_sfc()

white<-tm_shape(wp,bbox_w) + tm_fill("estimate")
black<-tm_shape(bp,bbox_b) + tm_fill("estimate")

tmap_arrange(white,black)

I want the maps next to each other, and same bbox for both maps, but got this
Error in vapply(g, function(i) i[[1]], character(1)) : values must be type 'character', but FUN(X[[2]]) result is type 'list'

Any suggestions?

A: Always try and test the steps you are taking to find where the problem first occurs. In this case I discovered the two maps, black and white are already broken so the tmap_arrange isn't going to work:
> black<-tm_shape(bp,bbox_b) + tm_fill("estimate")
> black
Error in vapply(g, function(i) i[[1]], character(1)) :
  values must be type 'character',
 but FUN(X[[2]]) result is type 'list'

So something is wrong with your construction of a simple tmap there. Let's see. How does tm_shape know you want that second argument to be the bounding box? Let's look at the help:
Usage:
     tm_shape(
       shp,
       name = NULL,
       is.master = NA,
       projection = NULL,
       bbox = NULL,
       unit = NULL,

oh, it doesn't think the second argument is the bbox, it thinks its the name. To specify the bbox, unless you also specify the args before it, you need to name the argument:
> black<-tm_shape(bp, bbox=bbox_b) + tm_fill("estimate")
> white<-tm_shape(wp, bbox=bbox_w) + tm_fill("estimate")
> tmap_arrange(black, white)


text:
Q: Why does this variable not grab a value? <?php
                #Show Recent Comments
                $theCommentID = $row['CommID'];
                echo "
Recent Comments
";
                if ($sth2->rowCount()) {
                while($row = $sth2->fetch(PDO::FETCH_ASSOC)) {
                    echo "
by {$row22['uname']} on {$row['date']} about {$row['prefix']} {$row['code']}   during  {$row['Qtr']},  {$row['Yr']}
                    Report
{$row['info']}
";
                    }
                }
                else {
                echo "
 No Comments Found, please add some below
";
                }
                unset($sth2);
?>

$pdo = new PDO('mysql:host=host;dbname=db', $u, $p);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
    SELECT name, lname, fname, picpath, email
    FROM Department, Professor
    WHERE pID = ?
    AND Department.dID = Professor.dID;
    ;');
$sth->execute(array(
    $pID
));
?>

<?php
// Get any professor comments currently present ON LOAD
$pID2 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
        $pdo2 = new PDO('mysql:host=host;dbname=db', $u, $p);
        $pdo2->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $sth2 = $pdo2->prepare('
SELECT C.cID, Co.CommID, prefix, code, info, date, Qtr, Yr
FROM Course C, Comment Co, Professor P
WHERE P.pID = ?
AND C.cID = Co.CName AND P.pID = Co.pID
ORDER BY Yr DESC;
             ');
        $sth2->execute(array(
            $pID2
        ));

?>
<?php
// Get the user of the comment
$pID22 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
        $pdo22 = new PDO('mysql:host=host;dbname=db', $u, $p);
        $pdo22->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $sth22 = $pdo22->prepare("
        SELECT uname FROM Student S, Comment C WHERE S.usrID = C.usrID and commID='$theCommentID';
             ");
        $sth22->execute(array(
            $pID22
        ));

?>

Why does {$row22['uname']} absolutely no value?
I've tried testing the sth22  query in the database to make sure it gave me what I needed before try this.

A: It doesn't appear as though $row22 is ever set a value to me.  From what I can tell, the 22 shouldn't be there on line 7.

A: It should just read...
{$row['uname']}

the 22 does not belong there.


text:
Q: 4k monitor isn't giving me the option for UHD I just bot a 4k monitor and i have a Nvidia Quadro k1200 that supposed to support 4 4K monitors at once. I have 4 monitors running at the same time. But the new 4k monitor, I still can't select a higher resolution than Full HD. I also installed the quadro drivers again and restarted the computer. didn't work.
It does look better up close even on Full HD. the other Full HD monitors i can see pixels up close. this one, i can't.


text:
Q: How can I elegantly create a hash from an array reference in Perl? I am looking for a more elegant way to create a hash that contains the list I have read in from my configuration file.  Here is my code:
read_config($config_file => my %config);

my $extension_list_reference = $config{extensions}{ext};

my @ext;

# Store each item of the list into an array

for my $i ( 0 .. (@$extension_list_reference - 1) ) {
    $ext[$i] = $extension_list_reference->[$i];
}

# Create hash with the array elements as the keys

foreach my $entry (@ext) {
    $extensions{$entry} = "include";
 }

Thanks.

A: Try using map:
http://perldoc.perl.org/functions/map.html
Here's what your new code should look like:
my %extensions = map { $_ => "include" } @{ $config{extensions}{ext} };

A: If I understand your problem, this is how you do it in one line:
@extensions{@$extension_list_reference} = ();

Note: each value of the hash is empty, but you still can check whether the key exists in the hash using function exists, like this:
if(exists $extensions{$some_key}) {...

P.S. If by some reason you really need those strings 'include' as values, you can have them, too:
@extensions{@$extension_list_reference} = ('include') x @$extension_list_reference;

A: my %hash = map { $_ => 'include' } @list;

A: This way:
read_config($config_file => my %config);
%extensions = map +($_ => "include"), @{$config{extensions}{ext}};

or this way:
read_config($config_file => my %config);
@extensions{@{$config{extensions}{ext}}} = ("include") x @{$config{extensions}{ext}};


text:
Q: Cleanup on termination of durable function Is it possibly to somehow get notified that the durable function as been or about to be terminated, such that it is possibly to initiate cleanup of the already finished activity functions for example? In my example we're sending multiple requests to a subsystem and need to revoke or refund the orders in case of the durable function is being terminated.

A: I don't believe that there is any way to subscribe to Terminatation events in Durable Functions, as the Durable Task Framework handles this before user code is ever invoked.
One option instead of using the explicit terminate API built into Durable Functions is to instead listen to some CustomTerminate event within your orchestration, using a Task.WhenAny() approach whenever you schedule an activity or suborchestration. Then, if you ever receive this CustomTerminate event instead of the Activity or SubOrchestration response, you could manually handle the cleanup at this point.


text:
Q: Graceful handling of SIGTERM (Ctrl-c) and shutdown a Threadpool Currently, I am at the last chapter of the rust book, implementing the graceful shutdown of the HTTP server.
Now I want to extend the logic a bit and trigger the graceful shutdown after pressing Ctrl-c. Therefore I use the ctrlc crate.
But I cannot make it work due to various borrowing checker errors:
fn main() {
    let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
    let pool = ThreadPool::new(4);

    ctrlc::set_handler(|| {
        // dropping will trigger ThreadPool::drop and gracefully shutdown the running workers
        drop(pool); // compile error, variable is moved here
    })
    .unwrap();

    for stream in listener.incoming() {
        let stream = stream.unwrap();

        pool.execute(|| {
            handle_connection(stream);
        });
    }
}

I tried multiple approaches with Arc<> and additional mpsc channels, but without success.
What is the best practice here in order to make it work?

A: I ended up with:
fn main() {
    let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
    let pool = ThreadPool::new(4);

    let (tx, rx) = channel();

    ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
        .expect("Error setting Ctrl-C handler");

    for stream in listener.incoming() {
        let stream = stream.unwrap();

        pool.execute(|| {
            handle_connection(stream);
        });

        match rx.try_recv() {
            Ok(_) => break,
            Err(_) => continue,
        }
    }
}

It has a flaw though. Namely after pressing Ctrl-c the shutdown process is not triggered immediately, but only after receiving another request. Then the loop will break and the ThreadPool goes out of scope and gets dropped which triggers the graceful shutdown logic.
The solution is adequate for my learning purposes. In a production environment, one would rely on the graceful shutdown from a web-framework like actix


text:
Q: Error in gmv_opt with PortfolioAnalytics package in r I have a returns xts object like
retornos_categorias <- an xts object with 20 columns where each column is a return vector

assets <- colnames(retornos_categorias)
portfolio.init <- portfolio.spec(assets)
portfolio.init <- add.constraint(portfolio.init, type = "full_investment")
portfolio.minSD <- add.objective(portfolio = portfolio.init, type="risk", name="StdDev")

portfolio.minSD.opt <- optimize.portfolio(retornos_categorias, portfolio = portfolio.minSD, optimize_method = "ROI_old", trace = TRUE)

When I use optimize.portfolio from PortfolioAnalytics package I get this error:
Error in gmv_opt(R = R, constraints = constraints, moments = moments,  :
  paste0("package:", plugin) %in% search() || requireNamespace(plugin,  .... is not TRUE

Someone else get this error? someone knows why I get that and how to fix it?
Thanks!

A: You very likely miss (i.e. need to install) a package, such as ROI or one of its plugins.  But without a more complete example, it is hard to tell.

Response to the update: It's still not a reproducible example.  You don't show the data, and you don't load/attach the required packages. Here is a reproducible example, and it works on my system. "It works" here means that it runs without an error; I did not inspect the results.
As data, I use a dataset from Kenneth French's website. Try to debug your code and find out what value plugin has; it should be the name of the missing package.
library("NMOF")
library("PortfolioAnalytics")
library("xts")

R <- French(tempdir(), "17_Industry_Portfolios_CSV.zip")
R <- as.xts(R, as.Date(row.names(R)))
R <- window(R, start = as.Date("2000-01-01"))

retornos_categorias <- R
assets <- colnames(retornos_categorias)
portfolio.init <- portfolio.spec(assets)
portfolio.init <- add.constraint(portfolio.init,
                                 type = "full_investment")
portfolio.minSD <- add.objective(portfolio = portfolio.init,
                                 type = "risk",
                                 name = "StdDev")

portfolio.minSD.opt <- optimize.portfolio(retornos_categorias,
                                          portfolio = portfolio.minSD,
                                          optimize_method = "ROI_old",
                                          trace = TRUE)

The function sessionInfo tells you what R and package versions have been used.
> sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.1 LTS
##
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-openmp/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-openmp/liblapack.so.3
##
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
##  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_US.UTF-8
##  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_US.UTF-8
##  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base
##
## other attached packages:
## [1] PortfolioAnalytics_1.1.0   PerformanceAnalytics_2.0.4
## [3] foreach_1.5.0              xts_0.12-0
## [5] zoo_1.8-8                  NMOF_2.2-0
##
## loaded via a namespace (and not attached):
## [1] datetimeutils_0.4-1 compiler_4.0.2      tools_4.0.2
## [4] parallel_4.0.2      codetools_0.2-16    grid_4.0.2
## [7] iterators_1.0.12    lattice_0.20-41     quadprog_1.5-8


text:
Q: Redis - Get the aggregated score from three sorted set i have three sorted sets:
setA {play1: 100, play2: 150, play3: 230}
 setB {play1: 120, play4: 100, play5: 200}
 setC {play1: 110, play3: 150, play5: 30}
Is it possible to get an aggregated result (sum the score for the same user in different sets and display all of users scores in the result) of the three sorted sets?
thanks!

A: ZUNIONSTORE setSetSetAllMySets 3 setA setB setC AGGREGATE sum

sum happens to be the default aggregation and therefore isn't strictly necessary. I just wanted to get you interested in what other aggregations are available.
http://redis.io/commands/zunionstore


text:
Q: Can I update the service on ArcGIS for Server programmatically? There is Windows Service. This service adds user raster data to the Raster Dataset in sde database.
The Raster Dataset registred on the ArcGis Server. This Raster Dataset also was publishing on ArcGis Server. When the user data has been added to this Raster Dataset, the data is not updated on ArcGis Service.
How update service on the ArcGis Server from my Windows Service? (I know IP address, password, and service name)

A: Here are some troubleshooting steps:
First, check to see if the published map service is cached or not.

*

*If the map service is cached, then you will need to update the cache in order to see the changes on the ArcGIS service.

*you will then need to create a script that will update the cache whenever new data is added to the raster database.

If the map service is not cached, the newly added raster data should be drawn automatically.  If it is still not showing up:

*

*open the MXD that was used to publish the map service

*check to make sure the MXD pointing to the correct database

*check to make sure that updated raster data that has been successfully loaded from the script (it might be a scripting error)


text:
Q: SwipeRefreshLayout not visible after the scroll down of RecyclerView My layout file
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayoutColleague"
    android:layout_below="@+id/main_header_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.ms.engage.utils.recycler.EmptyRecyclerView
        android:id="@+id/colleagues_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>

code
swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipeRefreshLayoutColleague);
swipeRefreshLayout.setColorSchemeResources(R.color.pull_to_refresh);
swipeRefreshLayout.setOnRefreshListener(this);


text:
Q: Strugguling to make a kivy application that add, sub, multiply, divide two input when a checkbox is active. Can somebody help me? I need to make an application consisting of a window.  In its upper half, this window has 2 text boxes and a button, aligned horizontally.
If you enter two numbers, one in each of the text boxes, and press the button, an operation of these two numbers is displayed in the lower half of the screen.
In the middle of the screen, 4 checkboxes (addition, subtraction, multiplication or division) to define the operation on the 2 numbers.
If one of the two numbers is not a digit, an error message is displayed.
from kivy.app import App
from kivy.config import Config
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.checkbox import CheckBox

class MyApp(App):
    def __init__(self, **kwargs):
        super().__init__()
        self.a = None
        self.b = None
        self.button = None
        self.display = None

    def build(self):
        self.title = 'Addition'

        """------------------------------------------------"""
        calc = BoxLayout(orientation='horizontal')

        self.a = TextInput(multiline=False)
        calc.add_widget(self.a)

        calc.add_widget(Label(text='+', font_size=20))

        self.b = TextInput(multiline=False)
        calc.add_widget(self.b)

        self.button = Button(text='Entrer', font_size=20)
        self.button.bind(on_press=self.add_numbers)
        calc.add_widget(self.button)
        """------------------------------------------------"""
        check = BoxLayout(orientation='horizontal')

        check.add_widget(CheckBox(group='op'))
        check.add_widget(Label(text='add'))
        check.add_widget(CheckBox(group='op'))
        check.add_widget(Label(text='sub'))
        check.add_widget(CheckBox(group='op'))
        check.add_widget(Label(text='mult'))
        check.add_widget(CheckBox(group='op'))
        check.add_widget(Label(text='div'))
        """------------------------------------------------"""
        display = BoxLayout(orientation='horizontal')
        self.display = Label(text='Result: ')
        display.add_widget(self.display)
        """------------------------------------------------"""

        box = BoxLayout(orientation='vertical')
        box.add_widget(calc)
        box.add_widget(check)
        box.add_widget(display)

        return box

    def add_numbers(self, instance):
        num1 = self.a.text
        num2 = self.b.text
        try:
            somme = float(num1) + float(num2)
            self.display.text = "Result: " + str(somme)
        except ValueError:
            self.display.text = "Erreur, vous devez entrer des chiffres."

Config.set('graphics', 'width', '350')
Config.set('graphics', 'height', '50')

if __name__ == '__main__':
    MyApp().run()

That's my program at the moment.
I've been trying to link the checkboxes to the function but without success
Can somebody help me?


text:
Q: Talend - Need server environment variables instead of local machine I'm using talend enterprise edition, I'm trying to use system environment variables as parameters for my jobs. when using system.getenv("paramname") and runnig the job, I'm getting the values from my local machine. what I need to do to to get the values from the talend server machine. The idea is to centrally add all the parameters as environment variables in the talend server and all users should use those env variables as parameters. any input is appreciated.

A: Instead of system.getenv("paramname"), please use system.getProperty("paramname"). As system.getenv() is deprecated
Hope this helps...

A: This thread might also be of use as it could be used to accomplish similgar goals  Reading properties from an external file . I included screenshots and description in that answer.
This is a similar approach, but allows placing a common.properties (or other named file) for all Talend jobs running on that same job server to use. This also makes it easy to have different Talend job servers (dev, qa, production, etc), where the same jobs are installed, but they pull their correct settings from the common property file (environment dependent).
It uses the components tFileInputDelimited and tContextLoad to accomplish the task.


text:
Q: Angular scope watch doesn't work in my app I've got the following code where I'm trying to show/hide a text box based on if a key was pressed in the global window scope. However, every time a key is pressed, it does not seem to fire the watch service. Why is this?
Plnkr here http://plnkr.co/edit/qL9ShNKegqJfnyMvichk
app.controller('MainCtrl', function($scope, $window) {
 $scope.name = '';

angular.element($window).on('keypress', function(e) {
//this changes the name variable
$scope.name = String.fromCharCode(e.which);
 console.log($scope.name)
})

$scope.$watch('name', function() {
 console.log('hey, name has changed!');
 });
});

A: It is because you are handling the keypress event outside of the digest cycle. I would strongly encourage you to let angular do its thing with databinding or using  ngKeypress
Otherwise, in your handler, call $scope.$digest().
angular.element($window).on('keypress', function(e) {
    //this changes the name variable
    $scope.name = String.fromCharCode(e.which);
    console.log($scope.name);
    $scope.$digest();
})

A: On a high level view, watching a value on a scope needs two parts:
First: the watcher - like you created one. Every watcher has two parts, the watch function (or like here the value) and the listener function. The watch function returns the watched object, the listener function is called when the object has changed.
Second: the $digest cycle. The $digest loops over all watchers on a scope, calls the watch function, compares the returned newValue with the oldValue and calls the corresponding listener function if these two do not match. This is called dirty-checking.
But someone has to kick the $digest. Angular does it inside its directives for you, so you don't care. Also all build-in services start the digest. But if you change the object outside of angular's control you have to call $digest yourself, or the preferred way, use $apply.
$scope.$apply(function(newName) {
$scope.name = newName;

});
$apply first evaluates the function and then starts the $digest.
In your special case, I would suggest to use ngKeypress to do it the angular way.


text:
Q: NetBeans IDE Error: java.lang.ClassNotFoundException while creating java project I get this error each time I create a java project.
I have tried different versions of JDK and gives the same error note that my IDE is latest update.
Here is the error code.
java.lang.ClassNotFoundException: com.sun.tools.javac.code.Symbol starting from ModuleCL@721c5d4e[org.netbeans.modules.java.source.base] with possible defining loaders null and declared parents [ModuleCL@2acc77b3[org.netbeans.api.java], ModuleCL@661b3a59[org.netbeans.libs.javacapi], ModuleCL@2ec50621[org.netbeans.modules.java.lexer], ModuleCL@7698b66a[org.netbeans.modules.editor.mimelookup], ModuleCL@47bc164[org.netbeans.modules.refactoring.api], ModuleCL@2bfed89a[org.netbeans.api.annotations.common], ModuleCL@4384ac5a[org.netbeans.modules.parsing.api], ModuleCL@2d977913[org.netbeans.modules.lexer], org.netbeans.MainImpl$BootClassLoader@34c45dca, ModuleCL@64102b49[org.netbeans.modules.java.platform], ...20 more]
at org.netbeans.ProxyClassLoader.doFindClass(ProxyClassLoader.java:215)
at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:125)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
Caused: java.lang.NoClassDefFoundError: com/sun/tools/javac/code/Symbol
at org.netbeans.modules.java.api.common.classpath.ModuleClassPaths$ModuleInfoClassPathImplementation.lambda$getModulesByName$22(ModuleClassPaths.java:1134)

Thank you in advance for your help!

A: I had the same problem and was able to solve it in windows by following the steps below:

*

*Uninstall Netbeans 12.4. Make sure to delete all the cache files (Drive:\users<user>\AppData\Roaming\Netbeans and Drive:\users<user>\AppData\Local\Netbeans) (Windows)

*Check your JDK directory (no JRE) and environment variables JAVA_HOME, CLASSPATH and PATH.

*Install Netbeans 12.4

*Create new project and check that you select Download and activate nb-javac.


text:
Q: Recovering a degraded RAID array I was just given an external hard drive by a colleague, with the comment "Hey, you're running Ubuntu. Maybe you can recover some of the data from this really old disk that nobody knows who last used?" (OK, that's not really what he said, but that's just about as much information I have at hand at the moment...)
I plugged in the disk in my computer, and discovered it was RAID1-configured. I've never worked with RAID-configurations before. After some googling and trying to figure out what to do to be able to read this disk, I've gathered the following information: http://pastebin.com/KZHAj7U9
What might be most interesting is the following excerpt:
tlycken@hoth ~ $ sudo mdadm -E /dev/sdb2
...
      Number   Major   Minor   RaidDevice State
this     0       8       18        0      active sync   /dev/sdb2

   0     0       8       18        0      active sync   /dev/sdb2
   1     1       0        0        1      faulty removed

There are two other partitions (sdb3 and sdb5) that report similar tables, but they both report "active sync" for the state on all three rows. So this partition seems to be the troublesome one.
If I open the Disk Utility GUI, I see the following, after trying to start the RAID array:

When I pressed the little play button at the top right (which is a stop button in this screenshot) I get the following error message:

Error starting RAID array
Error starting RAID array: Command-line `mdadm --assemble  --scan --uuid "866221ac:fd8d56af:aceaa1c2:25d2b442"' exited with non-zero exit status 2: mdadm: /dev/md2 has been started with 1 drive (out of 2).
(udisks-error-quark, 0)

All I can understand from this is that it seems that part of the RAID array is missing - however, I have no idea if the missing part is some partition on the disk I have in front of me (i.e. something I could probably configure to make it work) or on another physical disk (which I have little or no hope of being able to get my hands on).
How do I configure and mount this array so that i can read the data (read-only is fine)?

A: First things first: I would recommend making a bit copy of the disk, e.g. using ddrescue, and then working on the disk image, not on the physical disk. This might save you some headache if the disk suddenly dies on you - if it hasn't been used for a while, I would consider its fitness questionable at best.
That said, RAID 1 is a mirroring scheme - in other words, all the disks contain all the data; thus it is possible to recover data even if only a single functional disk is present.
What you see here is mdadm complaining that the array is supposed to contain 2 disks, therefore it marks the array degraded (there's something wrong with it, namely, only 1 disk is present out of 2). However, since the available disk seems to contain good data (it says sync, meaning "this disk is synced correctly to the current state of the array") you can still assemble it in degraded mode by adding the --force parameter:
mdadm --assemble --scan --uuid "866221ac:fd8d56af:aceaa1c2:25d2b442" --force

This should assemble the array even with a single disk; then you can mount the array normally, and access the data as you usually would.


text:
Q: How to toggle class on table tr's I have multiple tables on a page.
For each table, I want to be able to toggle a class on the click of the tr.
So far this is what I have for js:
 $(document).ajaxSuccess(function () {
 $("table tr").click(function () {

     if ($(this).closest("table tr").hasClass("selected_row"))
     { $(this).closest("table tr").removeClass("selected_row"); }

     else { $(this).closest("table tr").addClass("selected_row"); }
 });
});

Now the issue I'm having is that when I click on a second tr within this table, the previous row keeps the class that was added to it. How can I make it so that on any table, only 1 tablerow may have this class at a time.
Also not, there are sometime multiple tables on the page, so the solution needs to be relevant only to the table being clicked, not all tables on page.
Thanks,
Mark

A: Closest gets the parent of your selector, this is already table tr, try this :
   if ($(this).hasClass("selected_row")) {
       $(this).removeClass("selected_row");
   } else {
       $(this).addClass("selected_row");
       $(this).siblings().removeClass('selected_row');
   }

A: There is no need to add an onclick handler to every table row. Use event bubbling to your advantage. Use siblings to get the one that has the class if it exists.
$("table tbody").on("click", "tr", function() {
    var row = $(this);
    row.toggleClass("selected_row");
    row.siblings("selected_row").removeClass("selected_row");
});


text:
Q: Wreath product (Rotman, p.173) I have a question about the explanation of wreath product in Rotman's "An introduction to the theory of groups (4th ed.)."
Let $D$ and $Q$ be groups, $\Lambda$ be a $D$-set, $\Omega$ be a finite $Q$-set. For each $q \in Q$, define a permutation $q^\ast$ of $\Lambda \times \Omega$ by $ q^\ast(\lambda, \omega) = (\lambda, q\omega) $ and define $Q^\ast = \{\, q^\ast \mid q \in Q \,\}$.
The book says that the map $Q \to Q^\ast,~q \mapsto q^\ast$ is an isomorphism. The fact that this map is homomorphism and surjective comes almost immediately from its definition. I have a trouble to show that this map is injective.
Here is my attempt. Assume that $q^\ast = \operatorname{id}$. For a fixed $\lambda \in \Lambda$ and for any $\omega \in \Omega$,
$$ (\lambda, \omega) = \operatorname{id}(\lambda, \omega) = q^\ast(\lambda, \omega) = (\lambda, q\omega)$$
and conclude that $q = \operatorname{id}_\Omega$. But I think this means that $q$ belongs to the intersection of all the stabilizers and doesn't mean $q = 1_Q$. What am I missing?


text:
Q: Iterating over a collection with multiple types - how do I use type-specific attributes? I want to iterate over a collection that contains objects of various types.  If I want to use a common attribute, it's easy because I don't have to test for type -- they all respond.
But what if I want to use a type-specific attribute?  How should I go about this so that my code is nice and clean?
Do I just have one big if-elseif statement that I update every time I add a new type?
The code example below is Ruby on Rails, but the question applies to any language that supports polymorphism.
class Person < ActiveRecord::Base
  has_many :events
  has_many :meals, :through => :events, :source => :eventable,
    :source_type => "Meal"
  has_many :workouts, :through => :events, :source => :eventable,
    :source_type => "Workout"
end

Then I iterate:
p = Person.find(1)

p.eventable.each do |e|
  if e.meal?
    puts e.food_type
  elsif e.workout?
    puts e.repetitions
  elsif {...}
end

The above seems brittle.  Is there a better way?


text:
Q: VS Code jsconfig advance alias glob paths I am trying to configure my VS Code React project and for doing so I have created a jsconfig with the following structure:
{
  "compilerOptions": {
      "module": "commonjs",
      "target": "es2019",
      "jsx": "react",
      "baseUrl": ".",
      "paths": {
        "@Reducers/*": ["./src/reducers/*"],
        "@Selectors/*": ["./src/selectors/*"],
        "@Components/*": ["./src/components/*"],
        "@App/*": ["./src/components/App/*"],
        "@Loader/*": ["./src/components/Loader/*"]
    }
  },
  "include" : ["src/**/*"],
  "exclude": ["node_modules", "dist", "config", ".vscode"]
}

The problem is that this only works if I import something like
import Blabla from "@Loader/blabla"

If I do the below, peek definition and things like that does not work:
import BlablaDefault from "@Loader"

To have this working I have to add an extra line in my paths definitions, so I have to have:
"@Loader": ["./src/components/Loader"]
"@Loader/*": ["./src/components/Loader/*"]

Is there a way to get this in one line instead of two? Also, I imagine that if I have more nested components I would need to do something similar...
Kind of:
import Deep from "@DeepStuff/blabla1/blabla2/blabla3"

How would the glob expression be in this case?
Thank you in advance and regards.


text:
Q: How to use query function of hashmap in mutate of dplyr pipe in R? I would like to find a value using a hashmap and then use this value to calculate a new one. Usually I try to work efficiently, but I am not very proficient in R. I know the basics of dplyr pipes, so do no longer want to use for loops.
Here is a minimal reproducable example of the situation:
data("mtcars")

m.subset <- mtcars[2:7, 10:11]
letters <- c("a", "b", "c", "d", "e", "f")
m.subset <- cbind(m.subset, letters)

testmap <- hashmap()
testmap[c("a", "b", "c", "d", "e", "f")] <- c(4.0, 5.0, 6.0, 7.0, 8.0, 9.0)

m.subset %>% mutate(score1=query(testmap, letters)*gear) -> m.subset

Unfortunately, I get this error:
Error in `mutate()`:
! Problem while computing `score1 = query(testmap, letters) * gear`.
✖ `score1` must be size 6 or 1, not 0.
Run `rlang::last_error()` to see where the error occurred.

A note is that this works: score1=query(testmap, m.subset$letters[1])*m.subset$gear[1], where I can obviously interchange the 1 with an i and use a for loop. But I prefer not to, as a dplyr pipe is so nice to do columnwise calculations.
I also read several questions on StackOverflow, like error-in-r-mutate-must-be-size-4-or-1-not-0.

A: Assuming you are using r2r for hashmap and query, you can try the following. Using map2 from purrr you can go through each element of letters and gear, and apply the function query using your testmap.
library(tidyverse)
library(r2r)

m.subset %>%
  mutate(score1 = map2(
    letters,
    gear,
    ~ query(testmap, .x) * .y
  ))

Output
                  gear carb letters score1
Mazda RX4 Wag        4    4       a     16
Datsun 710           4    1       b     20
Hornet 4 Drive       3    1       c     18
Hornet Sportabout    3    2       d     21
Valiant              3    1       e     24
Duster 360           3    4       f     27


text:
Q: Multiple plots on same figure x = [0.35, 0.65, 0.8, 1]
y1 = [0.1, 0.21, 0.29, 0.35]
y2 = [0.11, 0.26, 0.28, 0.39]
y3 = [0.1, 0.2, 0.28, 0.36]
y4 = [0.1, 0.25, 0.31, 0.37]

I need to plot all this data on the same graph, such that there is one x-axis and two y-axes, one on the left and one on the right. The interval for y-axes is 0.1:0.1:0.4, and that for x-axis is 0:0.1:1.
I have tried plotyy:
[ax, h1, h2] = plotyy(x, y2, x, y4);
hold on
[bx, h3, h4] = plotyy(x, y3, x, y1);

but one of the vectors does not plot on the same graph. When you run this, and use the PAN option on the graph, you'll realize that only 3 curves are plotted while the 4th curve is plotted on another figure. When I check the legend U get only 3 curves, and not 4.

A: How about something like this:
plot(x, [y1(:) y2(:) y3(:) y4(:)])
legend({'y1' 'y2' 'y3' 'y4'}, 'Location','NorthWest')
set(gca, 'XLim',[0 1], 'YLim',[0.1 0.4])

A: Skip the hold and use
[ax, h1, h2] = plotyy(x, [y2;y3], x, [y4;y1]);

Edit:
This is kind of a hack since it is does not support data sets were x differ. That is y2 and y3 should be specified for the same x. The same is true for y4 and y1.


text:
Q: How change UTC time to Europe/Helsinki in SQL to make it working via Excel connection I am working in Oracle server and want to run the following query inside excel workbook
Select current_timestamp, FROM_TZ(CAST(current_timestamp AS TIMESTAMP), 'UTC') at time zone 'Europe/Helsinki'
from
  MYDB OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY

When I ran SQL in SQL Workbench, everything works perfectly, but when I try to create a connection to Oracle server from Excel and run the same query I have the following error in the workbook

As I understood, my driver does not read FROM_TZ(CAST(..))) function in Excel. How Can I  modify my query to start working in Excel?
Driver is Oracle in OraClient11g_home1 (64 bit)
UPDATE:
This error also comes if I use the following functions in Excel:
cast(DATA_DTTM as timestamp) AT TIME ZONE 'UTC' as utc
FROM_TZ(CAST(DATA_DTTM AS TIMESTAMP), 'UTC')
FROM_TZ(CAST(DATA_DTTM AS TIMESTAMP), 'UTC') at time zone 'Europe/Helsinki'

I want to tell that the certain timestamp column is in UTC format and then convert it to 'Europe/Helsinki', but Excel does not read AT TIME ZONE 'UTC' and FROM_TZ() (I tried to run them in Excel separately) + the same issue with TO_TIMESTAMP_TZ() function
Before I used Vertica and this manipulation was done by cast(DATA_DTTM as timestamp) AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Helsinki' as utc
The code I used:
select
cast(DATA_DTTM as timestamp) AT TIME ZONE 'UTC' as utc
FROM_TZ(CAST(DATA_DTTM AS TIMESTAMP), 'UTC')
FROM_TZ(CAST(DATA_DTTM AS TIMESTAMP), 'UTC') at time zone 'Europe/Helsinki'
from MYDB

Are there any alternative ways to set timestamp timezone and then convert it to another timezone?

A: In deed, looks like the Oracle ODBC driver does not support TIMESTAMP WITH TIME ZONE data type. See Using the Oracle ODBC Driver.
You need to cast the value to a plain TIMESTAMP value. And you must use column alias. This code works for me:
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset

   con.Open "DRIVER={Oracle in OraClient12Home1_32bit};SERVER=dbname;UID=MYUSER;PWD=***secret***;DBQ=dbname"
   cmd.ActiveConnection = con
   cmd.CommandType = adCmdText

   cmd.CommandText = _
      "SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP) as col_1, " & _
          "CAST(FROM_TZ(CAST(CURRENT_TIMESTAMP AS TIMESTAMP), 'UTC') AT TIME ZONE 'Europe/Helsinki' AS TIMESTAMP) as col_2 " & _
      "from MYDB " & _
      "OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY"

   Set rs.Source = cmd
   rs.CursorType = adOpenStatic
   rs.Open

   Do Until rs.EOF
      Debug.Print rs(0).Value, rs(1).Value
      rs.MoveNext
   Loop
   rs.Close
   con.Close

Another solution is to use the Oracle OLE DB provider instead of ODBC. The connection string would be
con.Open "Provider=OraOLEDB.Oracle;Data Source=dbname;User Id=MYUSER;Password=***secret***"

All others would remain the same.
The OLE DB provider supports TIMESTAMP WITH TIME ZONE, however it makes an implicit cast to TIMESTAMP, i.e. you will not get any time zone information. See TIMESTAMP Data Types


text:
Q: Python:Find if all elements in lists are the same except exactly 2 numbers I wonder how to check if two lists of numbers are the same except exactly 2 numbers
if list1 == list2: # + except 2 numbers

A: def differ_by_two(l1, l2):
    return sum(1 for i,j in zip(l1, l2) if i!=j) == 2

Example
>>> differ_by_two([1,2,3],[1,4,5])
True
>>> differ_by_two([1,2,3,4,5],[6,7,8,9,10])
False

A: If order of list elements is important, you can use something like this:
if sum(i != j for i, j in zip(list1, list2)) == 2:
    # the two lists are equal except two elements

If order is not important, and repeated elements do not matter, you could also use set intersection (&) and compare length:
if len(set(list1) & set(list2)) == len(list1) - 2:
    # the two list are equal except two elements

If order is not important, but repeated elements matter, use the same approach, but with collections.Counter:
from collections import Counter
if len(Counter(list1) & Counter(list2)) == len(list1) - 2:
    # the two list are equal except two elements

A: def SameBarTwo(l1, l2):
    a = len(l2)
    for i in range(len(l2)):
        if l2[i] in l1:
            l1.remove(l2[i])
            a -= 1
    return a == 2

This will make accommodations for duplicate values, order is not taken into account.


text:
Q: MVC4 Ajax Form URL Is there a way to set the URL for an asp.net-mvc-4 AJAX form? I am looking for an answer using the Ajax.BeginForm() syntax so that i can make use of Microsoft's model construction sorcery without needing to re-parse the url string myself.
There is a partial view that lives on foo.com.au/getFoo which has an ajax form in it. the ajax form will post to Foo controller (default), getFoo action.
When i am calling this from an external site (bar.com.au) i want it to post back to foo.com.au/getFoo. Instead it is posting to bar.com.au/getFoo. Is there some way to tell the Ajax Form to post to the full URL instead of just the relative path?
Motive
For those of you who suspect hax0rz or other foul play, i have built a widget which is being integrated across multiple client sites. I am now building an authentication plugin for this widget. The widget does not redirect them to my website for authentication, therefore i want it to post back to my domain with the results of the username/password input form.

A: You need to pass it in through the Ajax-options instead of supplying it in the overloaad of BeginForm:
@using (Ajax.BeginForm(
    new AjaxOptions
    {
        Url = Url.Action("getFoo", "Foo", null, Request.Url.Scheme)
    }))
{
    ...
}


text:
Q: How to create a tree list in Angular with ajax loading of each new layer? I'm new to Angular and trying to wrap my brain around how to do stuff.
I'm trying to create a list that's populated on page load by an ajax call to a REST API service, and the elements of that list would fire ajax calls to that same service when clicked on that populated sub-lists below those elements, and so on to depth n.
The initial population of the list is easy: the controller makes the ajax call, gets the JSON object, assigns it to scope and the DOM is handled with a ng-repeat directive. I'm having trouble with the subsequent loading of the sub-lists.
In jQuery, I would have a function tied to each appropriately classed element clicked upon via onClick which would get the required parameters, take the JSON output, parse it into HTML and append that HTML after the element which fired the event. This is direct DOM manipulation and therefore Angular heresy.
I've already looked at this question here, but I still don't quite understand how to implement something like this "the Angular way".
Help?
Edit: Solved this problem by making a recursive directive. Instructions from here: http://jsfiddle.net/alalonde/NZum5/light/.
Code:
    var myApp = angular.module('myApp',[]);

    myApp.directive('uiTree', function() {
      return {
        template: '
<ui-tree-node ng-repeat="node in tree"></ui-tree-node>
',
        replace: true,
        transclude: true,
        restrict: 'E',
        scope: {
          tree: '=ngModel',
          attrNodeId: "@",
          loadFn: '=',
          expandTo: '=',
          selectedId: '='
        },
        controller: function($scope, $element, $attrs) {
            $scope.loadFnName = $attrs.loadFn;
          // this seems like an egregious hack, but it is necessary for recursively-generated
          // trees to have access to the loader function
          if($scope.$parent.loadFn)
            $scope.loadFn = $scope.$parent.loadFn;

          // TODO expandTo shouldn't be two-way, currently we're copying it
          if($scope.expandTo && $scope.expandTo.length) {
            $scope.expansionNodes = angular.copy($scope.expandTo);
            var arrExpandTo = $scope.expansionNodes.split(",");
            $scope.nextExpandTo = arrExpandTo.shift();
            $scope.expansionNodes = arrExpandTo.join(",");
          }
        }
      };
    })
    .directive('uiTreeNode', ['$compile', '$timeout', function($compile, $timeout) {
      return {
        restrict: 'E',
        replace: true,
        template: '
' +
          '
' +
            '' +
            '{{ node.name }}' +
            '' +
                '{{ node.name }}' +
          '
' +
        '
',
        link: function(scope, elm, attrs) {
          scope.nodeId = function(node) {
            var localNode = node || scope.node;
            return localNode[scope.attrNodeId];
          };
          scope.toggleNode = function(nodeId) {
            var isVisible = elm.children(".uiTree:visible").length > 0;
            var childrenTree = elm.children(".uiTree");
            if(isVisible) {
              scope.$emit('nodeCollapsed', nodeId);
            } else if(nodeId) {
              scope.$emit('nodeExpanded', nodeId);
            }
            if(!isVisible && scope.loadFn && childrenTree.length === 0) {
              // load the children asynchronously
              var callback = function(arrChildren) {
                scope.node.children = arrChildren;
                scope.appendChildren();
                elm.find("a.icon i").show();
                elm.find("a.icon img").remove();
                scope.toggleNode(); // show it
              };
              var promiseOrNodes = scope.loadFn(nodeId, callback);
              if(promiseOrNodes && promiseOrNodes.then) {
                promiseOrNodes.then(callback);
              } else {
                  $timeout(function() {
                      callback(promiseOrNodes);
                  }, 0);
              }
              elm.find("a.icon i").hide();
              var imgUrl = "http://www.efsa.europa.eu/efsa_rep/repository/images/ajax-loader.gif";
              elm.find("a.icon").append('');
            } else {
              childrenTree.toggle(!isVisible);
              elm.find("a.icon i").toggleClass("icon-chevron-right");
              elm.find("a.icon i").toggleClass("icon-chevron-down");
            }
          };

          scope.appendChildren = function() {
            // Add children by $compiling and doing a new ui-tree directive
            // We need the load-fn attribute in there if it has been provided
            var childrenHtml = '<ui-tree ng-model="node.children" attr-node-id="' +
                scope.attrNodeId + '"';
            if(scope.loadFn) {
              childrenHtml += ' load-fn="' + scope.loadFnName + '"';
            }
            // pass along all the variables
            if(scope.expansionNodes) {
              childrenHtml += ' expand-to="expansionNodes"';
            }
            if(scope.selectedId) {
              childrenHtml += ' selected-id="selectedId"';
            }
            childrenHtml += ' style="display: none"></ui-tree>';
            return elm.append($compile(childrenHtml)(scope));
          };

          scope.css = function() {
            return {
              nodeLabel: true,
              selected: scope.selectedId && scope.nodeId() === scope.selectedId
            };
          };
          // emit an event up the scope.  Then, from the scope above this tree, a "selectNode"
          // event is expected to be broadcasted downwards to each node in the tree.
          // TODO this needs to be re-thought such that the controller doesn't need to manually
          // broadcast "selectNode" from outside of the directive scope.
          scope.setSelected = function(node) {
            scope.$emit("nodeSelected", node);
          };
          scope.$on("selectNode", function(event, node) {
            scope.selectedId = scope.nodeId(node);
          });

          if(scope.node.hasChildren) {
            elm.find("a.icon").append('');
          }

          if(scope.nextExpandTo && scope.nodeId() == parseInt(scope.nextExpandTo, 10)) {
            scope.toggleNode(scope.nodeId());
          }
        }
      };
    }]);

    function MyCtrl($scope, $timeout) {
        $scope.assets = [
            { assetId: 1, name: "parent 1", hasChildren: true},
            { assetId: 2, name: "parent 2", hasChildren: false}
        ];
        $scope.selected = {name: "child 111"};
        $scope.hierarchy = "1,11";
        $scope.loadChildren = function(nodeId) {
            return [
                {assetId: parseInt(nodeId + "1"), name: "child " + nodeId + "1", hasChildren: true},
                {assetId: parseInt(nodeId + "2"), name: "child " + nodeId + "2"}
            ];
        }
        $scope.$on("nodeSelected", function(event, node) {
            $scope.selected = node;
            $scope.$broadcast("selectNode", node);
        });
    }

Template:

      <ui-tree ng-model="assets" load-fn="loadChildren" expand-to="hierarchy" selected-id="111" attr-node-id="assetId"></ui-tree>

selected: {{ selected.name }}

A: Here's a solution which I prototyped for my own use.
https://embed.plnkr.co/PYVpWYrduDpLlsvto0wR/
Link updated


text:
Q: Word for aliasing globals or properties as local variables for better compression For the last few weeks, I've had a maddening case of "tip-of-the-tongue" syndrome concerning a colloquial verb I read a while ago while digging through uncompressed JavaScript.
At the top of the module's closure, the author had assigned commonly used values like true to a JavaScript variable named "TRUE", false to a variable named "FALSE", and similar transformations applied to other suspects. In a comment, the author had written something along the lines of "Here we'll ******* some commonly used variables for better minification". I vaguely remember it sounding something like, uhm... "kludge" or something like that...? Was ages ago.
Either way, I see this practice all the time with scripts the size of Olympus Mons, I just wish I remembered the damn word... :(
EDIT: Yeah, okay, it definitely wasn't "kludge", but I vaguely remember it having a similar phonetic structure.
This is starting to keep me up at night...

A: GOT IT!!!! I knew it ended in a "-ge"...
The word is munge.

The term was coined in 1958 in the Tech Model Railroad Club at the
  Massachusetts Institute of Technology. In 1960 the backronym "Mash
  Until No Good" was created to describe Mung, and a while after it was
  revised to "Mung Until No Good", making it one of the first recursive
  acronyms. It lived on as a recursive command in the editing language
  TECO.

BRB, getting that tattooed somewhere accessible.


text:
Q: What is best way to save user's data to carry through the website pages in PHP? What is the best way to carry users data through the pages(php)? Currently, I use sessions to hold and use data like username, lastlogin, password, purchased items and ... between the website pages.
Would saving these data in sessions decrease security of website? Is there another way(s) to carry these data?

A: Save the persistent data (which need to be preserved even if user closes the browser) into database.
Save everthing else into session.
As for cookies, please note that it gets sent back and forth with each request. I don't recommend using cookies, except maybe for session ID.


text:
Q: Terraform can not create a storage account in Azure I have a Terraform script that used to be able to create a storage account in Azure ok, but today started to return the error message:
azurerm_storage_account.testsa: 1 error(s) occurred:
* azurerm_storage_account.testsa: Error waiting for Azure Storage Account "terraformtesthubb" to be created: Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=400 -- Original Error: Code="AadClientCredentialsGrantFailure" Message="Failure in AAD Client Credentials Grant Flow."

The trace logs don't show anything useful, and the term AadClientCredentialsGrantFailure literally returns nothing in Google. What is the cause?

A: Answering this one for myself because Google totally failed me.
This turned out to be an issue with Azure. Despite there being no errors listed in any of the status pages, the script would work in US West, but fail in US West 2.
After a few days this issue went away, so it was an intermittent Azure issue.
Edit
For reference, this was the script. Markers like #{Principal.TenantId} are being replaced during the template deployment.
provider "azurerm" {
  client_id = "#{Principal.Client}"
  client_secret = "#{Principal.Password}"
  subscription_id = "#{Principal.SubscriptionNumber}"
  tenant_id = "#{Principal.TenantId}"
}

resource "azurerm_resource_group" "testrg" {
  name     = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  location = "#{Octopus.Environment.Name | ToLower}"
}

resource "azurerm_virtual_network" "test" {
  name                = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  address_space       = ["10.0.0.0/16"]
  location            = "${azurerm_resource_group.testrg.location}"
  resource_group_name = "${azurerm_resource_group.testrg.name}"
}

resource "azurerm_subnet" "test" {
  name                 = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  resource_group_name  = "${azurerm_resource_group.testrg.name}"
  virtual_network_name = "${azurerm_virtual_network.test.name}"
  address_prefix       = "10.0.2.0/24"
  service_endpoints    = ["Microsoft.Sql", "Microsoft.Storage"]
}

resource "azurerm_storage_account" "testsa" {
  name                     = "terraformtesthub#{Octopus.Environment.Name | ToLower}"
  resource_group_name      = "${azurerm_resource_group.testrg.name}"
  location                 = "#{Octopus.Environment.Name | ToLower}"
  account_tier             = "Standard"
  account_kind             = "StorageV2"
  account_replication_type = "RAGRS"
    lifecycle {
    prevent_destroy = true
  }
  network_rules {
    ip_rules                   = ["100.0.0.1"]
    virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"]
  }
}


text:
Q: Create markers on Google-maps, pull coordinates of location from API into the map i am using google maps react.
I am trying to fetch data on latitude and longitude from my APIinto the Google Maps as markers.
Getting an error "TypeError: markers.map is not a function"
here is code snippet -
  const [markers,setmarkers] = useState([]);

  const GetCoordinates = (info) => {
       setmarkers(info);}

  function GetMaps(props){
     const AnyComponent = ({text}) =>
{text}

     defaultmarkers = {center:{lat: xxxx, lng: xxxx}, zoom: 10}
   }

   return (

     <GoogleMapReact
       bootstrapURLKeys = xxxxxx
       defaultcenter= {defaultmarkers.center}
       defaultZoom= {defaultmarkers.zoom}>

       <AnyComponent>

           {markers.map(x => (   //////getting error on this line

               lat={x.lat}  // pull from API data
               lng={x.lng} // pull info from API
               text={x.title}

))}

       </AnyComponent><GoogleMapReact>

       <GetMaps /> // function called in return tag

Getting an error "TypeError: markers.map is not a function"


text:
Q: How password hash and salt stored in Symfony database? I am migrating a project from Symfony to Django. I need to import all users with passwords.
To do this I need to know how passwords are stored in the database. For each user password I need to know 4 things:

*

*the algorithm was used to generate hash

*number of iterations

*the salt was used to generate hash

*resulted hash
The project built on Symfony 3.4. The developers said to me that they are used default hashing algorithm and it is SHA512
I suppose the number of iterations is 1.
Left to find a salt and result hash. Both should be stored in the database.
In the password field in the database stored strings like this:
fOEJQT89OWYfI+hBHT28RpTQRiWnyo49Rtxqv6DWY/EJ6cSkFdZ0Y36VaqjWI+1NNhRGCHBBGJvwdMD1c7GZfw==
I expect to find a hash and a salt here
BUT
here are 88 symbols.
SHA512 has a 64 bytes long hash.
What is the format of data stored in this field?
Is both a hash and a salt stored here?

A: You have to check the app/config/security.yml for the encoders being used. Assuming you have something like the following:
security:
    encoders:
        App\Entity\User: 'sha512'

It will use the SHA512 encoder with default settings. From looking at the corresponding Encoder MessageDigestPasswordEncoder we can gather that it will use 5000 iterations by default and then base64 encode it.
The only thing left is figuring out if a salt was used, and if so how it was generated. Since SHA512 does not generate it's own salt you have to look at the user class and check its User::getSalt method. If this returns null, then no salt was used otherwise you will have to mimic its behaviour or retrieve the result when generating the password.


text:
Q: theory of equation..finding roots of a modular function The number of real roots of $\big|x^2+4|x|+3\big| +2x-11=0$ is?
I have tried by expanding modulus, and if I'm right I'm getting two real roots but I'm a bit confused because of the innermost modulus, please help

A: If $x\ge0$ then we simply get $x (x + 6) = 8$ so that we get the positive solution $x = \sqrt{17}-3$.
If $x<0$ then we get $|x^2 - 4x+3|+2x=11$.
We break this up into two cases (consider $x^2 - 4x+3 = 0$):

*

*If $2-\sqrt{15} \le x < 0$ then we get $-x^2 + 4x-3+2x=11$, which has only non-real roots (which thus can't satisfy $x<0$)

*If $x < 2-\sqrt{15}$ then we get $x^2 - 4x+3+2x=11$ which has solutions $x = -2$ and $x=4$. Since $x < 2-\sqrt{15}$, only $x = -2$ is a valid solution.

We thus have two real solutions: $x = \sqrt{17}-3$ and $x = -2 \qquad \square$

A: First answer this question: Under what circumstances can
$x^2 + 4\lvert x\rvert + 3$ be negative?
This will simplify the problem quite a bit.
Remember that a formula like this can be expressed as a piecewise polynomial function if you can figure out the values of $x$ at which anything inside an absolute value sign goes from negative to positive or vice versa.
Within any interval where you do not have such a sign change, the function is polynomial.
In this problem there are fewer pieces than you might expect.

A: $$\big|x^2+4|x|+3\big| +2x-11=0$$
For $x>0$ the equation is equivalent to $$x^2+4x+3+2x-11=x^2+6x -8=0$$
With solutions $x=-3\pm \sqrt {17}$
We keep the positive one.
$ x=0$ is not a solution.
For $x<0$, the equation is equivalent to  $$\big|x^2-4x+3\big| +2x-11=0$$ or $$ x^2-4x+3+2x-11=0$$
$$x^2-2x-8=0$$
The solutions to this last equation are $x=4$ or $x=-2$
We keep $x=-2$
Thus over all we have two  solutions $x=-2$ or  $x=-3+\sqrt {17}$