29.7.13

Also a Java utility library that includes a more RSI-friendly print option

 // utility functions  
 public class S {  
      private static boolean DEBUGMODE = true;  
      private S(){}  
      public static void p(Object s)  
      {  
           if (DEBUGMODE)  
           {  
                StackTraceElement[] ste = Thread.currentThread().getStackTrace();  
                String n = ste[2].getClassName();  
                System.out.println(n +": "+ s.toString());  
           }  
      }  
      public static Position int2Position(int i)  
      {  
           switch (i)  
           {  
           case 5: return Position.SCANNER;  
           case 0: return Position.ONE;  
           case 1: return Position.TWO;  
           case 2: return Position.THREE;  
           case 3: return Position.FOUR;  
           case 4: return Position.FIVE;  
           default: return null;  
           }  
      }  
      public static int Position2int(Position p)  
      {  
           if (p==Position.SCANNER)  return 5;  
           else if (p==Position.ONE)  return 0;  
           else if (p==Position.TWO)  return 1;  
           else if (p==Position.THREE) return 2;  
           else if (p==Position.FOUR) return 3;  
           else if (p==Position.FIVE) return 4;  
           return -1; // this should never happen; if it does, hopefully this causes some kind of silly error  
      }  
 }  

Labels:

Java apoptosis object; cascading abortion

Instantiating this object will cause cascading interrupts for all threads (including gui threads etc). It is useful for aborting a multi-threaded simulation from within a catch or something. Be aware, calling new Apoptosis() will end the current thread too, so you can never do anything with the object.
 // finds all the threads and kills them  
 public class Apoptosis   
 {  
      // finds all the threads and kills them  
      public Apoptosis()  
      {  
           ThreadGroup allThreads = Thread.currentThread().getThreadGroup();  
           ThreadGroup parentGroup;  
           while ( ( parentGroup = allThreads.getParent() ) != null )   
           {  
                allThreads = parentGroup;  
           }  
           allThreads.interrupt();  
      }  
 }  

Labels: ,

18.7.13

So lazy

sean@potatocake:~$ps -e | grep deluge
sean@potatocake:~$deluged
sean@potatocake:~$man deluge-web
sean@potatocake:~$deluge-web -f -p 8999
So lazy. That computer was like... 3 meters away from me at the time.

Labels: ,