switch data based on different value

This is a little convoluted, so i apologize in advance.

I have multiple tables, one has the columns ID/Member/Type/UseDefault.
The other table has columns with descriptive information about a person, based on the ID.

Type will mostly be defualt. In which case, the information that corresponds with ID is perfectly fine. If UseDefault is false (which will only happen when type IS NOT defualt AND they do not want to use the default value), then the supplied ID is also perfectly suitable. However, if type is not default, but use default is entered as Yes, i need to display the information that is associated with the same member’s default ID.

For example:

ID / Member /Type /UseDefault

  • 1 / joe / default /Y
  • 2 / joe / additional /Y
  • 3 / joe / third /N

in the table above when i join with the table that has all the descriptive information, for row 1 and 3, it is ok if i use their respective ID, but for 2, because type is not default and UseDefault is Y, i need to display the information for ID 1 (joe’s default ID). We will call the second table Info

basically i have

Select I.Car, I.Color, I.FavoriteFood
from Info I 
join Example E where I.id = E.id

Q: R ggplot2 – Different precision on seperate tick marks

I have been working on creating a histogram of some data I that I have recent generated and in a effort to make the data more readable would like to include the confidence intervals, including having the intervals numerically marked on the tick line.

This has created a small problem with the readability. Using the code below you can see that having mean as a float value will cause all of the tick marks to have the same precision as the mean value leading to a large number of trailing 0’s, in this case there are 7 but if you manully set the mean value to something like 3.5 all will have 1 trailing 0.

I was wondering if anyone knows how to set the percision of each mark manually. Ideally I would like to have the marks at 0,1,2,..,10 to be integer while the mean value would have 2 digits of precision shown since I will have a more accurate number listed.


df <- data.frame(x=rexp(1000))

mean = mean(df$x)

ggplot(df, aes(x=x)) + 
  geom_histogram(binwidth = .05, position="dodge", color="black", fill="transparent") + 
  geom_vline(data=rawdata, aes(xintercept=mean), linetype="dashed", color="red") +
  theme_bw() +
  scale_x_continuous(name="Values", expand = c(0, 0), breaks = sort(c(seq(0,10,1), mean)))

Image of the resultant graph from the code above.

Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development, works localy tho

I have a weird error that has been bugging me for a while now. When I run the server local the site shows up perfect but when I try to access it on my aws EC2 I get the error “ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development”
So I ran the command “bin/rake db:migrate RAILS_ENV=development” and this prints out.

bin/rake db:migrate RAILS_ENV=development
Running via Spring preloader in process 30908
== 20160812175638 CreatePosts: migrating ======================================
-- create_table(:posts)
   -> 0.0014s
== 20160812175638 CreatePosts: migrated (0.0017s) =============================

== 20160813194710 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0015s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0005s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0007s
== 20160813194710 DeviseCreateUsers: migrated (0.0031s) =======================

== 20160912112653 AddAttachmentImageToPosts: migrating ========================
-- change_table(:posts)
   -> 0.0012s
== 20160912112653 AddAttachmentImageToPosts: migrated (0.0013s) ===============

but I still get the same msg. So I did some searching on the net and I have read all the pages here on this issue and haven’t found nothing.

When I run “rake db:migrate:status” I see this:

Status   Migration ID    Migration Name
   up     20160812175638  Create posts
   up     20160813194710  Devise create users
   up     20160912112653  Add attachment image to posts

And when I do “rake db:version” I get this:

Current version: 20160912112653

“rails -v” gives me

Rails 4.2.6

and “cat Gemfile | grep rails” gives me this:# Bundle edge Rails instead:

gem 'rails', github: 'rails/rails'
gem 'rails'
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# bundle exec rake doc:rails generates the API under doc/api.
# gem 'capistrano-rails', group: :development
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

I’m at loss here, it works just fine on local and it worked just fine if I edit away /data/ from database.rb file.

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

  <<: *default
  database: db/data/development.sqlite3
  <<: *default
  database: db/test.sqlite3

  <<: *default
  database: db/data/production.sqlite3

But if I do that the database gets wiped as soon as I update the site with my redeploy script which is running docker-compose for me.

I quite sure that I’ve missed a simple thing that gives me this error tho since the site do work on the localhost.


BubbleSort Implementation

I tried to make an implementation of bubble sort, but I am not sure whether it is correct or not. If you can give it a look and if it is a bubble sort and can be done in better way please don’t be shy. Here is the code:

package Exercises;

import java.util.*;

public class BubbleSort_6_18 
    public static void main(String[] args) 
        Random generator = new Random();

        int[] list = new int[11];
        for(int i=0; i<list.length; i++)
            list[i] = generator.nextInt(10);

        System.out.println("Original Random array: ");


        System.out.println("nAfter bubble sort: ");

    public static void bubbleSort(int[] list)
        for(int i=0; i<list.length; i++)
            for(int j=i + 1; j<list.length; j++)
                if(list[i] > list[j])
                    int temp = list[i];
                    list[i] = list[j];
                    list[j] = temp;


    public static void printArray(int[] list)
        for(int i=0; i<list.length; i++)
            System.out.print(list[i] + ", ");

Resign .IPA with new BundleId, Provisioning Profile and Inhouse distribution certificiate

Third party development team have provided me an IPA signed with enterprise distribution certificate. I want to resign the same IPA with new BundleId, Provisioning Profile and In-house distribution certificate.

On searching I found various approach. Also I have tried using some third party applications but the final IPA never gets installed successfully from Itunes.
I used below links but no luck.


My question : Is resigning ipa signed with in-house distribution certificate with some profile and bundle-id to new in-house distribution certificate,profile and new bundleId works in iOS 9.X ? If yes what is correct method ?

Many thanks!

Understanding of bash syntax (quoted parameters)

Why this command works:

sudo rm -rf ${server_tomcatHomeDir}temp/*

While the same, but with quoted arg, doesn’t work:

sudo rm -rf "${server_tomcatHomeDir}temp/*"

It might be related only to quotes, but why this command works even with quoted args:

sudo cp "$HOME/${artifact}" "${server_tomcatHomeDir}/webapps/${webapp}"

I can’t understand. Can anyone clarify?

I just want to use quotes in the first command to prevent globbing and word splitting.

Github projects to customer domains

say i have a customer domain www.mydoamin.com and i want to create section or subdomains for each projects that i have for example, www.mydomain.com/project1 and www.mydomain.com/project 2. how do i do that? I have the CNAME file in the root of the repo as www.mydomain.com/project1 but it keeps saying custom doamin not correctly formatted. I have set up A host on my domain. i just can’t figure out what’s wrong with the CNAME file in the root of my github repo.

Matching a pattern that can be repeated in Regex

I want to write a regulated expression so that I can enter either one address like this C4:C15 or multiple ones (at most 3 in total) seperated by a comma like B3:B5,B7:B10,C4:C6

I already know how to enter each one separately using “^([B-” + Chr(Asc(“A”) + 2) + “])([2-9]|[1-9][0-9])?:?1([2-9]|[1-9][0-9])?(,)?$”, however how can I do that to add one or two more knowing that I know how many addresses I need but I don’t want to do it in a for loop.

CSS – Have Image Move With Centered Text-Align Input Text

I have an text input with the following HTML:

<input type="text">

and the corresponding CSS:

    text-align: center;
    border: none;
    outline: none;
    background-color: transparent;

The input element should blend seamlessly into its background with only the HTML icon indicating that it is indeed an input. The HTML icon will remain in a static position with the current mark-up as new text is added into the input.

Is there anyway to have my HTML icon start right to the left of the first letter and have it gradually move toward the left as the left boundary of the text string pushes in the same direction?

Fiddle Example

C++ Operator+ Overloading of Matrix

I am learning to build my own Matrix class and get a question on the operator+ overloading.

Matrix Matrix::operator+(Matrix &b)
    Matrix temp;
    return temp;
c = a + b;

This works very well but I am a little concerned that is it inefficient that I declare a temporary matrix first then copy it to the final target (matrix c)? For example, below is a naive matrix add function,

void matrixAdd(Matrix& c, Matrix& a, Matrix& b)

Off course, the first one is easier to use but will the second be faster? If so, how can I improve the first one?