Thursday, October 3, 2013

include google analytics in my js file

include google analytics in my js file

Would there be any drawbacks including the google analytics script in my
javascript file? Any suggestions?
HTML file:
<!DOCTYPE html>
<title>Include Analytics</title>
<script src=/js/myjsfile.js></script>
<p>No other Javascript in this document.
myjsfile.js:
window.onload = function(){
// my other functions
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx-x', 'domain.se');
ga('send', 'pageview');
}

Wednesday, October 2, 2013

how to upload multiple files in one

how to upload multiple files in one

I have made a code that let me upload multiple files but in separate
I was trying to upload a multiple files in one input where i set my input
tag into
<input type="file" multiple="" name="file1">
I selected 3 images but only 1 image was uploaded..
here is my VIEW before changing my input:
<?php echo form_open_multipart('test'); ?>
<p>
<?php echo form_label('File 1: ', 'file1') ?>
<input type='file' name='file1' id='file1'>
</p>
<p>
<?php //echo form_label('File 2: ', 'file2') ?>
<input type='file' name='file2' id='file2'>
</p>
<p><?php echo form_submit('submit', 'Upload them files!') ?></p>
and here is my CONTROLLER
function index()
{
if (isset($_POST['submit']))
{
$this->load->library('upload');
$config['upload_path'] = './upload_documents/';
$config['allowed_types'] = 'jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG';
$config['max_size'] = '0'; // 0 = no file size limit
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['overwrite'] = TRUE;
$this->upload->initialize($config);
foreach($_FILES as $field => $file)
{
// No problems with the file
if($file['error'] == 0)
{
// So lets upload
if ($this->upload->do_upload($field))
{
$data = $this->upload->data();
//alert("nice");
}
else
{
$errors = $this->upload->display_errors();
die();
}
}
else{
echo "alksjdfl";
die();
}
}
}
$this->load->view("test");
}
}

Probability - exactly one of A and B occurs

Probability - exactly one of A and B occurs

A and B are events that are subsets of the sample space. C is the event
that exactly one of A and B occurs.
1) Write an expression for C in terms of unions, intersections and
complements involving the events A and B
2) Let P be a probability defined on the events of the sample space. Write
an expression for P(C) in terms of P(A), P(B) and P(A¿B). Give proof of
your result.
Would I be right in saying that 1) is just
C=(AUB)-(A¿B)
Or would it be? (A¿B^c)U(A^c ¿B)

Java Swing repack components

Java Swing repack components

I have problem with pack function, when using Card Layout. I created 1
JFrame which include JPanel(in cardlayout) and this JPanel contains two
JPanels. ... so when I run my program the windows is resized to biggest
JPanel in program and i cant dynamicly resize it.
now screens: my background1(smaller background) class when i run program
only with this panel has width like 200 http://i41.tinypic.com/scfi88.jpg
when i run my program with added background2 the background gets width of
it so it looks for like 400 http://i41.tinypic.com/2lu742x.jpg so it gets
width of my background2 panel
code: main class:
public class main extends javax.swing.JFrame {
private JPanel mainPanel;
public main() {
mainPanel = new JPanel(new CardLayout());
add(mainPanel);
Background2 card1 = new Background2(mainPanel);
Background1 card2 = new Background1(mainPanel);
mainPanel.add(card1,"card1");
mainPanel.add(card2,"card2");
CardLayout cl = (CardLayout) (mainPanel.getLayout());
cl.show(mainPanel, "card1");
mainPanel.revalidate();
mainPanel.repaint();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new main().setVisible(true);
}
});
}
}
background1(it is big because it is few comonents generated in netbeans
design mode):
public class Background1 extends javax.swing.JPanel {
private JPanel mainPanel;
/**
* Creates new form HomePanel
*/
public Background1(JPanel panel) {
mainPanel=panel;
initComponents();
}
public JPanel getMainPanel() {
return mainPanel;
}
public void setMainPanel(JPanel mainPanel) {
this.mainPanel = mainPanel;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
left_Panel = new javax.swing.JPanel();
zakladka1_Button = new javax.swing.JButton();
background_Panel = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
powrot_Button = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
jTable3 = new javax.swing.JTable();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
zakladka1_Button.setText("button");
zakladka1_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zakladka1_ButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout left_PanelLayout = new
javax.swing.GroupLayout(left_Panel);
left_Panel.setLayout(left_PanelLayout);
left_PanelLayout.setHorizontalGroup(
left_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(left_PanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(zakladka1_Button)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
left_PanelLayout.setVerticalGroup(
left_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(left_PanelLayout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(zakladka1_Button)
.addGap(433, 433, 433))
);
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable2);
javax.swing.GroupLayout background_PanelLayout = new
javax.swing.GroupLayout(background_Panel);
background_Panel.setLayout(background_PanelLayout);
background_PanelLayout.setHorizontalGroup(
background_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(background_PanelLayout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE, 452,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(83, Short.MAX_VALUE))
);
background_PanelLayout.setVerticalGroup(
background_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
background_PanelLayout.createSequentialGroup()
.addContainerGap(14, Short.MAX_VALUE)
.addComponent(jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE, 319,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
powrot_Button.setText("<--");
powrot_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
powrot_ButtonActionPerformed(evt);
}
});
jLabel1.setText("jLabel1");
jTable3.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane3.setViewportView(jTable3);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(left_Panel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(powrot_Button)))
.addGap(18, 18, 18)
.addComponent(background_Panel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(powrot_Button,
javax.swing.GroupLayout.PREFERRED_SIZE, 43,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(left_Panel,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(background_Panel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(115, 115, 115))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jScrollPane3,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(42, 42, 42))))
);
}// </editor-fold>
private void powrot_ButtonActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout cl = (CardLayout) (mainPanel.getLayout());
cl.show(mainPanel, "card1");
mainPanel.revalidate();
mainPanel.repaint();
}
private void zakladka1_ButtonActionPerformed(java.awt.event.ActionEvent
evt) {
}
// Variables declaration - do not modify
private javax.swing.JPanel background_Panel;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTable jTable1;
private javax.swing.JTable jTable2;
private javax.swing.JTable jTable3;
private javax.swing.JPanel left_Panel;
private javax.swing.JButton powrot_Button;
private javax.swing.JButton zakladka1_Button;
// End of variables declaration
}
background2(it is big because it is few comonents generated in netbeans
design mode)::
public class Background2 extends javax.swing.JPanel {
private JPanel mainPanel;
public Background2(JPanel panel) {
mainPanel=panel;
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
loginFieldLabel = new javax.swing.JLabel();
zalogujButton = new javax.swing.JButton();
loginField = new javax.swing.JTextField();
passwordField = new javax.swing.JPasswordField();
logowanieLabel = new javax.swing.JLabel();
passwordFieldLabel = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
loginFieldLabel.setText("Login");
zalogujButton.setText("Zaloguj");
zalogujButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zalogujButtonActionPerformed(evt);
}
});
loginField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginFieldActionPerformed(evt);
}
});
passwordField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
passwordFieldActionPerformed(evt);
}
});
logowanieLabel.setText("Logowanie");
passwordFieldLabel.setText("Has³o");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.add(zalogujButton)
.add(149, 149, 149))
.add(org.jdesktop.layout.GroupLayout.LEADING,
layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING,
layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(logowanieLabel)
.add(layout.createSequentialGroup()
.add(56, 56, 56)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(passwordFieldLabel)
.add(loginFieldLabel))
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,
false)
.add(loginField)
.add(passwordField,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
193,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
.add(org.jdesktop.layout.GroupLayout.LEADING,
layout.createSequentialGroup()
.add(105, 105, 105)
.add(jButton1)))
.addContainerGap(190, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(logowanieLabel)
.add(29, 29, 29)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(loginField,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(loginFieldLabel))
.add(28, 28, 28)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(passwordFieldLabel)
.add(passwordField,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(33, 33, 33)
.add(zalogujButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(jButton1)
.addContainerGap(101, Short.MAX_VALUE))
);
}// </editor-fold>
private void zalogujButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
private void loginFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void passwordFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout cl = (CardLayout) (mainPanel.getLayout());
cl.show(mainPanel, "card2");
mainPanel.revalidate();
mainPanel.repaint();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JTextField loginField;
private javax.swing.JLabel loginFieldLabel;
private javax.swing.JLabel logowanieLabel;
private javax.swing.JPasswordField passwordField;
private javax.swing.JLabel passwordFieldLabel;
private javax.swing.JButton zalogujButton;
// End of variables declaration
}

TypeError: '_csv.reader' object has no attribute '__getitem__' // getting columns?

TypeError: '_csv.reader' object has no attribute '__getitem__' // getting
columns?

I'm trying to open a .csv file and put each column in different list:
import csv
CSV = csv.reader(open("AAPL.csv","rb"))
column1 = CSV[0]
column2 = CSV[1]
column3 = CSV[2]
column4 = CSV[2]
column5 = CSV[4]
column6 = CSV[5]
Here is my AAPL.csv:
Date Open High Low Close Volume Adj Close
2013-09-27 874.82 877.52 871.31 876.39 1258800 876.39
2013-09-26 878.3 882.75 875 878.17 1259900 878.17
2013-09-25 886.55 886.55 875.6 877.23 1649000 877.23
2013-09-24 886.5 890.1 881.4 886.84 1467000 886.84
2013-09-23 896.15 901.59 885.2 886.5 1777400 886.5
2013-09-20 898.39 904.13 895.62 903.11 4345300 903.11
2013-09-19 905.99 905.99 895.4 898.39 1597900 898.39
2013-09-18 886.35 903.97 883.07 903.32 1934700 903.32
2013-09-17 887.41 888.39 881 886.11 1259400 886.11
2013-09-16 896.2 897 884.87 887.76 1336500 887.76
.............................................................
end of file:
.............................................................
2012-06-29 574.96 58013 572.20 580.07 2519500 580.07
2012-06-28 565.90 566.23 557.21 564.31 1920900 564.31
2012-06-27 567.70 573.99 566.02 569.30 1692300 569.30
2012-06-26 562.76 566.60 559.48 564.68 1350200 564.68
2012-06-25 567.33 568.09 557.35 560.70 1581600 560.70
When I run my code, it returns me the following error:
Traceback (most recent call last):
File "/home/misha/Documents/finance/prices/some_csv.py", line 3, in
<module>
column1 = CSV[0]
TypeError: '_csv.reader' object has no attribute '__getitem__'
Is there any pythonic way to open a .csv file and put each column in
different list not using attribute getitem?
Thanks.
NOTE: and also i need to skip first row.

Tuesday, October 1, 2013

How can I implement tf history command in C#?

How can I implement tf history command in C#?

I would like to implement the following command using TFS programming API:
tf history /stopafter:1 /version:W /recursive /format:detailed /noprompt .
I have some code, but it tries to inspect local workspace info and there
is none. So, I am back to nothing.
How is it done?

Error with copy constructor

Error with copy constructor

My program keeps dyeing when trying to allocate new memory for my array.
By calling the add word function. Any help would be great!
Full code download @ http://www.johnsoncomputertechnologies.org/pgm2demo.zip
#include <iomanip> //Standard IO Manipulators Library
#include <algorithm>
#include <iostream> //Standard input/output library
#include <string> //Standard string Library
#include <cassert> //Error handeling Library
#include "pgm2.h"
using namespace std;
dictionary::dictionary()
{
wordptr = new value_type[DICTONARY_CAPACITY];
deffptr = new value_type[DICTONARY_CAPACITY];
used = 0;
}
dictionary::dictionary(dictionary& other)
{
value_type *wordptrs;
value_type *deffptrs;
wordptrs = new value_type[other.capacity];
deffptrs = new value_type[other.capacity];
used = other.used;
copy(other.wordptr, other.wordptr + used, wordptrs);
copy(other.deffptr, other.deffptr + used, deffptrs);
}
dictionary::~dictionary()
{
delete [] wordptr;
delete [] deffptr;
}
//Functions
void dictionary::reserve(size_type new_capacity)
{
value_type *larger_word;
value_type *larger_deff;
if(new_capacity == capacity)
return; //There allocated memory is already the correct size
if(new_capacity < used)
new_capacity = used;
larger_word = new value_type[new_capacity];
larger_deff = new value_type[new_capacity];
copy(wordptr, wordptr + used, larger_word);
copy(deffptr, deffptr + used, larger_deff);
delete [] wordptr;
delete [] deffptr;
wordptr = larger_word;
deffptr = larger_deff;
capacity = new_capacity;
}
void dictionary::addword(const value_type& word, const value_type& deff)
{
if(used == capacity)
reserve(used+1);
wordptr[used] = word;
deffptr[used] = deff;
++used;
}
pgm2.h
#include <iomanip> //Standard IO Manipulators Library
#include <algorithm>
#include <iostream> //Standard input/output library
#include <string> //Standard string Library
#include <cassert> //Error handeling Library
using namespace std;
class dictionary
{
public:
typedef string value_type;
typedef std::size_t size_type;
static const size_type DICTONARY_CAPACITY = 25;
//Default Constructor
dictionary();
dictionary(dictionary& other);
//Destructor
~dictionary();
//Functions
void reserve(size_type new_capacity);
void addword(const value_type& word, const value_type& deff);
void startPat (value_type patt);
void endPat(value_type patt);
void containsPat(value_type patt);
void print();
private:
value_type *wordptr;
value_type *deffptr;
size_type used;
size_type capacity;
};

How do I calculate roll, pitch, yaw from a unit vector?

How do I calculate roll, pitch, yaw from a unit vector?

I am provided a unit vector giving a direction in x, y, z coordinates, and
that the roll is defined as about the x axis, pitch around y, yaw around
z. I'm trying to determine how to calculate roll, pitch, and yaw given the
unit vector. I can see that the information should be there, but after
looking in to it for a bit, I've been unable to find the correct method of
doing this. How do I go about doing this?

Looking for a SF story regarding women growing things in their wombs – scifi.stackexchange.com

Looking for a SF story regarding women growing things in their wombs –
scifi.stackexchange.com

I'm looking for the title and author of a short story or novelette that I
read quite some time ago. The main characters are two young women. One is
taking correspondence courses, and is constantly …