Q:

Using compressors in Live Sound (Houses of Worship)

Context:
I recently (~2 months ago) got a gig mixing live sound for a church. I've had years of audio education, but none of the courses offered included extensive applications in FOH mixing (very odd, I know), so I'm very new to the application of audio techniques in a live environment.
The church I'm mixing at is all pastored by guys who have done mixing for far longer than I have, and have contacts who have been mixing for 30+ years. At least two of them have mentioned that they never use compressors in live sound. ever. It's possible they were speaking specifically about Vocal channels, but I don't think it was limited to that.
They also have a very specific kind of sound they are trying to craft, and my understanding of this is lots of BGVs, Bass Guitar, Kick/snare, and Keys.. in roughly that order of importance. Often times we have 5 BGVs, sometimes two keys, horns, bass, drums, aux percussion, etc.
Question:
How often do you apply compression to a channel when mixing? Obviously "If it needs it" is a good starting point, but how often would you say a channel "needs it? I'm trying to make sense of the comment from my boss "I used to mix for 18 years and I NEVER used compressors. Ever." If "Live sound guys never use compressors," then why would the board have them?
OR is there an environment where you would truly never use compressors?
I'm trying to understand this, so I appreciate any feedback!

A:

Sure, in my opinion compressors are an extremely useful tool and not using them at all as a rule is missing out on a lot.
When I'm mixing, one of my goals is to make a cohesive, balanced sound that reflects what the band is playing. However, a microphone or instrument is an open conduit to potentially  change that balance. So if a background singer for example is singing louder in some parts of a song than others at random points then that can potentially overpower the lead.
Also, a lead vocal or instrument should be in the foreground of the mix definitely but if your singer starts shouting to interact with the audience without a compressor then it can quite possibly cause discomfort since that will have significant more input than singing, just as much as if you were having a conversation and your friend pulls out his megaphone.
And what about dynamics? Well I adjust during a piece to provide that dynamic and pay attention to what parts the band wants to be significantly softer or louder or heavier emphasis on a vocal/instrument.
So to answer your question, I use compressors fairly often. It's a useful tool in our arsenal, especially with the advent of digital mixers.


Q:

Fill UItableViewCell with 2 array in swift

I have a basic uitableview with 2 UITableViewCell I am trying to fill the first cell with array1.count and the second cell with array2.count but I don't know how, this is my code:
override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var value: Int = 0
        if(section == 0){
            value = 1
        }else if(section == 2){
            value = 5
        }
        return value
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.cell1, for: indexPath) as!  Cell1
            cell.lbl_cell1.text = "Subject"
            cell.selectionStyle = .none
            return cell
        } else if indexPath.row == 1 {
            let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.cell2, for: indexPath) as!  Cell2
            cell.lbl_cell2.text = "Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 1500, cuando un impresor (N. del T. persona que se dedica a la imprenta) desconocido usó una galería de textos y los mezcló de tal manera que logró hacer un libro de textos especimen."
            cell.selectionStyle = .none
            return cell
        }
        return UITableViewCell()
    }

My error is that I always get 1 value in each cell, All I want is this
Cell 1 Math
cell 2 a,b,c,d,e,f,g,h .....
Thanks in advance

A:

Try this:
override func numberOfSections(in tableView: UITableView) -> Int {
        return 2
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var value: Int = 0
    if(section == 0){
        value = array1.count
    }else{
        value = array2.count
    }
    return value
 }

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.cell1, for: indexPath) as!  Cell1
        item = array1[indexPath.row]
        ...
        return cell
    } else {
        let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.cell2, for: indexPath) as!  Cell2
        item = array2[indexPath.row]
        ...
        return cell
    }
}


Q:

MySql %w date format parameter equivalent for SQL Server

In MySQL to get the day of week we use '%w' format parameter.what is the SQL Server equivalent for doing that? I used 'ddd' but it give me the day name (eg: Saturday) not the number.any suggestions?
This is what I've tried:
 select FORMAT( SYSDATETIME(), 'ddd', 'fa-IR' )

between I am aware of DATEPART(weekday , GETDATE()) but is lacks culture parameter.

A:

There is no exact replica of MySQL's %w which is always (0=Sunday..6=Saturday)
The easiest way to get 0 for Sunday every time in any SQL Server instance is:
datediff(day,-1,[yourdate_value]) % 7

What this does is to calculate the number of days since 1899-12-31 (a Sunday), then supply the remainder if divided by 7. A result of 0 will always be Sunday, a result of 6 will always be Saturday.
NB T-SQL uses a base date of 1900-01-01 (a Monday) and this base date can be represented by 0 in T-SQL date function such as datediff. So the -1 is one day less that the base date. Instead of -1 you could use any reliable Sunday date, e.g.
select datediff(day,'20181104',getdate()) % 7, datediff(day,-1,getdate()) % 7

and both columns would always be (0=Sunday..6=Saturday)

If you don't use the above, note that in MS SQL Server it is possible to change the day of week that represents zero, this setting is called datefirst and you can access the current value of this with:
select @@datefirst

A datefirst value of 7 in SQL Server = MySQL %w of 0 (Sunday). The initial setting of datefirst is usually established by choice of language, and you can find that language dependent datefirst value using this query:
select alias, name, dateformat, datefirst
from sys.syslanguages

              alias                 name          dateformat   datefirst
 ---- --------------------- -------------------- ------------ -----------
   1   English               us_english           mdy                  7
   2   German                Deutsch              dmy                  1
   3   French                Français             dmy                  1
   4   Japanese              日本語                ymd                  7
   5   Danish                Dansk                dmy                  1
   6   Spanish               Español              dmy                  1
   7   Italian               Italiano             dmy                  1
   8   Dutch                 Nederlands           dmy                  1
   9   Norwegian             Norsk                dmy                  1
  10   Portuguese            Português            dmy                  7
  11   Finnish               Suomi                dmy                  1
  12   Swedish               Svenska              ymd                  1
  13   Czech                 čeština              dmy                  1
  14   Hungarian             magyar               ymd                  1
  15   Polish                polski               dmy                  1
  16   Romanian              română               dmy                  1
  17   Croatian              hrvatski             ymd                  1
  18   Slovak                slovenčina           dmy                  1
  19   Slovenian             slovenski            dmy                  1
  20   Greek                 ελληνικά             dmy                  1
  21   Bulgarian             български            dmy                  1
  22   Russian               русский              dmy                  1
  23   Turkish               Türkçe               dmy                  1
  24   British English       British              dmy                  1
  25   Estonian              eesti                dmy                  1
  26   Latvian               latviešu             ymd                  1
  27   Lithuanian            lietuvių             ymd                  1
  28   Brazilian             Português (Brasil)   dmy                  7
  29   Traditional Chinese   繁體中文             ymd                  7
  30   Korean                한국어               ymd                  7
  31   Simplified Chinese    简体中文             ymd                  7
  32   Arabic                Arabic               dmy                  1
  33   Thai                  ไทย                  dmy                  7
  34   Bokmål                norsk (bokmål)       dmy                  1

The function DATEPART(WEEKDAY, YourDateColumn) responds to the datefirst setting, so IF the datefirst setting is 7, and the datepart value is 0 then it is Sunday. If the datefist setting is 1 then a datepart value of 0 means Monday. Here is a discussion of this (often confusing) relationship.
You can override these default setting by using:
SET DATEFIRST 7 ;
SELECT DATEPART(WEEKDAY, [yourdate_value])

and now (0=Sunday..6=Saturday)


Q:

Remove the commas, spaces and "NULL" string to 0(Zero) from Column

I am newbie to Excel VBA.
Need help to removing the commas, spaces and NULL string to "0" from ColumnName called StringName.
First, I have tried to remove the commas, spaces from the ColumnName called StringName and finally to find and replace the "NULL" string to 0(Zero).
Here is the code to Replace for commas, spaces from the ColumnName called StringName.
Sub ReplaceCharacters()

  Application.ScreenUpdating = False
    Dim lrow As Long
    lrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
  With ActiveSheet.Range("A2:A" & lrow).SpecialCells(xlCellTypeConstants, xlTextValues).Cells
      .Replace What:=",", Replacement:="", LookAt:=xlPart
      .Replace What:=" ", Replacement:="", LookAt:=xlPart
  End With

  Application.ScreenUpdating = True

End Sub

I am struggling to find and Replace the string "NULL" to 0 from the ColumnName called StringName.
I need help with this and I have tried a lot and ended up here for a solution.
Here is what I have tried..
' not working
Sub UpdateWhole()
    With ActiveSheet.UsedRange
    .Replace "NULL", "0", xlWhole
    End With
End Sub

' not working
Sub FormulaRng()
    For i = 2 To 10
       Worksheets("Sheet1").Range("A2:A" & i).FormulaR1C1 = "=IF(A" & i & "=""NULL"",0,A" & i & ")"
    Next
End Sub

Thanks in Advance

Here is the sample data to test
StringName
------------------
NULL
NULL
null
nullasdf
cbgrgNULLdf343
, asdfwe 4fdt
456fg , d55nullNULL
sdf34      df,    4fd
NULLfgf  null
121
22
34545

Required OutPut
------------------------
0
0
0
nullasdf
cbgrgNULLdf343
asdfwe4fdt
456fgd55nullNULL
sdf34df4fd
NULLfgfnull
121
22
34545

A:

The following revised procedure should work for you. I used the Clean function to remove all non-printable characters from the text before replacing the NULL text with 0.
VBA Code
Public Sub ReplaceCharacters()
On Error GoTo ErrTrap
Const ProcedureName As String = "ReplaceCharacters"
Dim sheet           As Worksheet: Set sheet = ActiveSheet
Dim cell            As Range

    Application.ScreenUpdating = False

    For Each cell In sheet.UsedRange.Cells
        cell = Trim(Application.WorksheetFunction.Clean(cell))
        cell.Replace What:="NULL", Replacement:=0, LookAt:=xlWhole
        cell.Replace What:=",", Replacement:="", LookAt:=xlPart
        cell.Replace What:=" ", Replacement:="", LookAt:=xlPart
    Next cell

ExitProcedure:
    On Error Resume Next
    Application.ScreenUpdating = True
    Set sheet = Nothing
    Exit Sub

ErrTrap:
    Select Case Err.number
        Case Else
            Debug.Print "Procedure: " & ProcedureName & " |Error #: " & Err.number & " |Error Description: " & Err.description
    End Select
    Resume ExitProcedure
    Resume 'for debugging

End Sub

Example Video


Q:

moment.js timezone get milliseconds

I'm trying to get number of days passed. I'm storing epoch (milliseconds) for date.
I'm reading startDate from database (date value of first record) in milliseconds and I want to find current epoch in specified timezone.
I tried this:
var startDate = rows[0]['MIN_DATE'];
var endDate = moment().tz("America/New_York");

Then to calculate difference, I used:
var oneDay = 24 * 60 * 60 * 1000;
var daysCount = Math.ceil((endDate - startDate) / (oneDay));

The value of startDate is:
1522821600000 which is: Wednesday, April 4, 2018 2:00:00 AM GMT-04:00 DST

The value of endDate is:
Moment_d: Wed Apr 04 2018 22:24:45 GMT-0400 (EDT)_isAMomentObject: true_isUTC: true_isValid: true_locale: Locale_offset: -240_pf: Object_z: Zone__proto__: Object

The value of daysCount is 2, how?
How can I get milliseconds instead of object from:
moment().tz("America/New_York");

A:

Solved this with following statement:
var endDate = moment().tz("America/New_York").valueOf();


Q:

Pass form post data to controller function after jquery validation

Validation input form wiyj jquery validation
Here is the script  -
$('#myform').validate({
    rules: {
        amount: {
            required: true,
            //email: true
        }

    },
    submitHandler: function (form) {
        alert('valid form submitted');

    }
});

Here is the codeigniter funtion -
  public function test_add(){

  if (!empty($_POST['RentForm'])) {
  echo 4567;
  die;
  }
  }

A:

You can try using ajax.
Script
var base_url = "<?=base_url();?>";
        $('#myform').validate({
            rules: {
                amount: {
                    required: true,
                }
            },
            submitHandler: function (form) {
                $.ajax({
                    url: base_url+'your_controller/test_add',
                    type: 'POST',
                    data: $('#myform').serialize(),
                    success: (res)=>{
                        // Do Something if success
                        console.log(res);
                    }
                });
            }
        });

Your Controller
public function test_add(){
            if ($this->input->post('RentForm')) {
                echo $this->input->post('RentForm');
                // Or do Something else
            }
        }


Q:

IE6 CSS display:table fix?

I'm working on a web app... unfortunately it has to work with the worst piece of software ever written, yes ie6.
I really like the CSS display:table and display:table-cell properties, but of course it doesn't work in ie.
Has anyone found any fixes for this? I have been looking, but haven't found anything.
Conditional CSS, .htc files, javascript...anything?
I would really like to avoid making everything with floats and clears

A:

Sorry. There isn't a fix to make IE6 support CSS display:table. The only way to acheive this layout in IE6 is to actually use <table> elements.
First question: do you really need to support IE6? If you can simply drop support for it, you'll solve yourself a whole ton of problems, including this one. Current global usage of IE6 is below 3%, and even lower in most developed countries.
If you do still need to support IE6, then your most obvious solution is simply to swallow your semantic markup pride and just use a <table> tag.
As described by @Tom, the next best solution is to write your layout using display:inline-block;.
inline-block allows you to define your elements as blocks, but still keep them in the text flow (kinda the way the <img> tag works by default). If you combine this with fixed element widths, and wapper divs around rows, you could acheive something similar to a table, although it may be hard to get it to expand dynamically with the page width.
The one big "gotcha" bug around this is that inline-block only works in IE6/7 for elements that have a default style of display:inline. In other words, it works for a <span> but not for a <div>. Not a disaster, but something to be aware of, especially since you're specifically asking about IE6 support. Other than that, the good news is that you should be able to get away with using display:inline-block without any other hacks or work-arounds.


Q:

How can I set the location of a JOptionPane?

I have a splash window that pops up while the program loads. This splash window uses the method setAlwaysOnTop(true), which is something I would prefer to keep.
The issue comes when a separate part of the program pops up a JOptionPane to notify the user they need to update the software. On Linux this appears in front of the Splash window, but on Windows it appears behind, barely visible to the user who then might sit for 30mins - hour before finding out why it's not loaded yet.
A fix I'd like to implement is to either

Force the JOptionPane to popup somewhere else on the screen
or
Change the location that the JOptionPane appears at, so it is positioned to the top, or bottom of the splash screen.

The only function I can see that would do this is the setLocationRelativeTo(Component myComponent) method. But this is no good as there is nothing better for it to be relative to (and nothing present!).
Is this sort of thing possible? If so how do I go about doing it?
Here is my SSCCE (based off of SeniorJD's code in their answer) :
public class Main {
    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                final Splash splash =new Splash();
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                final Frame frame = new Frame("Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                splash.dispose();
            }
        });
    }
}

@SuppressWarnings("serial")
public class Frame extends JFrame implements ActionListener{
    Frame(String title){
        super(title);
        JButton button = new JButton("Button");
        add(button);

        setAlwaysOnTop(true);
        setSize(500, 500);
        setLocationRelativeTo(getParent());
        setAlwaysOnTop(true);
        button.addActionListener(this);
        actionPerformed(null);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JOptionPane optionPane = new JOptionPane("Option Pane");
        optionPane.showMessageDialog(this, "Message: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tristique gravida congue.");
    }
}
    @SuppressWarnings("serial")
public class Splash extends JFrame {
    public Splash() throws HeadlessException {
        setAlwaysOnTop(true);
        setUndecorated(true);
        setVisible(true);
        setSize(600, 450);
        setLocationRelativeTo(getParent());
    }
}

This more ore less emulates the behaviour my users are seeing. How do I move the JOptionPane out of the way of the splash screen?

A:

You should set the frame as a parent of JOptionPane:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class Main {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                final JFrame frame = new JFrame("Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JButton button = new JButton("Button");
                frame.add(button);

                frame.setAlwaysOnTop(true);
                frame.setSize(500, 500);
                frame.setLocation(500, 500);

                button.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JOptionPane optionPane = new JOptionPane("Option Pane");
                        optionPane.showMessageDialog(frame, "Message!"); // if you put null instead of frame, the option pane will be behind the frame
                    }
                });

                frame.setVisible(true);
            }
        });
    }
}


Q:

Userfrosting - Get Working, Post blank screen with no error in log

I'm creating my first Userfrosting app and trying a few simple things but falling at the first hurdle.  I am trying to create a form which adds bands to a database table:
CREATE TABLE `uf_band` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `band_name` text NOT NULL,
 `band_description` longtext NOT NULL,
 `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
 `modified_at` timestamp NULL DEFAULT NULL,
 PRIMARY KEY (`id`)
)

initialize.php:
$table_band = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "band", [
    "band_name",
    "band_description",
    "created_at",
    "modified_at"
]);

index.php for the routes:
$app->get('/bands/new/?', function () use ($app) {
    $controller = new UF\BandController($app);
    return $controller->newBand();
});

The New Band form using GET works fine.
BandController.php
public function newBand(){
    if (!$this->_app->user->checkAccess('uri_bands')){
        $this->_app->notFound();
    }
    $this->_app->render('bands/new.twig', []);
}

and if I add this to the newBand Controller to test, it writes to the database when I load the new band form, which is fine:
    $new_band = new Band([
        "band_name" => "band_name",
        "band_description" => "band_description"
    ]);
    $new_band->save();
    $id = $new_band->id;

The problem is the Save using Post.  Even if I hard code in the values and do not even try to read the POST data, all I get is a blank screen.  There are no error messages and nothing in the apache error.log:
index.php
$app->post('/bands/new/?', function () use ($app) {
    $controller = new UF\BandController($app);
    return $controller->saveBand();
});

BandController.php
public function saveBand(){
    $new_band = new Band([
        "band_name" => "band_name",
        "band_description" => "band_description"
    ]);
    $new_band->save();
    $id = $new_band->id;
}

If I replace my POST route with
$app->post('/bands/new/?', function () use ($app) {
    echo 'post';
})

I still just get a blank screen.
Here's bands/new.twig though I think the problem is before this:
{% extends "layouts/layout-dashboard.twig" %}

{% set page_group = "dashboard" %}

{% block page %}
    {% set page = page | merge({
        "title"          : "Add New Band",
        "description" : ""
    }) %}
    {{ parent() }}
{% endblock %}

{% block content %}

{{page.title}}

{{page.description}}

Add New Band

                <form class="form-horizontal" role="form" name="bands" action="{{site.uri.public}}/bands/new" method="post">

                        Band Name

                            <input type="text" id="input_title" class="form-control" name="band_name" placeholder="Please enter the band name">

                        Description

                            <textarea type="text" id="input_title" class="form-control" name="band_description" placeholder="Please enter a description of the band.  This may be displayed publically"></textarea>

                        Genre

                            <select id="input_group" class="form-control select2" name="genre_id">
                                {% for group in groups %}
                                    <option value="{{group.id}}">{{group.name}}</option>
                                {% endfor %}
                            </select>

                        <button type="submit" class="btn btn-success text-center">Add Band</button>

                </form>

{% endblock %}
{% block page_scripts %}

{% endblock %}

Thanks for any thoughts.  With no error messages, this is driving me nuts!

A:

Seems like you have forgotten the csrf token.
You can add this hidden input field:
<input type="hidden" name="{{csrf_key}}" value="{{csrf_token}}">
and read more here.


Q:

Finish activity so counters reset

I'm trying to make a game with score counters, round counters, etc, but what I find is that when I finish the game activity with the finish() method, the ints still have the same numbers as before, is there a way to get things to no longer persist in memory when the activity has been closed w/o force closing?

A:

I'm trying to make a game with score counters, round counters, etc, but what I find is that when I finish the game activity with the finish() method, the ints still have the same numbers as before

Then you are storing the information somewhere that lives past the life of an activity, such as a static data member.


Q:

random number generation and nested array in JavaScript

I am trying to generate random number for creating scatter plot with d3js. I am doing it in the following manner:

//declare an array of arrays
var dataset = [
  []
];
var inner = [];

/*
    set the svg width and height
*/
var svgWidth = 500;
var svgHeight = 100;
var xCoord = 0;
var yCoord = 0;

for (var i = 0; i < 20; i++) {
  do {
    xCoord = Math.floor(Math.random() * svgWidth);
    yCoord = Math.floor(Math.random() * svgHeight);
  } while (xCoord <= 0 | yCoord <= 0);

  if (xCoord > 0 && yCoord > 0) {
    inner.push(xCoord);
    inner.push(yCoord);

    dataset.push(inner);
  }

  inner = [];
}

var svg = d3.select("body")
  .append("svg")
  .attr("width", svgWidth)
  .attr("height", svgHeight);

svg.selectAll("circle")
  .data(dataset)
  .enter()
  .append("circle")
  .attr("cx", function(d) {
    return d[0];
  })
  .attr("cy", function(d) {
    return d[1];
  })
  .attr("r", 5);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

The outer array should contain only 20 elements, I found out that it is creating 21 elements instead with the first element with only the radius values and no coordinate value for the center of the circle. Some hint would be great to have to understand the issue.

A:

The inner array isn't necessary, in fact it's the problem.
var dataset = [
  []
];

Just remove it.
var dataset = [];

A:

Try this:
//declare an array of arrays
var dataset = [];
var inner = [];

/*
    set the svg width and height
*/
var svgWidth = 500;
var svgHeight = 100;
var xCoord = 0;
var yCoord = 0;

for (var i = 0; i < 20; i++) {
  do {
    xCoord = Math.floor(Math.random() * svgWidth);
    yCoord = Math.floor(Math.random() * svgHeight);
  } while (xCoord <= 0 | yCoord <= 0);

  if (xCoord > 0 && yCoord > 0) {
    inner.push(xCoord);
    inner.push(yCoord);

    dataset.push(inner);
  }

  inner = [];
}

var svg = d3.select("body")
  .append("svg")
  .attr("width", svgWidth)
  .attr("height", svgHeight);

svg.selectAll("circle")
  .data(dataset)
  .enter()
  .append("circle")
  .attr("cx", function(d) {
    return d[0];
  })
  .attr("cy", function(d) {
    return d[1];
  })
  .attr("r", 5);


Q:

In my web application, one of the component is slower than other components, how to deal with that?

Suppose I have a micro-services based architecture. Some of the micro-services are more heavily loaded than others.How I decide how much scaling I do for each of the components? My understanding is I do load testing & find out how much load each of the service can bear & based on that some service I scale say by a factor of 3, some by factor of 5 etc. Now suppose I have a service - payment service - which depends on 3rd party payment gateway which is slow and not in my control - how to deal with that? I am free to containerize the application & user docker/kubernetes.

A:

A slow 3rd party payment processor can take several seconds to process a request.  This will affect your architecture in various ways.
First, your payment service should not expose an entry point that can take several seconds to respond.
The amount of memory and some other kinds of resources that a service consumes is proportional to the number of simultaneous requests, which is proportional to the response time.   If your slow service can multiply the response times of all upstream services by 10 or 100 times, then it can multiply the consumption of those resources by the same factor, and that is unacceptable.  It is also unacceptable to leave everybody waiting for several seconds with no status feedback.
So, instead of a "processPayment" entry point, you will need:

A "startPayment" entry point that quickly starts a payment and returns a transaction ID;
A "checkStatus" entry point that can check the status of a transaction given its ID; and
Maybe a way to subscribe to transaction status updates.

All of those entry points should be fast.
Furthermore, the spreading of payment processing across multiple requests over several seconds means that you can't really rely on everything staying up for that whole time.  Transactions in progress and their status updates will therefore have to be persisted in durable storage -- some kind of database.  You probably want to do this anyway, since the "start payment" and "check status" requests shouldn't have to end up at the same service instance, and the DB is what communicates the status from one instance to another.
Communication with the 3rd party processor should usually be handled by "worker" processes/threads, because request handling threads are not provisioned for those kinds of response times. If payments are processed with a single request to the 3rd party processor, then it will be important to use asynchronous clients to call that service so you don't have to keep thousands of threads alive simultaneously.  The networking stack on your client machines may also require careful configuration to support that number of simultaneous connections out.
Finally, since money is being processed, it is vitally important to ensure that transactions are not forgotten, to ensure that you can always check their status, and to guard against multiple payments resulting from retries, all the way up to the user interface.  The payment processor will provide enough API to allow you to do this no matter what, but it may require careful design on your part.
To support the required user interface, you will also need an entry point that can check to see if a transaction is already in progress for any particular purpose.


Q:

angular form validation - set required by code (not working)

    if(currentAdmin.target =='new')
    {
        $('#btnDel').hide();
        //Not working !!!
        $('#inputPassword1').attr("ng-required","true");
        $('#inputPassword2').attr("ng-required","true");
    }
    else
    {
        $('#btnDel').show();
        $('#inputPassword1').attr("ng-required","true");
        $('#inputPassword2').attr("ng-required","true");
    }

Well, basically I want to place the ng-required based on the condition. I made a trial using the required (without ng) and it does not works as well.
I inspected the element and injected the required and ng-required into the html and it's not works.
This will always be ignored after rendered. I need to do such thing like "Validator, refresh because it's different now"
any clue ?

A:

Even though I myself hate the kind of answer I am about to give, I feel it is appropriate in this situation: This is not the way to write if using angular...
So what should you do?
place the ng-required in the html code and set the value of the attribute to a bound variable that you set depending on your condition.
Example:
index.html
<form ng-controller="formController">
  <input type="password" ng-required="isAdmin">
  <input type="password" ng-required="!isAdmin">
</form>

app.js
angular.module('app',[]).controller('formController', function($scope){
  $scope.isAdmin=false;
  if(currentAdmin.target == 'new'){
    $scope.isAdmin=true;
  }
});

Not complete code, but hopefully you still understand what I mean.


Q:

Problem with routes in functional testing

I'm making a simple test project to prepare myself for my test.
I'm fairly new to nested resources, in my example I have a newsitem and each newsitem has comments.
The routing looks like this:
resources :comments

resources :newsitems do
    resources :comments
end

I'm setting up the functional tests for comments at the moment and I ran into some problems.
This will get the index of the comments of a newsitem. @newsitem is declared in the setup ofc.
test "should get index" do
    get :index,:newsitem_id => @newsitem
    assert_response :success
    assert_not_nil assigns(:newsitem)
end

But the problem lays here, in the "should get new".
 test "should get new" do
    get new_newsitem_comment_path(@newsitem)
    assert_response :success
 end

I'm getting the following error.
ActionController::RoutingError: No route matches {:controller=>"comments", :action=>"/newsitems/1/comments/new"}

But when I look into the routes table, I see this:
new_newsitem_comment GET    /newsitems/:newsitem_id/comments/new(.:format)      {:action=>"new", :controller=>"comments"}

Can't I use the name path or what I'm doing wrong here?
Thanks in advance.

A:

The problem is in the way your test specifies the URL. The error message is:
No route matches {:controller=>"comments", :action=>"/newsitems/1/comments/new"}

and of course there is no action called "/newsitems/1/comments/new". You want to pass the hash  { :controller => :comments, :action => :new, :news_item_id => 1 }.
The right syntax is simply:
get :new, :news_item_id => 1


Q:

Strange output from matplotlib mathtext

I tried to use mathtext to get a specially rendered figure title, but it failed. Instead of my test title it just printed cryptic characters. What am I doing wrong?

Operating System: Fedora release 18 (Spherical Cow)
Python and matplotlib are installed from official repositories via yum

Here's the (full) code:
import sys
print sys.version             # prints:
                              # 2.7.3 (default, Aug  9 2012, 17:23:57)
                              # [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)]
import matplotlib
print matplotlib.__version__  # prints:
                              # 1.2.0

import matplotlib.pyplot as plt
plt.plot([1,5])
plt.title(r"$1.2345$")
plt.show()

Here's the output image:

A:

If you're using RedHat, CentOS or some other Fedora derivative, you may be seeing the bug described here: https://bugzilla.redhat.com/show_bug.cgi?id=562421
Try installing the "stix" font package (on CentOS/RedHat this is "stix-fonts"). The delete your ~/.matplotlib/fontlist.cache file. Next, re-run your system's font-cache script, probably  "fc-cache -f -s -v".
Now, change the matplotlibrc settings (either via a ~./matplotlib/matplotlibrc file or a matplotlibrc file in the same directory as your script) as follows:
mathtext.fontset : stix
mathtext.fallback_to_cm : True
mathtext.default : it

I'd love to know if this works for you.

A:

Apparantly it was a font-related thing. Found an old bug-report to address the issue.
A suggestion in one of the comments was to install the package lyx-fonts. This solved the problem for me.

Another workaround proposed here is to configure the mathtext rendering like this (at the top of the script):
plt.rcParams['mathtext.fontset'] = "stix"


Q:

IE Exception if beforeunload event aborts page redirect

I have a cancel button that when called redirects the user to another page:

function onCancelButtonClick() {
   document.location.href = settings.cancelUrl;
}

I also have an event handler for the beforeunload event in order to prompt the user for confirmation before leaving the page if there are unsaved changes:

function onPageUnload() {
  //If the changes were already saved then there is no need to prompt the user for confirmation before leaving the page.
  if (eventDataSaved)
    return;

  //If the page has unsaved changes ask for confirmation before leaving the page.
  if (hasTheGridRecordsBeenChanged() || formHasUnsavedChanges)
    return "You have unsaved changes";
}

This works well in chrome. However, IE is throwing an exception in the onCancelButtonClick event handler method whenever the user selects the option of staying in the page when prompted.
I saw a couple of posts in SO from 2009 and 2010 that recommended just adding a try catch to address this which I am sure that we can all agree it's not an ideal solution. So I was wondering if in the past few years someone came up with a more elegant approach to address this IE issue.

A:

So since in my case I wanted to redirect the user back to the page that they were coming from I found out that if I leverage the browser history (as opposed to redirecting the user using document.location.href) IE no longer throws an exception.
So for me the solution was just to use window.history.back()  However you can also go to specific pages that were previously visited without getting an exception using window.history.go()  so the only scenario where you would still encounter the IE issue that I mentioned in my question is if your user tries to go to a page that s/he has not visited recently.


Q:

Left-Outer Join in Postgres Not Returning Values for Null

A download is comprised of download-times, download-time id, and buno ID.
Faults are comprised of fault-codes, download-time id, status, and type.  A download can have many faults, and can be joined on the download-time id.
Given a set of fault-codes, the results must contain each fault-code with a corresponding fault-count.  If a fault-code is not found in the download, the fault-code must be returned with a fault-count of zero.
The problem seems to require an OUTER JOIN, but haven't seen this working as expected on Postgres as it does not seem to return the set with nulls from the LEFT table.
The query is below, with some details left out for brevity:
SELECT  f.faultcode, f.downloadtimeid, d.downloadtime, count(*) as faultcount
FROM    download_time d
LEFT OUTER JOIN fs_fault f ON f.downloadtimeid = d.id
    AND f.faultcode IN (1000,1100)
    AND f.statusid IN(2, 4)
WHERE (d.downloadtime BETWEEN '04/11/2011' AND '05/01/2012')
    AND d.bunoid = 166501
GROUP BY d.bunoid, f.downloadtimeid, d.downloadtime, f.faultcode

The following day, I've edited to show the answer.  All answers were close and had various elements of assistance.  However, JayC's answer was closest.  Here is the final SQL, having the only change as the WHERE clause taking the fault-code IN statement:
SELECT  f.faultcode, f.downloadtimeid, d.downloadtime, count(*) as faultcount
FROM    download_time d
RIGHT OUTER JOIN fs_fault f ON f.downloadtimeid = d.id
        AND f.statusid IN(2, 4)
        AND d.downloadtime BETWEEN '04/11/2011' AND '05/01/2012'
        AND d.bunoid = 166501
WHERE f.faultcode IN (1000,1100)
GROUP BY d.bunoid, f.downloadtimeid, d.downloadtime, f.faultcode

Thanks, all for your assistance!  Love this site!

A:

I'm giving my answer because I have significant doubts about the other answers.  You gotta be careful about filter requirements.   Remember, the where clause runs after your joins.  So if there are any filter requirements in the where clause that refer to the non-outer joined table, you have (in many circumstances) nullified your outer join.  So taking your sql, It seems the simplest solution is to either use the proper join or move the table names appropriately, and then move the filter conditions out of the where clause and into the join clause.
SELECT  f.faultcode, f.downloadtimeid, d.downloadtime, count(*) as faultcount
FROM    download_time d
RIGHT OUTER JOIN fs_fault f ON
    f.downloadtimeid = d.id
    AND f.faultcode IN (1000,1100)
    AND f.statusid IN(2, 4)
    AND d.downloadtime BETWEEN '04/11/2011' AND '05/01/2012')
    AND d.bunoid = 166501
GROUP BY d.bunoid, f.downloadtimeid, d.downloadtime, f.faultcode

Another way which I believe should be equivalent is
SELECT  f.faultcode, f.downloadtimeid, d.downloadtime, count(*) as faultcount
FROM    download_time d
RIGHT OUTER JOIN fs_fault f ON
    f.downloadtimeid = d.id
    AND d.downloadtime BETWEEN '04/11/2011' AND '05/01/2012')
    AND d.bunoid = 166501
WHERE
    f.faultcode IN (1000,1100)
    AND f.statusid IN(2, 4)
GROUP BY d.bunoid, f.downloadtimeid, d.downloadtime, f.faultcode

As it doesn't strictly matter where the filter requirements on  fs_fault are.  (and your SQL engine's going to change that all up anyway).
Edit: Here's a SQLFiddle demonstrating filtering on the join clause vs. the where clause.


Q:

MapFragment: bad performance after using the back button

I have a performance issue when using MapFragment together with the action bar menu.
The bug emerges when three conditions are met

Have a MapFragment instantiated.
Trigger a fragment transaction from the options menu, replacing the map fragment with another fragment.
Hit the back button and return to the map fragment. The performance is now noticeably degraded. Panning and zooming is very jerky.

Opening the options menu again and dismissing it again fixes the issue.
The behavior does not arise when

Triggering the fragment replacement from a view button instead from the options menu.
Triggering the fragment replacement right in onCreate()
replacing the blank fragment with MapFragment from the options menu
calling popBackStack from the options menu
using a ListFragment instead of a MapView

Minimal working example (requires access to Google Maps API):
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.maps.MapFragment;

public class MapFragmentBugActivity extends Activity {
    Fragment mMapFragment;
    String MAP = "Map";
    String BLANK = "Blank";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_bug);
        mMapFragment = new MapFragment();
        getFragmentManager().beginTransaction()
                .replace(R.id.main, mMapFragment)
                .commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(MAP);
        menu.add(BLANK);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Fragment fragment;

        if (item.getTitle().equals(MAP)) {
            fragment = mMapFragment;
        } else {
            fragment = new Fragment();
        }

        getFragmentManager()
                .beginTransaction()
                .replace(R.id.main, fragment)
                .addToBackStack(null)
                .commit();

        return true;
    }
}

Activity layout, nothing special
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" />

A:

The fragment transaction is performed before the options menu is closed, this causes the weird behavior.
Instead of directly performing the fragment transaction, post it on the Handler. Once the options menu is closed, then the fragment transaction will be performed.
Try this :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Fragment fragment;

    if (item.getTitle().equals(MAP)) {
        fragment = mMapFragment;
    } else {
        fragment = new Fragment();
    }

    Handler handler = new Handler();
    handler.post(new Runnable() {

        @Override
        public void run() {
            getFragmentManager()
            .beginTransaction()
            .replace(R.id.main, fragment)
            .addToBackStack(null)
            .commit();
        }

    });

    return true;
}


Q:

Determining request size to mitigate 'The request message is too big.'

Using SharePoint Online (2013) we are encountering this issue occasionally when creating folders in batch.

Exception calling "ExecuteQuery" with "0" argument(s): "The request message is too big. The server does not allow messages larger than
  2097152 bytes."

Is there a way to determine the message size prior to doing $Context.ExecuteQuery() to prevent this?

A:

Here's a example for JS - if you are using C# I can't promise that you can access the same functionality to measure the request.
JS
I found the piece that is creating the request - you can get the string via ctx.get_pendingRequest().$2x_0().toString(). Afterwards you simply try to get the bytelength via JS (reference).
Working example:
var stringToByte = function(str){
  return encodeURI(str).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1;
}

var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var webs = web.get_webs();

ctx.load(webs);

alert('Current size is ' + stringToByte(ctx.get_pendingRequest().$2x_0().toString()) + 'bytes');

ctx.load(webs, 'Include(AllProperties, Title)');

alert('Current size is ' + stringToByte(ctx.get_pendingRequest().$2x_0().toString()) + 'bytes');

C#
I managed to get at least some vague Information via the GarbageCollector. Here's the full example:
using Microsoft.SharePoint.Client;
using System;
using System.Linq;

namespace Tester
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            try
            {
                var measure = new GcMeasurer();
                ClientContext ctx = new ClientContext("https://sharepoint");

                for (var i = 0; i < 1500; i++)
                {
                    measure.StartMonitor();
                    ctx.Web.AllProperties["_Tester" + i] = RandomString(1000);
                    measure.EndMonitor();
                    Console.WriteLine(BytesToString(measure.GetSize()));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            Console.Read();
        }

        private static readonly Random Random = new Random();

        public static string RandomString(int length)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            return new string(Enumerable.Repeat(chars, length)
              .Select(s => s[Random.Next(s.Length)]).ToArray());
        }

        private static String BytesToString(long byteCount)
        {
            string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB
            if (byteCount == 0)
                return "0" + suf[0];
            long bytes = Math.Abs(byteCount);
            int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
            double num = Math.Round(bytes / Math.Pow(1024, place), 1);
            return (Math.Sign(byteCount) * num).ToString() + suf[place];
        }
    }

    internal class GcMeasurer
    {
        private long CurrentSize { get; set; }
        private long MonitoredSize { get; set; }

        internal GcMeasurer()
        {
            CurrentSize = 0;
        }

        internal void StartMonitor()
        {
            MonitoredSize = GC.GetTotalMemory(true);
        }

        internal void EndMonitor()
        {
            CurrentSize += GC.GetTotalMemory(true) - MonitoredSize;
        }

        internal long GetSize()
        {
            return CurrentSize;
        }
    }
}


Q:

paging a heavy document using jquery and mvc

I have a html document but it's size is about 5MB.
Here is my code "../Product/index?page=1" it generates 5MB html :
Plugin url : http://andersonferminiano.com/jqueryscrollpagination/

    @{
    // here is "Product/index" Code
    if (Request.QueryString.HasKeys())
    {
        int iPage = Request.QueryString["page"].AsInt();
        using (var db = new PNUBOOKIR.Models.KowsarSiteEntities())
        {
            var queries = from n in db.vwGood
                          select n;
            long counter = 0;
            for (int i = 1; i <= iPage; i++)
            {
                foreach (var q in queries)
                {
                    counter++;

            @counter

                }
            }
        }
    }
}

I don't want to load it complete when the scroll goes down it should load 10 other "li" element

A:

I do not simulate so heavy page, but I have an other way to load page. Maybe, it can be a reference for you.

Separate each page request at action side, and return for only one page content.
Collect "style" content to css class, to reduce page content.
Improve performance of LINQ with PLINQ.

I notice the code output every page content.
var queries = from n in db.vwGood select n;
        long counter = 0;
for (int i = 1; i <= iPage; i++)
{
    foreach (var q in queries)
    {
        counter++;
    }
}

I suggest you can

modify LINQ with Paging function.
Update LINQ as PLINQ to improve performance. I add AsParallel() after db.vwGood, I am not sure what db.vwGood instance and wish this modify can be good.
Not return HTML content in Razor View, but in Action.

Pseudo code of Action is as below,
// iAmount is record amount in each page.
int iAmount = 50;
// queries is only the iPage content
// but not all of content from page one to page iPage.
var queries = (from n in db.vwGood.AsParallel() select n)
              .Skip(iPage - 1).Take(iAmount);
long counter = 0;
string strContent = string.Empty;
foreach (var q in queries)
{
    counter++;
    // Generate Cotnent here.
    strContent += @"

@counter

"
}
return Content(strContent)

When ShowMore button is clicked, ShowMore_OnClick() is performanced.
<input type="button" style="width: 100%" id="BtnShowMore" value="MORE"
    onclick="return ShowMore_OnClick();" />

This is JavaScript for Loading function.
I notice you do not use button to control content display, but scrollPagination. You can modify the JavaScript to suit with scrollPagination plugin. The thinking of code structure is same.
    var PageNO = 1;
    function ShowMore_OnClick() {
        var BtnShowMore = document.getElementById("BtnShowMore");
        BtnShowMore.value = "Loading...";
        jQuery.post(
            "/Home/GetHomeEventAjax/",
            { "PageNO": PageNO + 1 },
            function (data, states) {
                if (states == "success") {
                    var EventListArea = document.getElementById("EventListArea");

                    var newCommentItem = document.createElement("DIV");
                    newCommentItem.setAttribute("ID", "EventItem");
                    newCommentItem.innerHTML = data;
                    EventListArea.appendChild(newCommentItem);
                    PageNO = PageNO + 1;
                    BtnShowMore.value = "More";
                }
            }
        );
    }


Q:

How can I get information from a list inside json using jquery or javascript?

I have the following C# class:
public class JsonBackup
{
    public int Added { set; get; }
    public int DEVCount { set; get; }
    public int DS1Count { set; get; }
    public IList<ViewEvent> Events { get; set; }
}

and this is used to return a Json string like this:
return Json(new JsonBackup
            {
                Added = added,
                DEVCount = devCount,
                DS1Count = ds1Count,
                Events = t.Events
            });

I have the following javascript call:
$.ajax({
        url: $(this).attr('data-href'),
        dataType: 'json',
        type: 'POST'
    })
        .done(function (data) {
            backupDone(data, ajaxElapsed);
        })

I know that I can get the data.Added etc properties but how can I get the Event information that's
part of the Events list?
Here's an example of the C# class that has the event data:
public class ViewEvent {
    public long Elapsed { get; private set; }
    public ET EventType { get; private set; }
    public string Description { get; private set; }
    public string Message { get; private set; }
    public int Quantity { get; private set; }
}

What I really need is some JQuery or javascript way to get the following information out of what is returned from the Ajax call and add it to the ul element with the id="stats"

@viewEvent.Description : @viewEvent.Elapsed ms

A:

The code you need in your done function would look something like this:
$.each(data.Events, function (i, item) {
    $('ul#stats').append('
' + item.Description + ' : ' + item.Elapsed + ' ms
');
});


Q:

How to get sendmail working in Alpine Docker container?

I just want to send simple email for testing purposes, but when executing sendmail inside the container, I get sendmail: can't connect to remote host (127.0.0.1): Connection refused. What do I need to take into account when using sendmail inside Alpine container?

A:

In a container there will be no running MTA (mail transport agent), simply there is no mail server running. For example, you can use ssmtp (https://pkgs.alpinelinux.org/package/edge/main/x86/ssmtp) and configure it to use an outside, for example your providers, smtp-server (eg. mail.yourprovider.com).
Than you can use ssmtp to send email. Here is a similar case where sending mail from inside the php Docker image is not possible. Here you can read further -> https://github.com/docker-library/php/issues/135


Q:

can any one can clear me some naming conventions in cake php for every mvc folder and files

I checked in web for example and I found naming example as:
Database table: books
Model class: Book
Controller class: BooksController
View found at: /app/views/books/index.ctp

Why only model name should be singular? If I crated all field with page or book means what should be given in model.

A:

Yeah only model can be singular, you should use Book, if there are fields in the table, you shouldn't have to add anything in the model unless you have validations.
I think this link will explain you more
Why does CakePHP use different plural/singular naming conventions?
Hope it helps


Q:

Install Spree Commerce on cPanel Server

Sorry I'm a newbie with Ruby on Rails. I have a cPanel Server with ruby 1.8.7 and Rails 3.0.10.I downloaded Spree Commerce from GitHub and upload them to public_html. But what's next?

A:

I would not recommend installing Spree Commerce on a cPanel Hosting for the following reasons

It takes really a lot and lot of time and effort to do so
Really requires a strong experience to implement in cPanel environment and even though it is waste to invest time on that
I Hardly doubt if anyone recommends it

Deciding Spree deployment on a cPanel hosting is not a wise decision and better prefer any other deployment method.
Alternatively i would recommend getting a VPS from any hosting company if that suits your budget and try deploying on VPS instance .
There is also "Deploying to Heroku" guide specifically built for situations like that.
Also , have you tried sandbox available from Spreecommerce . Even though it wouldn't allow you to install extensions you can try that too to get a feel out of the box for free.


Q:

Decode synth preset formats for massive (.nmsv) fm8 (.nfm8) and absynth (.nabs)

I'm trying to decode the file formats for Massive, FM8 and absynth VST synths. The file format is binary with several sections. Reason for this endeavour is to convert the above formats to general vst .fxp format for automated loading and rendering of presets through the vst api.
From experimenting with saving the files when changing synth parameters I've found out following facts about the format:

File starts out with length field
File contains some fixed length sections introduced by "DSIN", "hsin" markers
The vst binary chunk returned by effGetChunk vst sdk api calls are 99% similar to the .nmsv, .nabs, .nfm8 preset file content
changing a single parameter in the synth changes some bytes at several places (3-4) in the file
The main section of the preset file seems to be compressed, while synth parameters should be float values between 0 and 1 they don't seem to be written as floating points into the file - apart from unrecognizable binary values there are plaintext strings e.g. for user defined macros there seems to be some sort of compression applied to the raw data. Compression seems to reference previously encountered strings and reference these strings in later portions of the stream:
If "THIS_IS_A_MACRO_NAME_ABC" is preceding "THIS_IS_A_MACRO_NAME_XYZ" in the stream the second string will be compressed to "[short sequence of bytes]_XYZ".
The files do not seem to contain any dictionary for compression which makes me think the dictionary must be stored somewhere else or there might not be a dictionary at all.

Could anyone help out here:

What compression scheme could be applied here?
Does anyone know about a similar format that has been successfully decoded?

Added an example file:
http://s000.tinyupload.com/index.php?file_id=08960658549599455274 contains a sample file. The string "TESTSTRING1" and "PREFIXTESTSTRING1SUFFIX" are contained in the uncompressed stream.
Shannon entropy is 5.84154 for the data chunk which is somewhere in the middle between english text and encrypted.

Here is an example which should demonstrate how the lenght field is computed:
The string "TESTSTRING123" precedes the string "PREFIX...SUFFIX".
                             P  R  E  F  I  X  L1 L2 D     S  U  F  L1 D
----------------------------------------------------------------------------------------
PREFIXTESTSTRING123SUFFIX 05 50 52 45 46 49 58 E0 04 16 02 53 55 46 20 12 40 42 00
PREFIXTESTSTRING12SUFFIX  05 50 52 45 46 49 58 E0 03 16 02 53 55 46 20 11 40 41 00
PREFIXTESTSTRING1SUFFIX   05 50 52 45 46 49 58 E0 02 16 02 53 55 46 20 10 40 40 00 33 40
PREFIXTESTSTRINGSUFFIX    05 50 52 45 46 49 58 E0 01 16 02 53 55 46 20 0F 40 3F 00 33 40
PREFIXTESTSTRINSUFFIX     05 50 52 45 46 49 58 E0 00 16 02 53 55 46 20 0E 40 3E 00 33 40
PREFIXTESTSTRISUFFIX      05 50 52 45 46 49 58 C0    16 02 53 55 46 20 0D 40 3D 00 33 40
PREFIXTESTSTRSUFFIX       05 50 52 45 46 49 58 A0    16 02 53 55 46 20 0C 40 3C 00 33 40
PREFIXTESTSTSUFFIX        05 50 52 45 46 49 58 80    16 02 53 55 46 20 0B 40 3B 00 33 40
PREFIXTESTSSUFFIX         05 50 52 45 46 49 58 60    16 02 53 55 46 20 0A 40 3A 00 33 40
PREFIXTESTSUFFIX          05 50 52 45 46 49 58 60    16 01    55 46 20 09 40 39 00 33 40
PREFIXTESSUFFIX           05 50 52 45 46 49 58 20    16 02 53 55 46 20 08 40 38 00 33 40
PREFIXTESUFFIX            05 50 52 45 46 49 58 20    16 01    55 46 20 07 40 37 00 33 40
PREFIXTSUFFIX             09 50 52 45 46 49 58 54 53 55 46 20 06 40 36 00 33 40

A:

I think the results of your well-designed tests help explain pretty much everything.
It is an LZ77 variant.  Try the following scheme for decoding the length and offsets.  (Encoded bytes are shown below as 8 binary bits.)
1st byte  2nd byte  3rd byte      token type  length    offset(*)
========  ========  ========      ==========  ======  ==============
000qqqqq     --        --     =>  literal     1 + Q         --
001qqqqq  rrrrrrrr     --     =>  dictionary  3       (Q<<8) + R + 1
010qqqqq  rrrrrrrr     --     =>  dictionary  4       (Q<<8) + R + 1
011qqqqq  rrrrrrrr     --     =>  dictionary  5       (Q<<8) + R + 1
100qqqqq  rrrrrrrr     --     =>  dictionary  6       (Q<<8) + R + 1
101qqqqq  rrrrrrrr     --     =>  dictionary  7       (Q<<8) + R + 1
110qqqqq  rrrrrrrr     --     =>  dictionary  8       (Q<<8) + R + 1
111qqqqq  rrrrrrrr  ssssssss  =>  dictionary  9 + R   (Q<<8) + S + 1

* the offsets are backwards in the decoded data from the current output position.

Edit
The whole file from offset 00000410 onwards appears to be decompressible using the above encoding scheme.
Doing so gives me the below.  You can see that the end of my first excerpt has a number of 32 bit floating point values.  The 2nd excerpt has your test string.
00000000:  F9 15 00 00 00 00 00 00 01 00 00 00 68 73 69 6E  ............hsin
00000010:  01 00 00 00 00 00 00 00 EC 2D F1 91 50 BC 4D 41  .........-..P.MA
00000020:  96 E1 F3 EA B1 70 A9 B9 18 00 00 00 00 00 00 00  .....p..........
00000030:  44 53 49 4E 01 00 00 00 01 00 00 00 01 00 00 00  DSIN............
00000040:  01 00 00 00 01 00 00 00 00 00 00 00 44 53 49 4E  ............DSIN
00000050:  6D 00 00 00 A5 15 00 00 00 00 00 00 01 00 00 00  m...............
00000060:  68 73 69 6E 01 00 00 00 00 00 00 00 85 50 7B 20  hsin.........P{
00000070:  83 65 FA 41 80 7B CA 65 CA E4 1D FA 75 15 00 00  .e.A.{.e....u...
00000080:  00 00 00 00 44 53 49 4E 6D 00 00 00 01 00 00 00  ....DSINm.......
00000090:  18 00 00 00 00 00 00 00 44 53 49 4E 01 00 00 00  ........DSIN....
000000A0:  01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00  ................
000000B0:  01 00 00 00 2D 15 00 00 00 00 00 00 18 00 00 00  ....-...........
000000C0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000E0:  00 00 00 3F 00 00 7D 3F 00 00 80 3F 00 00 80 3F  ...?..}?...?...?
000000F0:  00 00 00 3F BA 9E FF 3E 00 00 80 3F 00 00 80 3F  ...?...>...?...?
00000100:  00 00 80 3F 00 00 00 3F A6 30 00 3F 00 00 80 3F  ...?...?.0.?...?
00000110:  00 00 70 3F 00 00 80 3F 00 00 00 3F 00 00 80 3F  ..p?...?...?...?
00000120:  00 80 91 3E 00 00 00 3F 00 00 00 00 00 00 00 3F  ...>...?.......?
00000130:  00 00 00 3F 00 00 00 3F 00 00 00 3F 00 00 00 3F  ...?...?...?...?
00000140:  00 00 00 3F 00 40 41 3F 00 00 00 3F 00 00 00 00  ...?.@A?...?....
00000150:  00 80 99 3E 00 00 00 3F 00 00 00 3F 00 00 00 00  ...>...?...?....
00000160:  00 00 00 3F 00 00 00 3F 00 00 00 3F 00 00 00 3F  ...?...?...?...?
...
00000430:  00 00 00 00 00 01 00 00 00 07 00 00 00 00 00 00  ................
00000440:  00 00 00 00 00 01 01 00 00 00 00 C0 00 00 00 40  ...............@
00000450:  01 01 00 00 00 00 00 01 00 00 00 0B 00 00 00 54  ...............T
00000460:  45 53 54 53 54 52 49 4E 47 31 17 00 00 00 50 52  ESTSTRING1....PR
00000470:  45 46 49 58 54 45 53 54 53 54 52 49 4E 47 31 53  EFIXTESTSTRING1S
00000480:  55 46 46 49 58 01 00 00 00 33 01 00 00 00 34 01  UFFIX....3....4.
00000490:  00 00 00 35 01 00 00 00 36 01 00 00 00 37 01 00  ...5....6....7..
000004A0:  00 00 38 04 00 00 00 00 00 00 00 55 55 29 41 02  ..8........UU)A.
...


Q:

AChartEngine : Align Y-Axis Labels on right side of Axis itself

i am using aChartEngine for android. i have a problem with the y-axis, when the values reaches 10000 or more, the left digit is disappeared (Check the photo) in the photo the values are 7000-11500 but the values appearing above 10000 are 0000,0500, . . . etc
I would like to set the y-axis labels on the right side of the axis or something like that
can anyone help ?
knowing that i used
renderer.setYLabelsAlign(Align.RIGHT);

A:

You can tweak the margins of your chart:
renderer.setMargins(margins);

where margins is an array of [top, left, bottom, right]
If you want to set the alignment on the right side of the grid, just set Align.LEFT, which means they are align on the left.


Q:

How can I catch JS exceptions from async functions I don't control?

I know using try..catch for async functions doesn't work, and most advice I've read suggests using it inside the passed callback.
However, without control over the async function which throws the exception, what can one do to catch it? In my example it's chrome.bookmarks.create, which fails on some edge cases.

A:

In Chrome extensions, there are three possible ways of catching asynchronous errors:

Listen to global error events using window.onerror.
In the callback of asynchronous functions, check the value of chrome.runtime.lastError.


Q:

What dateformat is that?

I have to migrate old data to a new website and in the mysql-table is a column called date with a example value of "1308355200" but which datenformat is that can you help me?

A:

Explainations
A timestamp is a way to communicate a date easily. You are aware that in some region, date format are not the same. And that's a problem in programing because we would have to manage every format, in every programing language. Timestamp is universal and most of the programing language (if not all of them) are able to manage timestamp.
Now, PHP offers you a way to translate that timestamp into something more readable with the date() function.
Source-code
<?php

/* database processing here... */

$date = 1308355200; /* value you got from a database query */

$datestring = date('d F, Y', $date);
/* d : day, F : full month, Y : year */

echo 'The date we got from the database: ' . $datestring;

Output
The date we got from the database: 17 June, 2011

Documentation
Wikipedia : timestamp.
PHP : date().
Online demo
Online demo.


Q:

Make this dot plot in R

I am attempting to make the image shown here:

Using R code. Is there something better than dot plot for this type of figure? Basically I want to show the means and variability between two groups for 6 variables. Sample data provided below. Thanks a million!
 id var1 var2 var3  var4 group
 1  12    3    22   60    1
 2  8     6    19   55    1
 3  25    30   70   26    2
 4  26    31   75   31    2
 5  22    29   80   29    2

A:

For what it's worth, the down-votes are a bit harsh IMO, but I think you could've improved the quality of your question by adding what you've tried so far. The SO community is usually very quick and eager to help, provided you demonstrate that you've done some work before. I didn't down-vote your question but the down-votes you've accrued are most likely due to the lack of attempt from your side. For future questions you should take a look at how to ask questions, and what you can do to provide a minimal reproducible example/attempt.
That aside, here is an example that should get you started
library(tidyverse)
df %>%
    gather(variable, v, -id, -group) %>%
    group_by(group, variable) %>%
    summarise(value = mean(v), value.sd = sd(v)) %>%
    ungroup() %>%
    mutate(
        variable = as.factor(variable),
        group = as.factor(group)) %>%
    ggplot(aes(x = value, y = variable, shape = group)) +
        geom_point(size = 4) +
        geom_segment(aes(x = value - value.sd, xend = value + value.sd, yend = variable))

Sample data
df <- read.table(text =
    "id var1 var2 var3  var4 group
 1  12    3    22   60    1
 2  8     6    19   55    1
 3  25    30   70   26    2
 4  26    31   75   31    2
 5  22    29   80   29    2", header = T)


Q:

How do you run a file-reading program on itself in C?

I have only Java experience, and I'm starting to learn C through the K&R C book, second addition. In the first chapter, one of their examples is this program which simply counts the white space, characters, and digits:
#include <stdio.h>

main()
{
int c, i, nwhite, nother;
int ndigit[10];

nwhite = nother = 0;
for(i = 0; i < 10; i++){
    ndigit[i] = 0;
}

while((c = getchar()) != EOF){
    if(c >= '0' && c <= '9'){
        ++ndigit[c-'0'];
    }
    else if (c == ' ' || c == '\n' || c == '\t'){
        ++nwhite;
    }
    else{
        ++nother;
    }
}

printf("digits =");
for(i = 0; i <10; ++i){
    printf(" %d", ndigit[i]);
}
printf(", white space = %d, other = %d\n", nwhite, nother);

}
Next, in the book they say "the output of this program run on itself is " followed by its output. However, I've compiled the program in the terminal and just cannot figure out how to run this program on itself in C. In java, I would have passed the file name to String args[0] and read it from there, but this program doesn't have any similar mechanism, and doesn't seem to have an args array to pass to. Even if it did, the code itself doesn't seem to read from any particular file (for example, in java you could specifically set up a scanner to read args[0], and then call scanner.next() etcetc, but in this program, it just calls getchar() on seemingly nothing). Can anyone help me clear this up so I can run the program before continuing? Sorry if this is something super simple, like I said my experience in C is nonexistent. Thank you!
Also my formatting on this website is trash I apologize

A:

I assume they intend to run this program like so:
./example < example.c

You are correct about the fact that the program does not open a file and it does not use arguments. The getchar() function operates on stdin.
The program does not make much sense if you use it on the compiled file, so that is why I assumed it is supposed to be run with the source file. I see how the instructions are confusing.


Q:

How to disable PIN on SIM card

My SIM card is stuck inside the slot of my laptop and I can't get it out without causing further damage to my laptop.
Every time I log in gnome-shell prompts me for the PIN. Whether I am about to use it or not.
On my phone I know I can disable the PIN altogether so that it doesn't get requested again (even if place the SIM card on another device). How can I do the same in Ubuntu?

A:

You can disable PIN checking using the built in GSM modem as described here.


Q:

Calculated field and creating pie chart/donut using this calculated field

I have this following table
| Name | Group | Group1 | Group2 | Course  | Completed |
|------|-------|--------|--------|---------|-----------|
| abc  | Engg  | Civil  | single | engg1   | y         |
| abc  | Engg  | Civil  | single | math123 | y         |
| abc  | Engg  | Civil  | single | advmath | y         |
| def  | Engg  | Mech   | single | engg1   | y         |
| def  | Engg  | Mech   | single | math123 | n         |
| def  | Engg  | Mech   | single | advmath | y         |
| ghi  | Engg  | Civil  | double | engg1   | y         |
| ghi  | Engg  | Civil  | double | math123 | n         |
| ghi  | Engg  | Civil  | double | advmath | n         |
| ijk  | Engg  | Mech   | double | engg1   | y         |
| ijk  | Engg  | Mech   | double | math123 | y         |
| ijk  | Engg  | Mech   | double | advmath | y         |

I am trying to create a pie/donut chart to show % of students that have not completed all the course.
Can someone please help?

A:

If you want to compare completed = y versus completed = n simply:

create a new sheet
double click on the completed field (to add it to the sheet)
double click on [Number of Records] (to add it to the sheet)
Click on Show Me (top right) and choose pie graph

It should look like this in the end ....
EDIT: ah ok, I understand the data now, here's the result by creating 2 calculated fields:


Q:

Memory Game - How to match with different images?

I know it might sound strange but i need to make a memory game that matches different images instead of two same images, like for an example, number one and a hand with raised index finger
Here is my actual code that matches two same images, it clones the card making the same image appear twice
Scene Controller below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneController : MonoBehaviour {

public const int gridRows = 2;
public const int gridCols = 5;
public const float offsetX = 4f;
public const float offsetY = 5f;

[SerializeField] private MainCard originalCard;
[SerializeField] private Sprite[] images;

private void Start()
{
    Vector3 startPos = originalCard.transform.position; //The first position of the cards, all other cards are based on this one

    int[] numbers = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4};
    numbers = ShuffleArray(numbers);

    for(int i = 0; i < gridCols; i++)
    {
        for(int j = 0; j < gridRows; j++)
        {
            MainCard card;
            if(i == 0 && j == 0)
            {
                card = originalCard;
            }
            else
            {
                card = Instantiate(originalCard) as MainCard;
            }

            int index = j * gridCols + i;
            int id = numbers[index];
            card.ChangeSprite(id, images[id]);

            float posX = (offsetX * i) + startPos.x;
            float posY = (offsetY * j) + startPos.y;
            card.transform.position = new Vector3(posX, posY, startPos.z);
        }
    }
}

private int[] ShuffleArray(int[] numbers)
{
    int[] newArray = numbers.Clone() as int[];
    for(int i = 0; i < newArray.Length; i++)
    {
        int tmp = newArray[i];
        int r = Random.Range(i, newArray.Length);
        newArray[i] = newArray[r];
        newArray[r] = tmp;
    }
    return newArray;
}

//-------------------------------------------------------------------------------------------------------------------------------------------

private MainCard _firstRevealed;
private MainCard _secondRevealed;

private int _match = 5;
[SerializeField] private TextMesh matchLabel;

public bool canReveal
{
    get { return _secondRevealed == null; }
}

public void CardRevealed(MainCard card)
{
    if(_firstRevealed == null)
    {
        _firstRevealed = card;
    }
    else
    {
        _secondRevealed = card;
        StartCoroutine(CheckMatch());
    }
}

private IEnumerator CheckMatch()
{
    if(_firstRevealed.id == _secondRevealed.id)
    {
        _match--;
        matchLabel.text = "Pares Restantes: " + _match;
        if(_match == 1){
            matchLabel.text = "Somente " + _match + " Par Restante";
        }
        if(_match == 0){
            SceneManager.LoadScene("Sucesso");
        }
    }
    else
    {
        yield return new WaitForSeconds(0.5f);

        _firstRevealed.Unreveal();
        _secondRevealed.Unreveal();
    }

    _firstRevealed = null;
    _secondRevealed = null;

}

public void Menu()
{
    SceneManager.LoadScene("Menu");
}

public void Fases()
{
    SceneManager.LoadScene("Fases");
}

public void Sair()
{
    Application.Quit ();
}

public void Level1()
{
    SceneManager.LoadScene("Level 1");
}

public void Sucesso()
{
    SceneManager.LoadScene("Sucesso");
}

}

Main Card Class Below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MainCard : MonoBehaviour {

[SerializeField] private SceneController controller;
[SerializeField] private GameObject Card_Back;

public void OnMouseDown()
{
    if(Card_Back.activeSelf && controller.canReveal)
    {
        Card_Back.SetActive(false);
        controller.CardRevealed(this);
    }
}

private int _id;
public int id
{
    get { return _id; }
}

public void ChangeSprite(int id, Sprite image)
{
    _id = id;
    GetComponent<SpriteRenderer>().sprite = image; //Isso pega o Sprite Renderer e muda a propriedade do Sprite
}

public void Unreveal()
{
    Card_Back.SetActive(true);
}

}
PS: Sorry for my english

A:

You can encapsulate each image in an object of a class like this simple example:
class CardImage : MonoBehaviour
{
    public Sprite cardSprite;
    public int cardNumber;
}

Then in your game logic, you can check the cardNumber field for comparing two cards like this :
if (card1.cardNumber == card2.cardNumber)
{
// Do what you have to do when two cards are equal
}

For more information about OOP and Encapsulation see this


Q:

How to dismiss modal ViewController from UIAlertcontroller

I show a modal viewcontroller on which the user can decide to edit oder delete the presented car.
If the user wants to delete this car I present an UIAlertController with alert style to ask if he really wants to delete this car. Everything works fine. But after the user chooses "Yes" I am still in the modal viewcontroller.
How can I dismiss the modal view after the deletion?
I tried Following Code
self.parentViewController?.dismissViewControllerAnimated(true, completion: nil)

and
self.navigationController?.popViewControllerAnimated(true)

in the closure of the ok Action but both didn't worked for me. :(

A:

Put your code inside the
 dispatch_async(dispatch_get_main_queue(), {    //write your code here

 })

like that :
func showDeleteWarningAndDeleteEntity() {

    dispatch_async(dispatch_get_main_queue(), {

         let deleteController = UIAlertController(title: "Delete car", message: "Are you sure?", preferredStyle: .Alert)
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) {
        (action) in
    }
    let okACtion = UIAlertAction(title: "Yes", style: .Destructive) {
        (action) in
        //some network stuff happens here...

        self.dismissViewControllerAnimated(true, completion: nil)
    }
    deleteController.addAction(okACtion)
    deleteController.addAction(cancelAction)
    self.presentViewController(deleteController, animated: true, completion: nil)
     })

}

Hope this will works for you


Q:

How to interpret Employment Elasticity in this text?

In this VoxEU text, «Promising ideas for future research on the employment effects of minimum wages », how do I interpret the elasticity of employment?
I would think of it as percentual change in quantity of labour demanded over percentual change in minimum wage. However, if I google the concept, I get % change in employment associated with a % change in output. Ok, Factor Incomes = Expenditures = Output. However, although at a national level they are the same, at a micro level, I don't see how both definitions would equate...
Any help would be appreciated.

A:

I'm citing the first two lines of the article you refer to (emphasis mine):

The debate among researchers about the employment effects of minimum wages remains intense and unsettled. There is clear variation in the magnitude of estimated employment effects across studies, with the debate often being between an elasticity for low-skilled groups equal to (or indistinguishable from) zero, or an elasticity in the range of −0.1 to −0.2.

Mechanically, you can always compute elasticities of any two variables w.r.t. each other at an initial point $b$, which is defined as
$$\eta_{a, b} = \frac{\partial a(b)}{\partial b}\frac{b}{ a(b)}$$
Simply googling employment elasticity gives you
$$\eta_{employment, X}$$
where $X$ is the unknown. What is it, that employment is elastic towards?
The article makes clear that indeed, $a$ in this context is the employment rate, while $b$ is the level of the minimum wage.
Instead of googling, you could have looked at any of the studies cited in the article. The first sentence in Dube et al (2010) actually states that

We use policy discontinuities at state borders to identify the
  effects of minimum wages on earnings and employment in restaurants
  and other low-wage sectors.

So they're interested in two related elasticities, one of which was the one you initially suspected. Their table 2 will give you some estimates of those elasticities.


Q:

CollectionViewSource Grouping "All Items"

I have created a CollectionViewSource as follows:
<CollectionViewSource x:Key="MyGrouping" Source="{Binding MyCollection}">
    <CollectionViewSource.SortDescriptions>
        <componentModel:SortDescription PropertyName="Name"/>
    </CollectionViewSource.SortDescriptions>
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="Type"/>
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

I then define a TabControl as follows:
<TabControl ItemsSource="{Binding Groups, Source={StaticResource MyGrouping}}">
    <TabControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
                <DataGrid.Resources>

.....
All of the grouping works perfectly. However, I wanted to add an additional Tab that contains ALL of the items (ungrouped).
Is there a simple mvvm approach to doing this? Any help would be greatly appreciated.

A:

A basic idea is to create custom ListCollectionView with customized CollectionViewGroup. Below is the example.
public class CustomGroupListCollectionView : ListCollectionView
{
    private readonly CustomGroup _allGroup;

    public CustomGroupListCollectionView(IList list)
        : base(list)
    {
        _allGroup = new CustomGroup("All");
        foreach (var item in list)
        {
            _allGroup.AddItem(item);
        }
    }

    public override ReadOnlyObservableCollection<object> Groups
    {
        get
        {
            var group = new ObservableCollection<object>(base.Groups.ToList());
            group.Add(_allGroup);
            return new ReadOnlyObservableCollection<object>(group);
        }
    }
}

public class CustomGroup : CollectionViewGroup
{
    public CustomGroup(object name)
        : base(name)
    {
    }

    public void AddItem(object item)
    {
        ProtectedItems.Add(item);
    }

    public override bool IsBottomLevel
    {
        get { return true; }
    }
}


Q:

Inserting a Column to preexisting table in phpmyadmin

I want to add a column to preexisting table.
Can I add it in between two existing columns?
I am working on phpmyadmin.

A:

Use the add new column after dropdown.

Select the database from the menu on the left.
Select the table by clicking on it's title column hyperlink.
Check the add new column after radio button and select the column
you want to insert after in the drop down.
Click Add.

This video goes through the process http://www.youtube.com/watch?v=jZ72GCGWPQg

A:

You want something like:
ALTER TABLE contacts ADD email VARCHAR(60);

A:

The ordering of columns in MySQL isn't of much importance. As for adding a new column,
ALTER TABLE `tblName`
    ADD COLUMN `colName` INT(10) AFTER `firstCol`;

The AFTER clause defines the position where your new column will come.


Q:

Cannot use relative path when using 'Execute Line in Console' in Pycharm

I'm using Pycharm for python project. My project structure is like this:
+ project
  + src
    - Data.csv
    - main.py

This is main.py:
import panda as pd
dataset = pd.read_csv("Data.csv")

When i use 'Execute Line in Console' and run the second line, i get this error:
Traceback (most recent call last):
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-bd7168d85704>", line 1, in <module>
    dataset = pd.read_csv('Data.csv')
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 429, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 895, in __init__
    self._make_engine(self.engine)
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1122, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1853, in __init__
    self._reader = parsers.TextReader(src, **kwds)
  File "pandas\_libs\parsers.pyx", line 387, in pandas._libs.parsers.TextReader.__cinit__
  File "pandas\_libs\parsers.pyx", line 705, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: [Errno 2] File b'Data.csv' does not exist: b'Data.csv'

When i run the whole code using 'Run', it's fine, so i think that executing in console changes the directory. But i haven't figured out how to fix.

A:

To fix it, just close your current project and open another project which contain your file directly.


Q:

How can I submit a transaction created in --do-not-relay mode?

I've created a transaction in wallet started with --do-not-relay switch. It landed in raw_monero_tx file.
How can I push it to the network using wallet software? I know about online pushers but want to do it locally.
submit_transfer looks for signed_monero_tx and requires the file to have magic prefix.

A:

The content of raw_monero_tx is a raw byte array of a complete tx that is meant to be passed to the daemon RPC /sendrawtransaction. Here's an example on testnet (you need to have your testnet daemon running by doing monerod --testnet):
~$ cat raw_monero_tx
020001020005f9fb16bd06109503a60b334796e4c5cdcee80129056d2761a09282c0133c40d156dbc8fd18ef39ed39f102000209bbbc3bb0a02efc2a80387d0958eff044498751d88759967ec012a341b677990002c831025bc303f8c168d4e28e9db6c1ea96fc600bb5b162b58f2ebbab5412ecc621018a7d5c720c9eb07fbf6af552ff115f315f791d624a9149b4c26ae4ccdcb9d28d0380b5a7ce0ed63f5036a8c7fdb147d08417960f50569d86ddd08f36529a4f0521cc0b38440a29287970ac7fe91ccf49b01dd06c31c3479bfa55ef9dc75b4e677129e4d5cd019576a472d30ecc77934b1c20c957de143023e6ea815bb430073aadd41b0bd6064075c6a646962532f4cd59131f7a4d9b6195dd12dd3df9460786ef154e736f0dc0d8e8e86051308d880acba05e2025f3e1c4577ee057920dfe23f8e0584978a3af3063fefee0f16645b9219041d72f5cd5f7a6a91181230d4e47d2cbfd33b998dae0d4798afda673d6898bbbb6b0f208bc4730e435eccb3304f4083fa40b2a49dc0dbe7eda7981642a92beebb063d946bd70f487c97700103fd18a210689c4e5e49db58d54ea2c91dc6aebdade23b61c436cb962c6cda1e16a643736ec5c5762981d3d2a628bfdce6159754378631e046d3699d392b2dc2daf94b93e157bd036e07e56b613babeeb3d4d5d09a788224e4bee8be0f416ff0b6a3fb17b1b998803f583fde86e587dd2867bd4cf68795e2012c35105f6cdbd6b2fbec4e3f0067d0d06ebf567e3f6da01b25d35989406f204a2319858d6c78d3bb7eed5d8ba830aec6d2f0337932dab4b71f1d38a14207159716b1a95eeb05213e3ed774427ff7c3c895f208c4800e11a3783c9f02d7d405c3efc4794bf451d771aafbdfbda2a297f7d341210cd4cf35a8c3c9ea910e74f719cca4f27b8912119938c0cdea8db5f5cba67a35a11805482672b8ec23d8be50fb22aa17e0647faf313263902e5f879309026f3aeb2bb17828485ede1d194d9aef6a559bf116124292e93c00b3a547a29ae06bca4e4e318a27c4e6b1d96993e328d657c1f11336d32b710f35a9bab494a0f06ffaf12fbbf37306aeeebe65e7f745f419d3c1bd620a5fb09b1ebf14a462851332e63d46fbd35d1615d04faae236b03e397824ba383006847f7018f34c4efee368e0ba0e6df6e7f051a4b1c3bd26406a4a8409edfc90194cf6e0c9eafd45b7e6705fd513b5797b2784ddf9dd59fb1c408902e369dddefa4ea66e81ef46c9783591476f580f1bd6e6b3d982f5ade8cb8eab606ef7bf322efad54152e723a6aa66fd5418dff6bc5e81ada935ed0884be98c128b78698b3a1be7934bbcffcccf570bc27b1bb99bd31e1dee1cb755e541c480fa616bcf48c5b635a16ba7cfefe7be023b4a8ce857020afa76ff65d15610e7dc138deac4b48e0310eb5f6d2d412b60073618769f3556e7bd10cf01c97d1b3fdc2250e9c7f6570ea7e13dc2decb22eac491a8c124ef6dee70c2e9ca9a8bfea59a08aaf9613c0b1bdb45e4f489b11d692eb3a21b4b08cb1f0ef5507e86548354e04f980e8610ec54d2411e07e755ff653b983d37d8bc53e8ad0354388556d8525523c5d391bc22a962484d533d823672eaf731b165e716af885db35f0bb23993892b86f77ce0a7a7de666a92c7a381eb07a268d74b54ca7d7ccd5ad9b7fa6bd35e1a14350f383c4221f0efe6606906510706666a7c6e58ad5df9c5f0ad6a154b5675091c3a548f05e7ccdd4a85e515df6a73f1f6928dbb84bf48aee8effd1a10465566a66938ba2bb600cd6cd0ef47275e969e87c9708997b485e92dbc4ebb8e90743ced4fb44427fbdd71f7eeac39b36e1052e278e3efc4ca1a73f2db7767b1ee25ba5d098aaca229d416e1281ef7f7fb37fd4742b580d0ffc38fa574cb5eb1dc404defab12c66ee28d8a644db9db1b2734c972d1c8b7a2bea6e85321b3f7f24c7ebb7f7a2d06f7f89d1d2ef55aa96898af0688900e236efb763f18f106adf37edf818909a3f18b9e0a85fe5337f6f67d45d9bde8d5988968b8ffc0d2c3bf825f66661437f012a74d7cf16078321d034f05a2cda876ea23dc0cad892ed8e4918d8b801fec29e93a59f477432bcf53fbb1c53855d210c8a9277f03c5862094af3a34c54a43175819b63db2f96cc8480839a2fc048b14a0bf244469b680de850a93e5ca0bb04bb874313ffad205356ef9dcfb75e0168c22adcd82de9e9caae8e11c64016f5f6b790778cc28e327185807fc22a1a758e0dd67fe79894383219334607edc80f8c47644b87dbf91626083d58e9e036ec15bf91850de7c39568608ff0e7194601dacdaae688967bdf1593d5b046b0b16c6eb26856a9627801e4586cbf75b516db861f9b034de240abf4a3edbf55b0c71f67c3632ed9ba21208974b985f8b8410af6cc8108bc8b6e21ba7970464e809bcd50b7f66c84e6c27e63cda2215e71a144cd9af4a63b939a9f0728c70537d00c9d61f298180dc05a973e8562f14d1ecb0bc6407abeb6a9f77de378b16e524027c8d5786b32325180b627c561af1e1e3219dd78d30d7d86714504e5576812c0c33ebe7c7ee5ae762aecfa5c18d6c97e3139f4151edd61df58e783bae5653e404b48f5db95855850a6f36a43a28f8380d99c711608411d7e9fe310c0250c6ad09aa343906cefdcf9111980799192ca1725aa9a4eb09c3e3b8dd9c5fea3063a508d3f460b6242d4dac432d7b1bffa72dee6dde0c1c761c137d9c122ed6229cff041343bfcc7a738734548237e6583b886a8a6f265a666e29e2171dd0bdd0104e0202bfc9314d024983e69c52bf478ec7c9fc3d8bfc0476db8be44c46bf8ef8ab07b4f7327b581eaf338f5cba0edf93d9a68067549c1c6071aa5b9835b8489b980a

~$ curl -X POST http://127.0.0.1:28081/sendrawtransaction -d '{"do_not_relay": false, "tx_as_hex":"020001020005f9fb16bd06109503a60b334796e4c5cdcee80129056d2761a09282c0133c40d156dbc8fd18ef39ed39f102000209bbbc3bb0a02efc2a80387d0958eff044498751d88759967ec012a341b677990002c831025bc303f8c168d4e28e9db6c1ea96fc600bb5b162b58f2ebbab5412ecc621018a7d5c720c9eb07fbf6af552ff115f315f791d624a9149b4c26ae4ccdcb9d28d0380b5a7ce0ed63f5036a8c7fdb147d08417960f50569d86ddd08f36529a4f0521cc0b38440a29287970ac7fe91ccf49b01dd06c31c3479bfa55ef9dc75b4e677129e4d5cd019576a472d30ecc77934b1c20c957de143023e6ea815bb430073aadd41b0bd6064075c6a646962532f4cd59131f7a4d9b6195dd12dd3df9460786ef154e736f0dc0d8e8e86051308d880acba05e2025f3e1c4577ee057920dfe23f8e0584978a3af3063fefee0f16645b9219041d72f5cd5f7a6a91181230d4e47d2cbfd33b998dae0d4798afda673d6898bbbb6b0f208bc4730e435eccb3304f4083fa40b2a49dc0dbe7eda7981642a92beebb063d946bd70f487c97700103fd18a210689c4e5e49db58d54ea2c91dc6aebdade23b61c436cb962c6cda1e16a643736ec5c5762981d3d2a628bfdce6159754378631e046d3699d392b2dc2daf94b93e157bd036e07e56b613babeeb3d4d5d09a788224e4bee8be0f416ff0b6a3fb17b1b998803f583fde86e587dd2867bd4cf68795e2012c35105f6cdbd6b2fbec4e3f0067d0d06ebf567e3f6da01b25d35989406f204a2319858d6c78d3bb7eed5d8ba830aec6d2f0337932dab4b71f1d38a14207159716b1a95eeb05213e3ed774427ff7c3c895f208c4800e11a3783c9f02d7d405c3efc4794bf451d771aafbdfbda2a297f7d341210cd4cf35a8c3c9ea910e74f719cca4f27b8912119938c0cdea8db5f5cba67a35a11805482672b8ec23d8be50fb22aa17e0647faf313263902e5f879309026f3aeb2bb17828485ede1d194d9aef6a559bf116124292e93c00b3a547a29ae06bca4e4e318a27c4e6b1d96993e328d657c1f11336d32b710f35a9bab494a0f06ffaf12fbbf37306aeeebe65e7f745f419d3c1bd620a5fb09b1ebf14a462851332e63d46fbd35d1615d04faae236b03e397824ba383006847f7018f34c4efee368e0ba0e6df6e7f051a4b1c3bd26406a4a8409edfc90194cf6e0c9eafd45b7e6705fd513b5797b2784ddf9dd59fb1c408902e369dddefa4ea66e81ef46c9783591476f580f1bd6e6b3d982f5ade8cb8eab606ef7bf322efad54152e723a6aa66fd5418dff6bc5e81ada935ed0884be98c128b78698b3a1be7934bbcffcccf570bc27b1bb99bd31e1dee1cb755e541c480fa616bcf48c5b635a16ba7cfefe7be023b4a8ce857020afa76ff65d15610e7dc138deac4b48e0310eb5f6d2d412b60073618769f3556e7bd10cf01c97d1b3fdc2250e9c7f6570ea7e13dc2decb22eac491a8c124ef6dee70c2e9ca9a8bfea59a08aaf9613c0b1bdb45e4f489b11d692eb3a21b4b08cb1f0ef5507e86548354e04f980e8610ec54d2411e07e755ff653b983d37d8bc53e8ad0354388556d8525523c5d391bc22a962484d533d823672eaf731b165e716af885db35f0bb23993892b86f77ce0a7a7de666a92c7a381eb07a268d74b54ca7d7ccd5ad9b7fa6bd35e1a14350f383c4221f0efe6606906510706666a7c6e58ad5df9c5f0ad6a154b5675091c3a548f05e7ccdd4a85e515df6a73f1f6928dbb84bf48aee8effd1a10465566a66938ba2bb600cd6cd0ef47275e969e87c9708997b485e92dbc4ebb8e90743ced4fb44427fbdd71f7eeac39b36e1052e278e3efc4ca1a73f2db7767b1ee25ba5d098aaca229d416e1281ef7f7fb37fd4742b580d0ffc38fa574cb5eb1dc404defab12c66ee28d8a644db9db1b2734c972d1c8b7a2bea6e85321b3f7f24c7ebb7f7a2d06f7f89d1d2ef55aa96898af0688900e236efb763f18f106adf37edf818909a3f18b9e0a85fe5337f6f67d45d9bde8d5988968b8ffc0d2c3bf825f66661437f012a74d7cf16078321d034f05a2cda876ea23dc0cad892ed8e4918d8b801fec29e93a59f477432bcf53fbb1c53855d210c8a9277f03c5862094af3a34c54a43175819b63db2f96cc8480839a2fc048b14a0bf244469b680de850a93e5ca0bb04bb874313ffad205356ef9dcfb75e0168c22adcd82de9e9caae8e11c64016f5f6b790778cc28e327185807fc22a1a758e0dd67fe79894383219334607edc80f8c47644b87dbf91626083d58e9e036ec15bf91850de7c39568608ff0e7194601dacdaae688967bdf1593d5b046b0b16c6eb26856a9627801e4586cbf75b516db861f9b034de240abf4a3edbf55b0c71f67c3632ed9ba21208974b985f8b8410af6cc8108bc8b6e21ba7970464e809bcd50b7f66c84e6c27e63cda2215e71a144cd9af4a63b939a9f0728c70537d00c9d61f298180dc05a973e8562f14d1ecb0bc6407abeb6a9f77de378b16e524027c8d5786b32325180b627c561af1e1e3219dd78d30d7d86714504e5576812c0c33ebe7c7ee5ae762aecfa5c18d6c97e3139f4151edd61df58e783bae5653e404b48f5db95855850a6f36a43a28f8380d99c711608411d7e9fe310c0250c6ad09aa343906cefdcf9111980799192ca1725aa9a4eb09c3e3b8dd9c5fea3063a508d3f460b6242d4dac432d7b1bffa72dee6dde0c1c761c137d9c122ed6229cff041343bfcc7a738734548237e6583b886a8a6f265a666e29e2171dd0bdd0104e0202bfc9314d024983e69c52bf478ec7c9fc3d8bfc0476db8be44c46bf8ef8ab07b4f7327b581eaf338f5cba0edf93d9a68067549c1c6071aa5b9835b8489b980a"}' -H 'Content-Type: application/json'
{
  "double_spend": false,
  "fee_too_low": false,
  "invalid_input": false,
  "invalid_output": false,
  "low_mixin": false,
  "not_rct": false,
  "not_relayed": false,
  "overspend": false,
  "reason": "",
  "status": "OK",
  "too_big": false
}

Note that you need to set do_not_relay to false in order to make the daemon relay the transaction.


Q:

How do I add a graph to my app like the one in the Android weather genie widget?

The Android weather genie widget has an awesome graph. I want to add it to my app.
But I can't figure out how they did it! (they aren't releasing the source code).
Can someone please tell me where to find a nice polished graph like that I can drop into my app?
Tanks
Brad

A:

This site has some good stuff
http://www.achartengine.org/content/demo.html
This question has some good stuff too
https://stackoverflow.com/questions/424752/any-good-graphing-packages-for-android


Q:

rMBP kernel_task spikes when connecting more than one external monitor

When connecting a second external monitor kernel_task spikes to 600%+. This makes the computer unusable.
Before Yosemite, this worked fine with 3 monitors.
Here are the specifics:

When I connect one monitor to either DP or HDMI things work fine.
When I connect a second monitor with either DP or HDMI kernel_task spikes.
When I disconnect either the DP or HDMI sometimes the kernel_task rapidly returns to normal levels.
When I disconnect all monitors the kernel_task rapid returns to normal levels. (In Activity Monitor goto View > Update Frequency > Very Often and as soon as you disconnect the monitors, you will get lots of rapid updates to the UI).
Occasionally when plugging in two monitors it works (DP or HDMI) but the 3rd causes an immediate spike. After this happens, all monitors must be removed for it to return to normal. Sometimes removing all but one will fix it.
Sometimes when I plug all 3 in it takes 3 mins+ for it to occur.

What I have tried:

Resetting NVRAM.
Resetting SMC.
Attempting the above scenario with power adapter plugged in and running on battery.
Disabling "Automatic Graphics Switching" in Energy Saver.
Using integrated graphics by using sudo pmset -c gpuswitch 0

NOTE: When trying some of these things sometimes it takes 1min to happen.
System config:
I am running a MacBook Pro Retina 2.7Ghz i7 (Macbook10,1 / Mid 2012) running Yosemite 10.10.1.
I have 3 external monitors (Dell 2415H) with 2 connected by Display Port and 1 with the HDMI.

I think the issue has to do with power management. Whenever my CPU hits 58 degrees it seems to occur. I just left my 3 monitors plugged in for 5+ mins and it didn't happen. But when I started searching using Chrome it immediately happened.
Looks like a good fix here: http://www.rdoxenham.com/?p=259

A:

According to Rhys Oxenhams:

the kernel will keep looping some very simple tasks, e.g. getting the date,
  therefore ‘consuming’ (with the highest priority) the majority of the CPU in a
  bid to cool the system down.

The solution he mentions on his blog should work for earlier Macs. For Ivy-Bridge Macs and a little earlier Richard Schwarting has found the appropriate file to disable. Instructions are included below for convenience. I have tried many things, but this works.

Disable kext by renaming it
cd /System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/Plugins
sudo mv X86PlatformShim.kext X86PlatformShim.kext.disabled

Clear kext cache (not sure if this is needed)
sudo touch /System/Library/Extensions/

Restart
sudo reboot

After installing OSX updates you may need to repeat the above procedure if the updates have re-created the kext.

Update for (High) Sierra:
TL:TR
Rename IOPlatformPluginFamily.kext/ACPI_SMC_PlatformPlugin.kext/[MacModelIdentifier].plist
Step by step:

Start intro Recovery Mode (press CMD + R while startup)
Utility > Terminal csrutil disable (Disable system file protection)
Restart and rename /System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/ACPI_SMC_PlatformPlugin.kext/Contents/Resources/[MacModelIdentifier].plist (Mac > About > System Report > Model Identifier) to bugfix.plist (or something else)
Restart and check if kernal_task process is down below 10%
If successful restart again in Recovery Mode and enable system protaction again with csrutil enable

Tested and worked for me at 10.13.2 on Early 2011 MacbookPro.
Source with pictures (german)
http://www.couchpiratin.de/mac-zu-langsam-kernel_task-cpu-fehler-beseitigen/