vendredi 11 septembre 2015

How do I configure django-money to output GBP in British format?

I'm using django-money to handle money amounts in GBP (Pounds Sterling), but they are being output as GB£20.00, rather than £20.00. This is despite settings.LANGUAGE_CODE being "en-GB" and settings.USE_L10N being True.

What am I doing wrong?



via Chebli Mohamed

Using Linked List into OSP 2 TaskCB

I am learning OSP 2 and how to use to implement method in the TaskCB, as well as an implementation of a Linked List. So I got my TaskCB class work fine, but when I create a Linked List it gives me errors such as

Possible cause: Failed to add/remove a thread to/from task

Image of output

Anybody can help me to point out what I am missing or any suggest would be great! Thank you!

Here is my TaskCB and Linked Like code so far.

import osp.FileSys.*;
import osp.Hardware.*;
import osp.IFLModules.*;
import osp.Memory.*;
import osp.Ports.*;
import osp.Threads.*;

/**
 * The student module dealing with the creation and killing of tasks. A task
 * acts primarily as a container for threads and as a holder of resources.
 * Execution is associated entirely with threads. The primary methods that the
 * student will implement are do_create(TaskCB) and do_kill(TaskCB). The student
 * can choose how to keep track of which threads are part of a task. In this
 * implementation, an array is used.
 * 
 * @OSPProject Tasks
 */
public class TaskCB extends IflTaskCB {
    /**
     * The task constructor. Must have
     * 
     * super();
     * 
     * as its first statement.
     * 
     * @OSPProject Tasks
     */

    private LinkedList<ThreadCB> threadList;
    private LinkedList<PortCB> portList;
    private LinkedList<OpenFile> openFilesTable;

    private static int virtureMemorySize = (int) Math.pow(2,
        MMU.getVirtualAddressBits());

    public TaskCB() {

        super();
    }

    /**
     * This method is called once at the beginning of the simulation. Can be
     * used to initialize static variables.
     * 
     * @OSPProject Tasks
     */
    public static void init() {
        // your code goes here

    }

    /**
     * Sets the properties of a new task, passed as an argument.
     * 
     * Creates a new thread list, sets TaskLive status and creation time,
     * creates and opens the task's swap file of the size equal to the size (in
     * bytes) of the addressable virtual memory.
     * 
     * @return task or null
     * 
     * @OSPProject Tasks
     */
    static public TaskCB do_create() {

        TaskCB theTask = new TaskCB();
        PageTable pagTable = new PageTable(theTask);
        theTask.setPageTable(pagTable);

        theTask.threadList = new LinkedList<ThreadCB>();
        theTask.portList = new LinkedList<PortCB>();
        theTask.openFilesTable = new LinkedList<OpenFile>();

        theTask.setCreationTime(HClock.get());
        theTask.setStatus(TaskLive);
        theTask.setPriority(0);

        FileSys.create(SwapDeviceMountPoint + theTask.getID(),
            virtureMemorySize);
        OpenFile swapFile = OpenFile.open(SwapDeviceMountPoint + theTask.getID(),
            theTask);

        if ( swapFile == null ) {
            ThreadCB.dispatch();
//            theTask.do_kill();
            return null;
        }

        theTask.setSwapFile(swapFile);
        ThreadCB.create(theTask);

        return theTask;

    }

    /**
     * Kills the specified task and all of it threads.
     * 
     * Sets the status TaskTerm, frees all memory frames (reserved frames may
     * not be unreserved, but must be marked free), deletes the task's swap
     * file.
     * 
     * @OSPProject Tasks
     */
    public void do_kill() {

        for ( int i = threadList.size() - 1; i >= 0; i-- ) {
            ((ThreadCB) this.threadList.get(i)).kill();
        }

        for ( int i = this.portList.size() - 1; i >= 0; i-- ) {
            ((PortCB) this.portList.get(i)).destroy();
        }

        this.setStatus(TaskTerm);
        this.getPageTable().deallocateMemory();

        for ( int i = openFilesTable.size() - 1; i >= 0; i-- ) {
            OpenFile swapFile = (OpenFile) openFilesTable.get(i);
            if ( swapFile != this.getSwapFile() ) {
                swapFile.close();
            }
        }

        this.getSwapFile().close();
        FileSys.delete(SwapDeviceMountPoint + this.getID());

    }

    /**
     * Returns a count of the number of threads in this task.
     * 
     * @OSPProject Tasks
     */
    public int do_getThreadCount() {
        return threadList.size();
    }

    /**
     * Adds the specified thread to this task.
     * 
     * @return FAILURE, if the number of threads exceeds MaxThreadsPerTask;
     *         SUCCESS otherwise.
     * 
     * @OSPProject Tasks
     */
    public int do_addThread(ThreadCB thread) {
        if ( threadList.size() >= ThreadCB.MaxThreadsPerTask ) {
            return TaskCB.FAILURE;
        }
        threadList.addFirst(thread);
        return TaskCB.SUCCESS;
    }

    /**
     * Removes the specified thread from this task.
     * 
     * @OSPProject Tasks
     */
    public int do_removeThread(ThreadCB thread) {
        if ( this.threadList.contains(thread) ) {
            this.threadList.remove(thread);
            return TaskCB.SUCCESS;
        }
        else
            return TaskCB.FAILURE;
    }

    /**
     * Return number of ports currently owned by this task.
     * 
     * @OSPProject Tasks
     */
    public int do_getPortCount() {
        return portList.size();
    }

    /**
     * Add the port to the list of ports owned by this task.
     * 
     * @OSPProject Tasks
     */
    public int do_addPort(PortCB newPort) {
        if ( portList.size() >= PortCB.MaxPortsPerTask ) {
            return TaskCB.FAILURE;
        }
        portList.addFirst(newPort);
        return TaskCB.SUCCESS;
    }

    /**
     * Remove the port from the list of ports owned by this task.
     * 
     * @OSPProject Tasks
     */
    public int do_removePort(PortCB oldPort) {
        if ( this.portList.contains(oldPort) ) {
            portList.remove(oldPort);
            return TaskCB.SUCCESS;
        }

        return TaskCB.FAILURE;
    }

    /**
     * Insert file into the open files table of the task.
     * 
     * @OSPProject Tasks
     */
    public void do_addFile(OpenFile file) {
        this.openFilesTable.addLast(file);

    }

    /**
     * Remove file from the task's open files table.
     * 
     * @OSPProject Tasks
     */
    public int do_removeFile(OpenFile file) {
        if ( file.getTask() != this )
            return TaskCB.FAILURE;
        openFilesTable.remove(file);
        return TaskCB.SUCCESS;
    }




import java.util.*;

public class LinkedList<V> implements Iterable<V>
{
   private Node<V> head;
   private int count = 0;

 /**
   *  Constructs an empty list
   */
   public LinkedList()
   {
      head = null;
   }
 /**
   *  Returns true if the list is empty
   *
   */
   public boolean isEmpty()
   {
      return head == null;
   }

   public int size() {
       return count;
   }
 /**
   *  Inserts a new node at the beginning of this list.
   *
   */
   public void addFirst(V item)
   {
      head = new Node<V>(item, head);
   }
 /**
   *  Returns the first element in the list.
   *
   */
   public V getFirst()
   {
      if(head == null) throw new NoSuchElementException();

      return head.data;
   }
 /**
   *  Removes the first element in the list.
   *
   */
   public V removeFirst()
   {
      V tmp = getFirst();
      head = head.next;
      return tmp;
   }
 /**
   *  Inserts a new node to the end of this list.
   *
   */
   public void addLast(V item)
   {
      if( head == null)
         addFirst(item);
      else
      {
         Node<V> tmp = head;
         while(tmp.next != null) tmp = tmp.next;

         tmp.next = new Node<V>(item, null);
      }
   }
 /**
   *  Returns the last element in the list.
   *
   */
   public V getLast()
   {
      if(head == null) throw new NoSuchElementException();

      Node<V> tmp = head;
      while(tmp.next != null) tmp = tmp.next;

      return tmp.data;
   }
 /**
   *  Removes all nodes from the list.
   *
   */
   public void clear()
   {
      head = null;
   }
 /**
   *  Returns true if this list contains the specified element.
   *
   */
   public boolean contains(V x)
   {
      for(V tmp : this)
         if(tmp.equals(x)) return true;

      return false;
   }
 /**
   *  Returns the data at the specified position in the list.
   *
   */
   public V get(int pos)
   {
      if (head == null) throw new IndexOutOfBoundsException();

      Node<V> tmp = head;
      for (int k = 0; k < pos; k++) tmp = tmp.next;

      if( tmp == null) throw new IndexOutOfBoundsException();

      return tmp.data;
   }
 /**
   *  Returns a string representation
   *
   */
   public String toString()
   {
      StringBuffer result = new StringBuffer();
      for(Object x : this)
        result.append(x + " ");

      return result.toString();
   }
 /**
   *  Inserts a new node after a node containing the key.
   *
   */
   public void insertAfter(V key, V toInsert)
   {
      Node<V> tmp = head;

      while(tmp != null && !tmp.data.equals(key)) tmp = tmp.next;

      if(tmp != null)
         tmp.next = new Node<V>(toInsert, tmp.next);
   }
 /**
   *  Inserts a new node before a node containing the key.
   *
   */
   public void insertBefore(V key, V toInsert)
   {
      if(head == null) return;

      if(head.data.equals(key))
      {
         addFirst(toInsert);
         return;
      }

      Node<V> prev = null;
      Node<V> cur = head;

      while(cur != null && !cur.data.equals(key))
      {
         prev = cur;
         cur = cur.next;
      }
      //insert between cur and prev
      if(cur != null)
         prev.next = new Node<V>(toInsert, cur);
   }
 /**
   *  Removes the first occurrence of the specified element in this list.
   *
   */
   public void remove(V key)
   {
      if(head == null)
         throw new RuntimeException("cannot delete");

      if( head.data.equals(key) )
      {
         head = head.next;
         return;
      }

      Node<V> cur  = head;
      Node<V> prev = null;

      while(cur != null && !cur.data.equals(key) )
      {
         prev = cur;
         cur = cur.next;
      }

      if(cur == null)
         throw new RuntimeException("cannot delete");

      //delete cur node
      prev.next = cur.next;
   }

 /*******************************************************
 *
 *  The Node class
 *
 ********************************************************/
   private static class Node<AnyType>
   {
      private AnyType data;
      private Node<AnyType> next;

      public Node(AnyType data, Node<AnyType> next)
      {
         this.data = data;
         this.next = next;
      }
   }

 /*******************************************************
 *
 *  The Iterator class
 *
 ********************************************************/

   public Iterator<V> iterator()
   {
      return new LinkedListIterator();
   }

   private class LinkedListIterator  implements Iterator<V>
   {
      private Node<V> nextNode;

      public LinkedListIterator()
      {
         nextNode = head;
      }

      public boolean hasNext()
      {
         return nextNode != null;
      }

      public V next()
      {
         if (!hasNext()) throw new NoSuchElementException();
         V res = nextNode.data;
         nextNode = nextNode.next;
         return res;
      }

      public void remove() { throw new UnsupportedOperationException(); }
   }
}



via Chebli Mohamed

Visual studios c#, trying to add objects every click of a button

I'm trying to add a circle every click on button1. For some reason after adding the first circle, I can't add a second. Please help, it's for a school project... Here's the code: http://ift.tt/1FBNY2q



via Chebli Mohamed

Transfer artifact via SFTP using Maven

I'm attempting to add a build task into a Maven pom file so that I can transfer a jar file as well as some xml files to an SFTP server (it's a VM with Tomcat installed) but I have been unable to so far.

I've had a look at a few links, but they either don't quite match the requirements, have missing steps, or don't work. I'm basically a beginner with Maven so I'm not sure if I'm doing it correctly.

The requirement is that I want to invoke a Maven build, with command line arguments for the hostname, username, and password (which I have working) which then will upload a jar file and the xml files to a VM with Tomcat running in it via SFTP (FTP doesn't work, and I don't think SCP will work as I don't have a passfile). I also don't want to mess with the main Maven settings.xml file to add the connection details in, which some of the links I found seem to be reliant upon.

I have the following profile so far, using FTP, but it doesn't work due to not using SFTP.

<profiles>
    <profile>
        <!-- maven antrun:run -Pdeploy -->
        <id>deploy</id>
        <build>
            <plugins>
                <plugin>
                    <inherited>false</inherited>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.6</version>
                    <configuration>
                        <target>
                            <!-- <loadproperties srcFile="deploy.properties" /> -->

                            <ftp action="send" server="${server-url}"
                                remotedir="/usr/share/myappserver/webapps/myapp/WEB-INF/lib"
                                userid="${user-id}" password="${user-password}" depends="no"
                                verbose="yes" binary="yes">
                                <fileset dir="target">
                                    <include name="artifact.jar" />
                                </fileset>
                            </ftp>

                            <ftp action="send" server="${server-url}"
                                remotedir="/var/lib/myappserver/myapp/spring"
                                userid="${user-id}" password="${user-password}" depends="no"
                                verbose="yes" binary="yes">
                                <fileset dir="src/main/resource/spring">
                                    <include name="*.xml" />
                                </fileset>
                            </ftp>

                            <!-- calls deploy script -->
                            <!-- <sshexec host="host" trust="yes" username="usr" password="pw" 
                                command="sh /my/script.sh" /> -->

                            <!-- SSH -->
                            <taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" 
                                classpathref="maven.plugin.classpath" />
                            <taskdef name="ftp"
                                classname="org.apache.tools.ant.taskdefs.optional.net.FTP"
                                classpathref="maven.plugin.classpath" />
                        </target>

                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>commons-net</groupId>
                            <artifactId>commons-net</artifactId>
                            <version>1.4.1</version>
                        </dependency>
                        <dependency>
                            <groupId>ant</groupId>
                            <artifactId>ant-commons-net</artifactId>
                            <version>1.6.5</version>
                        </dependency>
                        <dependency>
                            <groupId>ant</groupId>
                            <artifactId>ant-jsch</artifactId>
                            <version>1.6.5</version>
                        </dependency>
                        <dependency>
                            <groupId>jsch</groupId>
                            <artifactId>jsch</artifactId>
                            <version>0.1.29</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

I tried swapping ftp for sftp, and using org.apache.tools.ant.taskdefs.optional.ssh.SFTP instead, but it didn't seem to work.

So to summarize, the SFTP config needs to be self contained within the pom file as much as possible, with stuff like the host url, username and password being passed in when invoked.



via Chebli Mohamed

Call function inside bxslider callback

I am trying to call a custom function inside a bxslider callback but the function doesn't get recorgnized (aka: Uncaught Reference Error: nextSlideCustom() is not a function)

my current code looks like

    var slider=$('#slider1').bxSlider({
         pager: 'true',
         onSlideNext: nextSlideHandle()
    });

and in a different js file I am defining this function:

function nextSlideHandle(){
    console.log("huhu");
}

so what's the problem with my code, or is it mory likely a wrong configuration of the slider or something?

thanks in advance!



via Chebli Mohamed

How to disable browser auto filling username and password

How to disable browser auto filling form username and password fields. I have already tried autocomplete="off". It's not working for me. Please find the form below. And help me to solve this.



via Chebli Mohamed

MySQL - Check if two values are equal or both NULL?

If I want to compare two values, I can write:

SELECT * FROM table1
JOIN table2 ON table1.col = table2.col;

I've noticed that this does not work if both table1.col and table2.col are NULL. So my corrected query looks like this:

SELECT * FROM table1
JOIN table2 ON 
  (table1.col = table2.col)
  OR
  (table1.col IS NULL AND table2.col IS NULL);

Is this the correct way to compare two values? Is there a way to say two values are equal if they are both NULL?



via Chebli Mohamed