×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Comments

top

Best Valentine's Day gift (as recipient):

jomama717 Best? No Clue (197 comments)

I can tell you from past experience however that pretty high on the worst list is "Hockey Tickets".

about 2 months ago
top

A Dedicated Shell For Git Commands

jomama717 Re:Shell? Give me a web based browser (96 comments)

Yeah, I really want to be able to do it right in the browser - I started wanting it the other day when I was sitting in the waiting room at my kid's ballet class and trying to debug an issue on my phone by looking at the code on github.com. It would have been 100 times easier if I'd been able to click on method names/classes and jump to the declarations, or even search for references right in the browser. Wondering if I can find where/how eclipse stores it's project indices and roll my own...

Thanks for the reply!

about 2 months ago
top

A Dedicated Shell For Git Commands

jomama717 Shell? Give me a web based browser (96 comments)

As others have commented I think this idea can be covered with some simple aliases in bash, seems a tad silly.

What I wish was available was a way to view the source of a git with one minor enhancement - the ability to browse with a click to the declaration/definition of functions/variables a la the IDE of your choice. Would be neat to be able to build an index using some tool, check it into the root of your repo, and then have the site use the index to mark up the source code with the appropriate links.

I've dug around for something that does this but haven't found anything suitable - anyone know of anything?

about 2 months ago
top

Silk Road's Ross Ulbricht's Next Court Date Set For November

jomama717 Explain why comments are broken (77 comments)

First off I appreciate your comments, wonderful to see a thoughtful and measured response to this whole thing for a change. I've been using the new site for the past few days - at first just trying to sift through the crap, and then getting fed up and downmodding and finally replying to it out of desperation, and through all of it I never witnessed how the commenting/modding system is any more broken that it has ever been. Missing features galore, yes, but fundamentally broken?

The *only* specific gripe I've seen was that if the thread gets too nested the comments are squeezed into an unreadably narrow box. (1) that's seems like a pretty easy fix, and (2) I can't recall the last time I've read through a good comment thread that was more than 4-5 levels deep. So with respect, what am I missing? What has been fundamentally broken in the comment system? Nobody seems to say, they just say it sucks, or is fundamentally broken, or as you say is an add-on, etc.

I've been an active reader/commenter/submitter for over a decade and none of this makes any sense to me. Worst case the site is done, due not to the redesign itself, but the completely unhinged overreaction to it (see: throwing out the baby with the bathwater.) Best case, 1-2 months from now the is cruising along fine minus a tiny group of users with a very skewed set of priorities.

about 2 months ago
top

Bitcoin Plunges after Mt. Gox Exchange halts trades

jomama717 Explain it to me (3 comments)

I *honestly* do not understand it. Explain it to me, and don't just tell me it sucks, I want to know the details of your personal torment at the hands of a website redesign. Do you feel slighted? Are you personally offended by the website's layout? On a scale of 1 to 10 how would you rank the pain and suffering? Try explaining it to me as you would explain it to a child, or a starving refugee.

It's buggy. There is shit missing. A lot of shit missing. Yet, I seem to be able to read all of these pointless comments, and reply to them without issue. I can mod them offtopic with no issues whatsoever. If it weren't for this totally inexplicable flood of self-righteous protest comments I think my life would cruise right along reading and enjoying normal slashdot comments in the new design. Or, maybe not. Maybe if I could see the site operating as it should be in the new format I would begin to feel your profound misery. Alas I'll never know.

I've resigned myself to the distinct possibility that the site is now forever ruined - by you and your ilk, not by the poor saps charged with the redesign. Of all of the goddamn things to be outraged about, I do not understand it.

about 2 months ago
top

Quarks Know Their Left From Their Right

jomama717 The Baby and the Bathwater (150 comments)

I can't think of a better idiom to describe what all of you assholes are doing with this Fuck Beta business. Even if you get what you want, something that has changed from "guaranteed access to 'classic'" (even though it's not *really* classic) to "oh yeah, and not just classic, classic with X, Y and Z!!" at this point the site will be ruined because you pimply little fucks have latched onto some kind of mob mentality and will not quit.

The new shit is buggy and is missing features, they've said they'll handle it, let them. Very depressing to see that the general sorry state of discourse in this country has spread now to this site. Fuck the unreasonable vocal minority. I miss the site, quit holding it hostage.

about 2 months ago
top

Ask Slashdot: What Do You Do If You're Given a Broken Project?

jomama717 Re:You were not hired to finish the project (308 comments)

A good contractor won't try to avoid reputation damage by skulking around and trying to figure out the seedy back story of the project they've been assigned to - in fact I can't think of a better way to damage your reputation!

A good contractor fixes the problem, or clearly documents why he or she cannot fix the problem and provides alternative recommendations, one of which might be hire a different contractor. It's called professionalism.

about 2 months ago
top

Ask Slashdot: What Do You Do If You're Given a Broken Project?

jomama717 Re:This is why poeple call their jobs "work" (308 comments)

This. The description of the task does not sound out of the ordinary to me, it sounds about like what I have been doing for the past 15 years.

...the code is not robust. You create a small new feature, and the app breaks down in unexpected ways. You fix a bug, and new bugs pop up all over the place.

You've just described every project I've ever been dropped into - welcome to the wonderful world of software development, where anything is possible - but NOTHING is easy.

about 2 months ago
top

Tesla's Having Issues Charging In the Cold

jomama717 Re:why is everyone always snide about Tesla? (476 comments)

Relevant quote from the movie Moneyball:

...I know you've taken it in the teeth out there, but the first guy through the wall. It always gets bloody, always. It's the threat of not just the way of doing business, but in their minds it's threatening the game. But really what it's threatening is their livelihoods, it's threatening their jobs, it's threatening the way that they do things. And every time that happens, whether it's the government or a way of doing business or whatever it is, the people are holding the reins, have their hands on the switch. They go bat shit crazy. I mean, anybody who's not building a team right and rebuilding it using your model, they're dinosaurs...

about 3 months ago
top

An OS You'll Love? AI Experts Weigh In On Her

jomama717 Re:a symptom of professional immaturity (175 comments)

Related quote:

I don't know how many of you have ever met Dijkstra, but you probably know that arrogance in computer science is measured in nano-Dijkstras. -- Alan Kay

about 3 months ago
top

Ask Slashdot: How To Reimagine a Library?

jomama717 Digital Book Scanning Operation (231 comments)

Get the kids involved in an ongoing operation whereby books are acquired, digitally scanned, and then re-donated to other schools/libraries/etc. Store the digital copies in some offsite database that can be shared amongst other schools/libraries/etc. Provide terminals where the students can peruse the scanned books and allow access to the digital library for students at home.

Can't think of a better way to keep a library as a place to learn new and relevant skills and be exposed to gobs of information and knowledge at the same time.

I'm sure this all falls apart when the copyright lawyers get involved, but I would love to see the publicity the publishers get when they sue a school library :)

about 3 months ago
top

Rosetta Probe Awakens, Prepares To Chase Comet

jomama717 Not to diminish... (72 comments)

...but IMHO the curiosity landing makes anything like this that I read about seem like a cake walk. Still in complete awe of the team(s) that pulled that off.

Excited to see what Rosetta sends back!

about 3 months ago
top

Telescope Designer and Astronomer John Dobson, 1915-2014

jomama717 Re:my dad (57 comments)

That's great. It's amazing the level of interest that people express when they are presented the opportunity to view these things with no effort or cost associated.

When the Venus transit happened I set up my little orion in the driveway and projected the image onto a sheet of paper and within 10 or 15 minutes a mob of people from my neighborhood (most of whom I'd never met) had gathered around - parents on walks with their kids, dogs, or out jogging, what have you - it was great. They were all talking about it, asking questions about it, generally marveling at the image.

The best part was explaining it to the kids - I would explain what was happening, they would turn to the image again, and a few seconds later you could see on their faces the realization of the scope of what they were witnessing. It was really great. I can see why he did it.

about 3 months ago
top

How would you use science to innovate upon sports?

jomama717 Re:Automated referee-ing (253 comments)

I always wanted them to do this for gymnastics/ice skating/diving at the olympics and such - the subjective nature of the judging for these sports leads to all sorts of controversy.

They could require the athletes to wear sensors, or just stickers of some kind on their joints and then have the computer judge how close their movements come to the "ideal" movements for their size of frame. A perfect 10 would really mean perfection. They could still have a human panel to judge artistic merits or whatever, but particularly for diving and gymnastics it seems mainly technical.

about 3 months ago
top

Levitating and Manipulating Objects With Sound

jomama717 Re:Anti Gravity Schmanti Gravity (59 comments)

Pretty sure they were referring to the device/setup itself, not the effect.

about 3 months ago
top

New Superconductor Theory May Revolutionize Electrical Engineering

jomama717 Re: that picture takes me back (92 comments)

If you have a mac (or any Unicode able terminal) try out my sig. Saw the c64 code in someone else's sig, linked to a book about the phenomenon (maybe too strong a word)

about 4 months ago
top

Microsoft Adds Node.js Support To Visual Studio

jomama717 Re:Node.js?! How 'bout C89 support? (197 comments)

I'll check that out. Agreed that shitloads of nested anonymous handler functions is ugly as hell... and seems to be were most complex javascript leads. I'm not a huge proponent of node or anything, but I do think it has its uses.

about 5 months ago
top

Microsoft Adds Node.js Support To Visual Studio

jomama717 Re:Node.js?! How 'bout C89 support? (197 comments)

Interesting - it has occurred to me that a lot of these "new" fangled frameworks and such really are just a return to concepts and practices from the past - didn't know what the historic analog of this nodeJS (and the like) stuff was. Thanks.

about 5 months ago

Submissions

top

Curiosity Commences Drilling on Mars

jomama717 jomama717 writes  |  about a year ago

jomama717 writes "Although there is no official word yet from NASA it appears that drilling has commenced, based on evidence detailed here. Curiosity has been officially searching for drilling sites in the "Yellowknife Bay" area for nearly two weeks."
Link to Original Source
top

Ramanujan's Deathbed Conjecture Finally Proven

jomama717 jomama717 writes  |  about a year ago

jomama717 writes "Another chapter in the fascinating life of Srinivasa Ramanujan appears to be complete:

While on his death bed, the brilliant Indian mathematician Srinivasa Ramanujan cryptically wrote down functions he said came to him in dreams, with a hunch about how they behaved. Now 100 years later, researchers say they've proved he was right.

"

Link to Original Source
top

jomama717 jomama717 writes  |  more than 6 years ago

jomama717 (779243) writes "From the article :

SAN FRANCISCO (AP) — Internet search leader Google Inc. is trying to convince federal and state authorities that Microsoft Corp.'s Vista operating system is stifling competition as the high-tech heavyweights wrestle for the allegiance of personal computer users. In a 49-page document filed April 18 with the U.S. Justice Department and state attorneys general, Google alleged that the latest version of Microsoft's Windows operating system impairs the performance of "desktop search" programs that find data stored on a computer's hard drive.
"
top

jomama717 jomama717 writes  |  more than 7 years ago

jomama717 (779243) writes "From the article:

Landmark Legal Foundation today nominated nationally syndicated radio talk show host Rush Limbaugh for the 2007 Nobel Peace Prize. Limbaugh, whose daily radio show is heard by more than 20 million people on more than 600 radio stations in the United States and around the world, was nominated for the prestigious award for his "nearly two decades of tireless efforts to promote liberty, equality and opportunity for all humankind, regardless of race, creed, economic stratum or national origin. These are the only real cornerstones of just and lasting peace throughout the world," said Landmark President Mark R. Levin. "Rush Limbaugh is the foremost advocate for freedom and democracy in the world today," explained Levin.
There is no topic called "It's sad. Cry.""

Journals

top

Missing: Clipboard Swap

jomama717 jomama717 writes  |  more than 3 years ago

We are all very familiar with the ctrl-x/ctrl-c/ctrl-v cut/copy/paste functionality (s/ctrl/open-apple/ to be (non?)PC) but we are missing one: swap. There have been hundreds of times when the ability to hit a simple combination keystroke to simultaneously copy the selected text to the clipboard and paste the previous contents of the clipboard over the selected area would have been a huge help. I'm sure this can be done in various apps using macros, but a swap functionality with the same cross-app status that cut/copy/paste enjoy would be nice.

top

Battling "Terminal Obesity"

jomama717 jomama717 writes  |  more than 6 years ago Like many fellow IT professionals I struggle against the inevitable weight gain that comes with hours of sitting in front of a terminal with little time left over to hit the gym. It all comes down to calories - typing doesn't go a long way towards burning them, so I've come up with a few simple changes I can make in my routine to cut down the intake:

  1. Eat slow, eat less

    As a Subway fiend I did an experiment: rather than inhaling a footlong in 15 minutes, I tried slowly eating a six inch sub over the course of a half an hour. Eureka! At the end of the half hour I was completely stuffed (as opposed to ludicrously stuffed), and on half of the calories to boot. One tip - make it a point to actually put down whatever you are eating after every bite - you may be surprised how much that slows you down.

  2. Take the stairs

    May not sound like much, but I was shocked to discover that walking up 4 flights of stairs instead of taking the elevator actually winded me. To me this indicated two things: (1) I was grossly out of shape, and (2) that effort must have burned a few calories. Elevator be damned.

  3. Resist the dish

    As the pounds pile up, what once was an added bonus in the workplace - the abundance of candy dishes and snack machines - becomes a constant temptation. A little bit of self discipline goes a long way (6 tootsie rolls have 140 calories!!!) If the need to snack is firmly entrenched, bring your own - almonds and popcorn flavored rice cakes are my personal favorites. Moderation is still the key - an ounce of almonds (20-25) has as many calories as the six tootsie rolls (but won't leave you hungry for more in 10 minutes).

  4. Take a hike

    When I'm wrestling with a tricky problem or design detail, I have always found it beneficial to get away from my desk for a while. This used to mean hitting the snack room - using this "brain time" as an excuse to eat even more. Now I leave the building altogether and walk a few laps around it. Not only am I getting some exercise, but the fresh air seems to stoke the fire a bit. It's snowing you say? Get some snow shoes. Why not?

  5. Water is good - and free!

    Drinking water every day is such a simple thing, but goes a long way towards shedding the lbs. I used to drink Coke straight up (~5 a day to the tune of 755 calories) until I switched to diet. Sure, diet coke has no calories, but what exactly does it have? Now I drink water: no calories, free, and alll natural baby.

It's still a struggle, and I still have to work at these rules every day, but I think I've at least stopped the bleeding. I'd love to hear other ideas people have come up with in the interest of avoiding out of control weight gain in the IT workplace, and I hope at least one person out there gives some of these ideas a try.

top

Java Trie Implementation

jomama717 jomama717 writes  |  more than 6 years ago /******************************************
* The three classes below implement a    *
* "Trie" structure in java.  My favorite *
* application of this structure is a     *
* streaming keyword replacer where a     *
* keywords can be compared one character *
* at a time as a stream is read.  Enjoy! *
******************************************/

/**************
* LookupTree *
**************/

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Iterator;

/**
* A collection of LookupTreeNodes that represents a list of words
* layed out in such a way that incremental lookup by letter is convenient.
*/
public class LookupTree
{
  private LookupTreeNode mRootNode = new LookupTreeNode();

  public void addWord(String word)
  {
    LookupTreeNode nodeIter = mRootNode, tempIter = null;
    char currentChar = (char)0;

    for(int i = 0; i < word.length(); i++)
    {
      currentChar = word.charAt(i);

      if( (tempIter = nodeIter.getNodeForLetter(currentChar)) == null )
      {
        nodeIter = nodeIter.addLetter( currentChar, false );
      }
      else
      {
        nodeIter = tempIter;
      }
    }

    if( nodeIter.getIsWord() )
    {
      System.out.println( "Word: " + word + " already exists in table" );
    }
    else
    {
      nodeIter.setIsWord(true);
    }
  }

  /**
   * Given a file containing a list or words seperated by newlines fill up the
   * tree with those words.
   * @param fileName The name of the file to read words from.
   */
  public void loadWordsFromFile(String fileName)
  {
    String tempStr = null;
    File inFile = null;
    BufferedReader br = null;

    try
    {
      inFile = new File(fileName);

      br = new BufferedReader(
            new InputStreamReader(
             new FileInputStream(inFile)));

    }
    catch(FileNotFoundException fe)
    {
      System.out.println( fe.toString() );
      return;
    }

    try
    {
      while( (tempStr = br.readLine()) != null )
      {
        this.addWord( tempStr );
      }
    }
    catch(IOException ioe)
    {
      System.out.println( ioe.toString() );
    }
  }

  /**
   * Given String return true if the word is in the tree, false otherwise.
   * @param word The word to check the existence of.
   * @returns boolean true if the word is in the tree, false otherwise.
   */
  public boolean wordExists( String word )
  {
    LookupTreeNode nodeIter = mRootNode;
    boolean returnVal = false;
    char currentChar = (char)0;

    for( int i = 0; i < word.length(); i++)
    {
      currentChar = word.charAt(i);
      nodeIter = nodeIter.getNodeForLetter(currentChar);
      if( nodeIter == null )
      {
        break;
      }
    }

    if( nodeIter != null && nodeIter.getIsWord() )
    {
      returnVal = true;
    }

    return returnVal;
  }

  /**
   * Walk the table and perform an action on each word. Order is not guaranteed.
   * @param node The node to start from.
   * @param currWord The starting String, used for recursion
   * @param action A method in the form void action(String arg) to be performed on each string found
   */
  private void walkTable(LookupTreeNode node, String currWord, Method action)
  {
    Iterator iter = node.getLetterIterator();
    LookupTreeNode nextNode = null;
    Object [] arg = new Object[1];
    StringBuffer currentWord = new StringBuffer(currWord);
    currentWord.setLength( currWord.length() + 1 );
    char currentChar = (char)0;

    while( iter.hasNext() )
    {
      currentChar = ((Character)(iter.next())).charValue();
      currentWord.setCharAt(currWord.length(), currentChar);
      nextNode = node.getNodeForLetter( currentChar );
      if( nextNode.getIsWord() )
      {
        arg[0] = currentWord.toString();
        if( action != null && this.validateActionMethod( action ) )
        {
          try
          {
            action.invoke( this, arg );
          }
          catch( Exception e )
          {
            System.out.println( "Error while trying to execute method: " + action.toString() +
                                ": " + e.toString() );
          }
        }
        else
        {
          System.out.println( "Action method null or invalid" );
        }
      }

      this.walkTable( nextNode, currentWord.toString(), action );
    }
  }

  /**
   * Make sure that the method passed as action to the walker is of the right format.
   */
  private boolean validateActionMethod( Method action )
  {
    Class [] params = action.getParameterTypes();
    boolean returnVal = true;

    try
    {
      if( params.length != 1 || !params[0].equals(Class.forName("java.lang.String")) )
      {
        returnVal = false;
      }
    }
    catch( Exception e )
    {
      System.out.println( "Invalid class for parameter found" );
      returnVal = false;
    }

    return returnVal;
  }

  /**
   * Walk the tree and print each word
   */
  public void printTable()
  {
    try
    {
      this.walkTable( mRootNode, new String(), this.getActionMethodFromName( "printWord" ) );
    }
    catch(Exception e)
    {
      System.out.println( e.toString() );
    }
  }

  protected void printWord( String arg )
  {
    System.out.println( arg );
  }

  /**
   * utility for retrieving the Method object from the method name from *this* class
   */
  private Method getActionMethodFromName( String funcName )
  {
    Method returnMethod = null;

    try
    {
      Class [] params = { new String().getClass() };
      returnMethod = this.getClass().getDeclaredMethod( funcName, params );
    }
    catch( Exception e )
    {
      System.out.println( "Warning - returning null method: " + e.toString() );
    }

    return returnMethod;
  }

  /**
   * Return an iterator that can be used to incrementally (letter by letter)
   * check if a word exists in the list.
   */
  public LookupTreeIterator getIterator()
  {
    return new LookupTreeIterator(mRootNode);
  }

  /**
   * Return an iterator that can be used to incrementally (letter by letter)
   * check if a word exists in the list.
   */
  public boolean isRootChar( char c)
  {
    return mRootNode.containsLetter( c );
  }

  public static void main( String [] args )
  {
    try
    {
      LookupTree LT = new LookupTree();
      LT.loadWordsFromFile("dictionary.txt");
      LT.printTable();

      BufferedReader stdReader = new BufferedReader(
                                 new InputStreamReader( System.in ));

      String tempStr = null;

      while(true)
      {
        System.out.print("Enter a word to lookup, or \"quit\" to quit: ");
        tempStr = stdReader.readLine();
        if(tempStr.equals("quit") )
        {
          break;
        }
        else
        {
          System.out.println( LT.wordExists( tempStr ) );
        }
      }
    }
    catch(Exception e)
    {
      e.printStackTrace();
      System.out.println( e.toString() );
    }
  }

}

/******************
* LookupTreeNode *
******************/

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
* Represents one node of a tree class that makes
* incremental word-lookup easy.
*/
public class LookupTreeNode
{
  //true when the word ending with the letter that is this
  //TreeNode's key is a complete word.
  private boolean isWord = false;
  private HashMap letterMap = new HashMap();

  public LookupTreeNode() {}

  /**
   * Returns an iterator over the set of keys in this Node.
   * The set of keys is the set of letters represented at this
   * level of the tree.
   * @returns Iterator The keySet iterator
   */
  public Iterator getLetterIterator()
  {
    return letterMap.keySet().iterator();
  }

  /**
   * Returns the Set of keys int his Node.  The keys represent
   * the letters represented at this level of the tree.
   * returns Set The set of letters in this Node.
   */
  public Set getLetterSet()
  {
    return letterMap.keySet();
  }
  /**
   * Returns the Set of keys int his Node.  The keys represent
   * the letters represented at this level of the tree.
   * returns Set The set of letters in this Node.
   */

  public boolean containsLetter( char c )
  {
    return letterMap.containsKey(new Character(c));
  }

  /**
   * Adds a new letter at this level, and returns the corresponding
   * Node that is created.
   * @param c The letter to be added
   * @param isword If true, the isWord flag will be set for true in the returned Node,
   *        indicating that the added letter completed a word.
   * @returns LookupTreeNode The added node.
   */
  public LookupTreeNode addLetter(char c, boolean isword)
  {
    LookupTreeNode newNode = new LookupTreeNode();

    letterMap.put(new Character(c), newNode);

    return newNode;
  }

  public boolean getIsWord() { return this.isWord; }
  public void setIsWord( boolean isword ) { isWord = isword; }

  /**
   * See if this node contains some letter c.  If it does, return the letter's
   * corresponding node.
   * @param c The letter to look up
   * @returns LookupTreeNode the Node corresponding to the letter c, or null
   */
  public LookupTreeNode getNodeForLetter(char c)
  {
    return (LookupTreeNode)letterMap.get(new Character(c));
  }
}

/**********************
* LookupTreeIterator *
**********************/

import java.util.Set;

/**
  * The iterator class.  Maintains state and can be reset.
  */
public class LookupTreeIterator
{
   private final int BUFFER_SIZE     = 1024;
   private LookupTreeNode mInitialTreeNode = null;
   private LookupTreeNode mCurrentTreeNode = null;
   private Set mCurrentNodeKeys      = null;
   private char [] mCurrentWord      = null;
   private int mCurrentWordCount     = 0;
   private boolean mValidState       = true;
   private boolean mIsWord           = false;

   /**
    * Start at node rootNode, initialize word buffer, set initial node for reset later.
    */
   public LookupTreeIterator( LookupTreeNode rootNode )
   {
     mCurrentTreeNode  = mInitialTreeNode = rootNode;
     mCurrentNodeKeys  = mCurrentTreeNode.getLetterSet();
     mCurrentWord      = new char [ BUFFER_SIZE ];
     mCurrentWordCount = 0;
   }

   /**
    * See if the character c exists at the iterator's current location in the tree.
    */
   public boolean tryCharacter( char c )
   {
     boolean returnVal = false;
     mCurrentWord[ mCurrentWordCount++ ] = c;
     if( mCurrentNodeKeys.contains( new Character(c) ) )
     {
       returnVal = true;
       gotoNextNode(c);
     }
     else
     {
       mValidState = false;
       mIsWord = false;
     }
     return returnVal;
   }

   /**
    * Iterate to the next letter, only called if that letter exists.
    */
   private void gotoNextNode( char c )
   {
     mCurrentTreeNode = mCurrentTreeNode.getNodeForLetter(c);
     mCurrentNodeKeys = mCurrentTreeNode.getLetterSet();
     mIsWord = mCurrentTreeNode.getIsWord();
   }

   /**
    * Get the current buffer containing all looked up letters, including any that didn't exist.
    */
   public String getCurrentBuffer()
   {
     //MJM return mCurrentWord.toString();
     return new String( mCurrentWord, 0, mCurrentWordCount );
   }

   /**
    * Is the word currently held in the buffer a complete word in the tree?
    */
   public boolean isWord()
   {
     return mIsWord;
   }

   /**
    * Is the iterator currently in a valid state?  i.e. did the last letter checked exist,
    * meaning that what is currently in the buffer can be traced in through the tree?
    */
   public boolean isValid()
   {
     return mValidState;
   }

   /**
    * Reset the iterator
    */
   public void reset()
   {
     mCurrentTreeNode = mInitialTreeNode;
     mCurrentNodeKeys = mCurrentTreeNode.getLetterSet();
     mCurrentWordCount = 0;
     mValidState = true;
   }

}

top

How a Macbook Saved My Marriage

jomama717 jomama717 writes  |  about 7 years ago Ok, the subject is a gross exaggeration, but check this out:

My wife of close to a year has a macbook that I rarely use but am increasingly intrigued by. Out of the blue I get a business trip to London for one week (we live in Chicago), where my wife's brother lives. She would love to come with me but alas her passport is in limbo. Why? She is having her last name changed to mine...DOH! Feeling bad about all of this I devise a plan to leave cards hidden around the house that contain riddles that divulge the location of a small present, one each day while I am away. The only problem - how to indicate the location of the clue cards, which are themselves hidden? I thought about email, but decided I would probably be too busy to remember every morning, and the time difference would be tricky. A phone call is no good because she would use her jedi mind control powers to bypass the clues and get straight to the present. Maybe an automated daily event of some kind...? After some thinking I come up with a simple file/shell script combination that I leave on her laptop:

The file (clues.txt) is a text file with a line for each day/clue that starts with the date followed by a colon, e.g. "Mar_19:<the riddle>".

An example riddle/clue is:
"From where I sit from daybreak to close, right under this is under my nose" (I do development work full time from home, and the card was under my keyboard)

The script:

CLUES=/some/obscure/path/clues.txt
cluekey=`date | tr -s '[:space:]' | cut -d" " -f2,3 | tr ' ' '_'`;
clue=`cat "$CLUES" | grep "$cluekey" | cut -d":" -f2`

if [ "X$clue" = "X" ]; then
echo "No clue today!";
else
echo $clue
fi

Simple enough - now for the really cool part - the Macbook has a feature that I stumble across called "automator" which is basically a workflow engine that uses as tasks various actions from various applications on the computer. One of these actions is "Run Shell Script" - which takes text input and gives text output. Another workflow task is "Text to Speech", which takes text as input and "speaks" the text as output. I create a simple 2 step workflow of my script and the text to speech piece, and then the automator allows me to save the workflow as an application on the desktop! I save the workflow as "GetTodaysClue" and stick it right in the middle of her desktop. Before I leave to catch my flight on Friday I leave some flowers and a card that points out the curious new icon on her desktop, and the game is afoot. The clue automatically changes each day and is spoken as many time as my wife needs to hear it before the next day - brilliant!

The whole plan was a huge hit, and I gained a great deal of respect for the mac - so much so that I plan on buying one when my PC dies.

top

"Golden Ass" Anime

jomama717 jomama717 writes  |  more than 7 years ago I recently read the ancient story The Golden Ass written by Apuleius and was blown away by the imagery and wild storyline it contained. It soon after occured to me what a great movie it would make, although due to some of the racy subject matter in it it might be better served by an animated movie along the lines of Princess Mononoke or even Fire and Ice . I'm not holding my breath - but man would that be cool!

top

More useful shell functions

jomama717 jomama717 writes  |  more than 7 years ago Here are some more shell functions that I have found to be extremely useful in a development environment.  Most are made obsolete by using an IDE, but there are always cases where you get stuck in a console writing code.

#
#C/C++ source recursive find: recfind <search_string>
#
function recfind {
    find . -name "*.[ch]*" -print | xargs grep -n "$1";
} 2>/dev/null

#
#Java source recursive find: jrecfind <search_string>
#
function jrecfind {
    find . -name "*.java" -print | xargs egrep -n "$1";
} 2>/dev/null

#
#Generic recursive find: grecfind [<filespec>] <search_string>
#
function grecfind {
    if [ $# -eq 1 ]; then
        findStr=${1};
        fileSpec=*;
    else
        findStr=${2};
        fileSpec=${1};
    fi

    find . -name "${fileSpec}" -print | xargs grep -n ${findStr};
} 2>/dev/null

#
#Find a java class in a deployed application environment: findClass <classname>
#
function findClass {
  echo "Looking in jars..."
  for jarfile in `find . -name "*.jar" -print`; do
    FOUND=(`jar tf $jarfile | grep "$1"`);
    if [ ! -z ${FOUND[0]} ]; then
      echo "Found in $jarfile:";
      for found in ${FOUND[@]}; do
        echo "$found";
      done
    fi
  done
  echo "...done.  Looking on filesystem..."
  find . -name "*$1*.class" -print
  echo "...done."
} 2>/dev/null

top

Bash "cd" wrapper

jomama717 jomama717 writes  |  more than 7 years ago Below is some bash script I wrote years ago that allows you to "anchor" up to 5 directories for fast access later by entering the command "cd [1-5]".  You can assign a number to the current directory by typing "cd -s [1-5]", and dump the current assignments with "cd -p".  Aside from these new options cd operates as normal (unless you have directories named 1,2,3,4, or 5).  There is also a "dir_persist" function that saves off the current set of anchors under a given tag and can be loaded up after a subsequent login.  I find that this simple change allows me to navigate a large source repository much faster than before (no more cd ../../../../../../../other_component).  Note that this is the "cygwinized" version, which should run on unix but I've never tried it.  I originally only used it only on unix machines, and had to jump through some hoops to handle directories with spaces in the names on cygwin.

CD_USAGE="cd: Usage: cd [ -s [ 1-5 | [1-5]=<directory> ] | -p | <directory name> | [1-5] ]";

function dir_persist {
     DIRSTRINGS="ONE_DC TWO_DC THREE_DC FOUR_DC FIVE_DC";
    _DIRSTRINGS=($DIRSTRINGS);

    if [ $# -eq 0 ]; then
      echo -n "Enter a name to persist dirs under, or <enter> to skip: "
      read session_tag
    else
      session_tag=${1}
    fi

    if [ "${session_tag}" = "" ]; then
        CDFILE_NAME=".cdfile_${HOSTNAME}_default"
    else
        CDFILE_NAME=".cdfile_${HOSTNAME}_${session_tag}"
    fi

    let count=0;
    while [ $count -lt 5 ] ; do
      outp=`env | grep "${_DIRSTRINGS[$count]}"`;
      if [ "" != "$outp" ] ; then
        dir_to_print=`echo $outp | cut -d"=" -f2`;
        let num=count+1;
        if [ $count -eq 0 ] ; then
            echo "$num=$dir_to_print" > ~/${CDFILE_NAME};
        else
            echo "$num=$dir_to_print" >> ~/${CDFILE_NAME};
        fi
      fi
      let count=count+1;
    done
}

function dirset {
     DIRSTRINGS="ONE_DC TWO_DC THREE_DC FOUR_DC FIVE_DC";
    _DIRSTRINGS=($DIRSTRINGS);
let err=0;

if [ "$#" -ge 2 ] || [ "$#" -eq 0 ] ; then
   let err=1;
fi
if [ -z `echo "$1" | grep "="` ] ; then
    let reg=$1;
    let pwd_flag=1;
else
    let reg=`echo "$1" | cut -d"=" -f1`;
    dir=`echo "$1" | cut -d"=" -f2 | tr '~' ' '`;
    let pwd_flag=0;
fi

if [ $reg -gt 5 ] || [ $reg -eq 0 ] ; then
   echo >&2 "cd: Invalid directory choice";
   let err=1;
fi
if [ $err -eq 0 ] ; then
    let reg=reg-1;
    if [ $pwd_flag -eq 1 ] ; then
        littlePWD="${PWD}"
        export "${_DIRSTRINGS[$reg]}=${littlePWD}";
    else
        littleDir="${dir}"
        export "${_DIRSTRINGS[$reg]}=${littleDir}";
    fi
fi
}

function cd {
  DIRSTRINGS="ONE_DC TWO_DC THREE_DC FOUR_DC FIVE_DC"
  _DIRSTRINGS=($DIRSTRINGS)
  let err=0

case $# in
0)
    command cd
     return
;;
1)
    if [ "$1" = "-p" ] ; then
      let count=0
       while [ "$count" -lt 5 ] ; do
         outp=`env | grep "${_DIRSTRINGS[$count]}"`
         if [ "" != "$outp" ] ; then
           dir_to_print=`echo $outp | cut -d"=" -f2`
           let num=count+1
           echo "$num) $dir_to_print"
         fi
         let count=count+1
       done
     elif [ "$1" = 1 -o "$1" = 2 -o "$1" = 3 -o "$1" = 4 -o "$1" = 5 ] ; then
      let choice=$1
      let choice=choice-1
      _CD_STRING="\$${_DIRSTRINGS[$choice]}"
      CD_STRING=`eval echo "${_CD_STRING}"`
      command cd "${CD_STRING}"
     else
      command cd "${1}"
      return
     fi
;;
2)
    teststr=`echo $1 | grep "\-s"`
   if [ -z "$teststr" ] ; then
      echo >&2 "$CD_USAGE"
      let err=1
      return
   fi
      dirset "$2"
;;
*)
     echo >&2 "$CD_USAGE"
     let err=1
     return
;;
esac

}

top

"Text Twist" cheating code

jomama717 jomama717 writes  |  more than 6 years ago

UPDATE:

If anyone cares (HA!) I noticed recently that TextTwist 2 came out, so I downloaded it and sure enough they are using the same crazy flat file representation of a trie that they used in the first version (see below), I just had to tweak the code to allow 15 letter words and expand the result table size. Change:

#define MAX_WORD_LEN 7
#define RESULT_TABLE_SIZE 64

to:

#define MAX_WORD_LEN 15
#define RESULT_TABLE_SIZE 128

and you're good to go.

The C++ code below is some old code (I just updated it to use the std::* stuff) I found laying around from a few years back that I wrote to cheat at the game "Text Twist" that I was semi-addicted to once. The game is a standard jumble/word finding game where you get 5-7 letters and have to put together all of the words that can be made from those letters. What originally got me interested was a file called "longtree.bin" in the installation area that turned out to be a flat-file representation of a trie (http://en.wikipedia.org/wiki/Trie) containing all of the words in the game. The code below compiles (on windows only as it is, the file handling stuff is windows specific) into an executable that takes the longtree file and sequences of letters and dumps out the exact list of words (in the correct order) that the game will count. The code is not professional quality, so expect some crashes if you color outside of the lines. Enjoy! ///////Begin code////////

#include <string>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <ctype.h>
#include <windows.h>
 
#define MAX_WORD_LEN 7
#define RESULT_TABLE_SIZE 64
 
typedef HANDLE fileDesc;
typedef int (*compareFunc)(std::string, std::string);
 
bool validFile(fileDesc file);
fileDesc createFile(const char *fileName);
fileDesc openFile(const char *fileName);
int fileRead(fileDesc fd, void *buf, size_t s);
int fileGetCurrentPointer(fileDesc fd);
int fileSetCurrentPointer(fileDesc fd, unsigned int offset);
bool closeFile(fileDesc file);
bool writeFile(fileDesc file, const char *buffer, size_t len);
int alphaCompare(std::string a, std::string b);
int hashCompare(std::string a, std::string b);
int sortHash(std::string str, int idx);
void rotateStr( std::string &str, int idx);
 
enum state { S_START=0, S_ALPHA=1, S_ZERO=2, S_ONE=3, S_ERROR=5 };
 
///////////////
// nodeList //
///////////////
struct nodeList
{
  char letter;
  bool isWord;
  nodeList *nextLetter;
  nodeList *nextLocal;
};
 
/////////////////
// searchTree //
/////////////////
class searchTree
{
private:
  std::ofstream tout;
  nodeList *root;
  std::string *resultTable[RESULT_TABLE_SIZE];
  int wordCounts[MAX_WORD_LEN];
public:
  searchTree()
  {
    root = NULL;
    tout.open("debugTree.txt", std::ios::out);
    for(int i = 0; i < RESULT_TABLE_SIZE; i++) resultTable[i] = NULL;
    for(int j = 0; j < MAX_WORD_LEN; j++) wordCounts[j] = 0;
  }
  void addWordToTree(std::string newWord);
  int getAllSubWords(std::string findMe);
  nodeList *createBasicNode(char letter);
  nodeList *isLetterInList(nodeList *head, char let);
  nodeList *addLetterToList(nodeList *head, char let);
  void operateOnPerms(std::string s, int i);
  void findAllSubsOf(std::string str);
  void addToResultTable(std::string str);
  void resetResultTable();
  void printResultTable();
  void sortResultTable(compareFunc func);
  void printWordCounts();
};
 
/////////////////
// treeReader //
/////////////////
class treeReader
{
private:
  std::ofstream fout;
  searchTree *myTree;
  fileDesc descriptor;
  int markers[MAX_WORD_LEN], reader;
  state currentState;
  char currentVal;
  static const char fileName[];
public:
  treeReader()
  {
    fout.open("ttwist_debug.txt", std::ios::out);
    myTree = new searchTree;
    descriptor = openFile(fileName);
    currentState = S_START;
 
    for(int i = 0; i < MAX_WORD_LEN; i++)
    {
      markers[i] = -1;
    }
 
    reader = 0;
    fileSetCurrentPointer(descriptor, reader);
    currentVal = getCharacter(reader);
  }
 
  ~treeReader(){ fout.close(); }
  void processTree();
  char getCharacter(int pos);
  char lookAtNext(int pos);
  void advanceReader(){ reader++; }
  void getWordSkipLast();
  void getWordFull();
  void deleteAndAdvanceMarkers();
  void setNextMarker(int pos);
  void setCurrentState(state newState){ currentState = newState; }
  void foundAlpha();
  void foundZero();
  void foundOne();
};
 
////////////////////////////////////
// //
// treeReader Functions //
// //
////////////////////////////////////
 
void treeReader::processTree()
{
  char value;
  char inputStr[256];
  std::string *temp = new std::string;
  while(value = getCharacter(reader))
  {
    if(isalpha(value))
    {
      foundAlpha();
    }
    else if(value == '0')
    {
      foundZero();
    }
    else if(value == '1')
    {
      foundOne();
    }
    else
    {
      std::cout << "Error: foreign character found\n";
      exit(1);
    }
 
    advanceReader();
  }
 
  myTree->printWordCounts();
 
  while(1)
  {
    std::cout << "Enter a string: ";
    std::cin >> *temp;
    if(*temp == "kwit") break;
    myTree->findAllSubsOf(*temp);
  }
  std::cout << "Done!\n";
}
 
void treeReader::foundAlpha()
{
  switch(currentState)
  {
    case S_START:
      setNextMarker(reader);
      break;
    case S_ALPHA:
      break;
    case S_ZERO:
      setNextMarker(reader);
      break;
    case S_ONE:
      setNextMarker(reader);
      break;
  }
 
  setCurrentState(S_ALPHA);
}
 
void treeReader::foundZero()
{
  switch(currentState)
  {
    case S_START:
      break;
    case S_ALPHA:
      break;
    case S_ZERO:
      break;
    case S_ONE:
      break;
  }
 
  setCurrentState(S_ZERO);
}
 
void treeReader::foundOne()
{
  switch(currentState)
  {
    case S_START:
      break;
  case S_ALPHA:
      getWordSkipLast();
      break;
    case S_ZERO:
      getWordFull();
      deleteAndAdvanceMarkers();
      break;
    case S_ONE:
      getWordFull();
      deleteAndAdvanceMarkers();
      break;
  }
 
  setCurrentState(S_ONE);
}
 
void treeReader::getWordSkipLast()
{
  char *foundWord = (char*)malloc((MAX_WORD_LEN + 1)*sizeof(char));
  int i;
  for(i = 0; i < MAX_WORD_LEN; i++)
  {
    if(markers[i] == -1) break;
      foundWord[i] = getCharacter(markers[i]);
  }
 
  foundWord[i - 1] = '\0';
  std::string str(foundWord);
  myTree->addWordToTree(str);
  free(foundWord);
}
 
void treeReader::getWordFull()
{
  char *foundWord = (char*)malloc((MAX_WORD_LEN + 1)*sizeof(char));
  int i;
  for(i = 0; i < MAX_WORD_LEN; i++)
  {
    if(markers[i] == -1) break;
      foundWord[i] = getCharacter(markers[i]);
  }
 
  foundWord[i] = '\0';
  std::string str(foundWord);
  myTree->addWordToTree(str);
  free(foundWord);
}
 
char treeReader::getCharacter(int pos)
{
  void *buf = malloc(32);
  char *returnVal, returnChar;
  fileSetCurrentPointer(descriptor, pos);
 
  if(!fileRead(descriptor, buf, 1))
  {
    return 0; //EOF
  }
 
  fileSetCurrentPointer(descriptor, pos); //don't increment
  returnVal = (char*)buf;
  returnChar = returnVal[0];
  free((char*)buf);
  return returnChar;
}
 
char treeReader::lookAtNext(int pos)
{
  char returnChar;
  returnChar = getCharacter(pos+1); //check for EOF
  return returnChar;
}
 
void treeReader::setNextMarker(int pos)
{
  int i = 0;
  while((markers[i] != -1) && (i < MAX_WORD_LEN)) i++;
  markers[i] = pos;
}
 
void treeReader::deleteAndAdvanceMarkers()
{
  for(int i = MAX_WORD_LEN - 1; i >= 0; i--)
  {
    if(markers[i] != -1)
    {
      if(!isalpha(lookAtNext(markers[i])))
      {
        markers[i] = -1;
      }
      else
      {
        markers[i]++;
        return;
      }
    }
  }
}
 
const char treeReader::fileName[] = "longtree.bin";
 
///////////////////////////////////////////
// //
// searchTree Functions //
// //
///////////////////////////////////////////
 
void searchTree::addWordToTree(std::string newWord)
{
  nodeList *nextLetterList = root;
  nodeList *follow = root;
  nodeList *looker = root;
 
  wordCounts[newWord.length() - 1] += 1;
 
  for(int i = 0; i < newWord.length(); i++)
  {
    if(root == NULL)
    {
      root = createBasicNode(newWord[i]);
      follow = root;
      nextLetterList = looker = root->nextLetter;
      continue;
    }
 
    looker = isLetterInList(nextLetterList, newWord[i]);
 
    if(looker == NULL)
    { //not in list
      looker = addLetterToList(nextLetterList, newWord[i]);
 
      if(nextLetterList == NULL)
      {
        nextLetterList = looker; //first let in list
      }
 
      if(follow != nextLetterList)
      { //if not on first level of tree
        follow->nextLetter = nextLetterList;
      }
    }
 
    follow = looker;
    nextLetterList = looker = looker->nextLetter;
  }
 
  follow->isWord = true;
}
 
nodeList *searchTree::createBasicNode(char letter)
{
  nodeList *ptr = new nodeList;
  ptr->letter = letter;
  ptr->nextLocal = ptr->nextLetter = NULL;
  ptr->isWord = false;
  return ptr;
}
 
nodeList *searchTree::isLetterInList(nodeList *head, char let)
{
  nodeList *temp;
  for(temp = head; temp != NULL; temp = temp->nextLocal)
  {
    if(temp->letter == let)
    {
      return temp;
    }
  }
 
  return NULL;
}
 
//this assumes that let is not in list
nodeList *searchTree::addLetterToList(nodeList *head, char let)
{
  nodeList *temp, *follow = NULL;
  for(temp = head; temp != NULL; temp = temp->nextLocal)
  {
    follow = temp;
  }
 
  temp = createBasicNode(let);
 
  if(follow != NULL) follow->nextLocal = temp; //if not first letter
  return temp;
}
 
int searchTree::getAllSubWords(std::string findMe)
{
  int i = 0;
  std::string result("");
  nodeList *lastLet = root;
  nodeList *looker = root;
  for(int i = 0; i < findMe.length(); i++)
  {
    while((looker != NULL) && (looker->letter != findMe[i]))
    {
      looker = looker->nextLocal;
    }
 
    if(looker == NULL)
    {
      return 0;
    }
    else if(looker->letter = findMe[i])
    {
      result += looker->letter;
      if(looker->isWord)
      {
        addToResultTable(result);
      }
    }
    else if(looker == NULL)
    {
      return 0;
    }
 
    lastLet = looker;
    looker = looker->nextLetter;
  }
}
 
void searchTree::addToResultTable(std::string str)
{
  int i;
  for(i = 0; resultTable[i] != NULL; i++)
  {
    if(i >= RESULT_TABLE_SIZE)
    {
      std::cout << "Result table limit exceeded\n";
      return;
    }
    if(*resultTable[i] == str)
    {
      return;
    }
  }
 
  resultTable[i] = new std::string(str);
}
 
void searchTree::printResultTable()
{
  sortResultTable(&hashCompare);
  sortResultTable(&alphaCompare);
  for(int i = 0; i < RESULT_TABLE_SIZE; i++)
  {
    if(resultTable[i] == NULL) return;
    std::cout << *resultTable[i] << std::endl;
  }
}
 
void searchTree::resetResultTable()
{
  for(int i = 0; i < RESULT_TABLE_SIZE; i++)
  {
    if(resultTable[i] == NULL) return;
    delete resultTable[i];
    resultTable[i] = NULL;
  }
}
 
void searchTree::sortResultTable(compareFunc func)
{
  int i, j, m, n;
  std::string *temp;
  for(m = 0; resultTable[m] != NULL; m++);
  i = m-1;
  int lastExchangeIdx;
 
  while (i > 0)
  {
    lastExchangeIdx = 0;
    for(j = 0; j < i; j++)
    {
      if((*func)(*resultTable[j+1],*resultTable[j]) == 1)
      {
        temp = resultTable[j];
        resultTable[j] = resultTable[j+1];
        resultTable[j+1] = temp;
        lastExchangeIdx = j;
      }
    }
 
    i = lastExchangeIdx;
  }
}
 
//return a < b ? 1 : 0
int alphaCompare(std::string a, std::string b)
{
  if(a.length() != b.length()) return -1;
 
  for(int i = 0; i < a.length(); i++)
  {
    if(a[i] == b[i])
    {
      continue;
    }
    else if(a[i] < b[i])
    {
      return 1;
    }
    else
    {
      return 0;
    }
  }
}
 
//return a < b ? 1 : 0
int hashCompare(std::string a, std::string b)
{
  int aHash = sortHash(a, 0);
  int bHash = sortHash(b, 0);
  if(aHash == bHash)
  {
    return -1;
  }
  else if(aHash < bHash)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}
 
int sortHash(std::string str, int idx)
{
  return ((int)str[idx] * (str.length() - 2));
}
 
void searchTree::findAllSubsOf(std::string str)
{
  operateOnPerms(str, 0);
  printResultTable();
  resetResultTable();
}
 
void searchTree::operateOnPerms(std::string s, int n)
{
  int i;
  if( n == s.length()-1 )
  {
    getAllSubWords(s);
  }
  else
  {
    int k=s.length();
 
    for( i=n ; i<k ; i++ )
    {
      int j;
 
      for( j=k+n-i ; j<k ; j++ )
        if( s[n] == s[j]) break;
 
      if( j==k ) operateOnPerms( s,n+1);
 
      rotateStr( s, n);
    }
  }
}
 
void searchTree::printWordCounts()
{
  for(int i = 0; i < MAX_WORD_LEN; i++)
  {
    if(wordCounts[i])
    {
      std::cout << "Words with " << i+1 << " letters: " << wordCounts[i] << std::endl;
    }
  }
}
 
void rotateStr( std::string &str, int idx )
{
  char temp = 0;
  int i = 0;
  int len = str.length();
 
  if(idx < len )
  {
    temp = str[idx];
 
    for(int i = idx; i<len-1; i++) str[i] = str[i+1];
    str[len-1] = temp;
  }
}
 
///////////////////////////////////////////
// //
// Main //
// //
///////////////////////////////////////////
 
int
main()
{
  treeReader TR;
  TR.processTree();
  return 0;
}
 
////////////////////////////////////////////
// //
// File Processing Functions //
// //
////////////////////////////////////////////
 
bool
validFile(fileDesc file)
{
    return file != INVALID_HANDLE_VALUE;
}
 
fileDesc
createFile(const char *fileName)
{
    return CreateFile(fileName,
                      GENERIC_READ | GENERIC_WRITE,
                      FILE_SHARE_READ,
                      NULL,
                      CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL,
                      NULL);
}
 
fileDesc
openFile(const char *fileName)
{
    return CreateFile(fileName,
                      GENERIC_READ,
                      FILE_SHARE_READ,
                      NULL,
                      OPEN_EXISTING,
                      0,
                      NULL);
}
 
int
fileRead(fileDesc fd, void *buf, size_t s)
{
    BOOL successful;
    DWORD br;
 
    successful = ReadFile((HANDLE)fd, buf, s, &br, 0);
    if(!successful)
        return -1;
    else
        return br;
}
 
int
fileGetCurrentPointer(fileDesc fd)
{
    return SetFilePointer((HANDLE)fd, 0, NULL, FILE_CURRENT);
}
 
int
fileSetCurrentPointer(fileDesc fd, unsigned int offset)
{
    return SetFilePointer((HANDLE)fd, offset, NULL, FILE_BEGIN);
}
 
bool
closeFile(fileDesc file)
{
    return CloseHandle(file);
}
 
bool
writeFile(fileDesc file, const char *buffer, size_t len)
{
    DWORD bytesWritten;
 
    return WriteFile(file, buffer, len, &bytesWritten, NULL);
}

top

Madonna vs. Doctor Who

jomama717 jomama717 writes  |  more than 7 years ago I heard the Madonna song "Hung Up" on TV the other day and the background beat/tune sounded to me exactly like the Doctor Who theme song as I remember it (Tom Baker years). I tried to get the original Doctor Who theme from itunes but all I came up with was some crappy rip-off remix of it, which, actually did sound a lot like the Madonna song. I suppose I'll have to buy a Doctor Who DVD and rip the theme off of there if I want to get my hands on the real deal.

Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...