Tuesday, March 10, 2015

Space Engineers and stone removal

This is one of those cases where the editor just isn't wide enough. Attached is some code that I wrote for a friend because I know some C#. It is for the starting miner ship, but it's not completely functional because it does not sort all items to the connector. You need a second connector to dump waste. I only had a basic understanding of the game's systems. Good luck!
Code:
 void Main() 
 { 
    var blockTerminal = new List<IMyTerminalBlock>();
    var blockProduction = new List<IMyTerminalBlock>();  
    
    GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(blockTerminal); 
    GridTerminalSystem.GetBlocksOfType<IMyProductionBlock>(blockProduction); 
    
    //now get the Wastedump connector.  You need to use an object that can eject stuff 
    IMyShipConnector wasteboxport = GridTerminalSystem.GetBlockWithName("Connector") as IMyShipConnector;    
    var wastebox = wasteboxport as Sandbox.ModAPI.InterfacesIMyInventoryOwner;     //this is the transfer target
    
    blockTerminal.AddRange(blockProduction);  //merge lists, notice the "AddRange" due to the class type
    blockTerminal.Add(wasteboxport);  //merge lists, note the "Add"


    int i_counterBlockTerminal;
    int i_counter_source;
    int i_counter_inventory;
    
    if(blockTerminal.Count==0)
    {
    ;;
    }else
    {
        for (i_counterBlockTerminal=0; i_counterBlockTerminal<blockTerminal.Count; i_counterBlockTerminal++)//loop through each block
        {
            var inventory_source = blockTerminal[i_counterBlockTerminal] as Sandbox.ModAPI.InterfacesIMyInventoryOwner; 
       //         throw new Exception("inventory_source.InventoryCount: "+inventory_source.InventoryCount);
            for(i_counter_source=0; i_counter_source<inventory_source.InventoryCount; i_counter_source++)//loop through each item of the selected block            
            {       // also, because inventory is of type IMyInventoryOwner, I had to make the "Count" method InventoryCount
                   var inventory_items = inventory_source.GetInventory(i_counter_source).GetItems(); 
                   // throw new Exception("inventory_items.Count: "+inventory_items.Count);
                for(i_counter_inventory=0; i_counter_inventory<inventory_items.Count; i_counter_inventory++) 
                {
                    var item_name = inventory_items[i_counter_inventory].ToString().Split('x');   //need to split the "amount x name" string
                    //throw new Exception("blockTerminal["+i_counterBlockTerminal+"]inventory_source["+i_counter_source+"]: "+item_name[0]);
                    string item_type = item_name[1];
                    if (item_type.Contains(@"Ingot/Stone") || item_type.Contains(@"Ore/Stone"))
                    {
                        //move everything into the waste connector
                        //throw new Exception("item_type: "+item_type);
                        inventory_source.GetInventory(i_counter_source).TransferItemTo(wastebox.GetInventory(0), i_counter_inventory, null, true, null); 
                    }  
                }

            }
        }
        //the end of moving things to the connector
        wasteboxport.GetActionWithName("ThrowOut").Apply(wasteboxport); 
    }
 }

Monday, March 31, 2014

Cadence and tunneling ports

Cadence periodically changes ports. There is a "base" connection port, and then some client ports. I recently helped a friend tunnel their license server connection so that he could push rectangles in the coffee shop.

As an example, the license port is specified:
CDS_LIC_FILE=5280@ecelinsrv3.ece.gatech.edu
However, Cadence opens a bunch of client ports, so you need to forward more than just the primary port. In the end, the forwarding script (tun.sh) looked like:
#!/bin/sh
ssh -C -2 -f -N -g \
-L 5280:ecelinsrv3.ece.gatech.edu:5280 \
-L 32801:ecelinsrv3.ece.gatech.edu:32801 \
-L 32815:ecelinsrv3.ece.gatech.edu:32815 \
ecelinsrv9.ece.gatech.edu
The higher number ports you need to find with:
netstat -tulpn
It will list groups of TCP ports, and add those to the script until you get a successful tunneling of the license. In my case, 32801 and 32815 where the secondary ports to forward that day. It is also worth noting that these seem to change every once in awhile, so if you cannot get a license, you will need to update the port list.

Monday, January 6, 2014

Computer Scientists are pretty much worthless when it comes to conserving anything.

Bits are equal to power. Let's say that I want a simple tool to get a file, in this case "wget". One would think that it would be simple to compile it, or get it; however, here's the build dependency list:
gnutls libtasn1 nettle p11-kit desktop-file-utils glib2 libffi perl5 perl5.12 gdbm popt libxslt libxml2 xz libgcrypt libgpg-error pcre
Perl? I don't want Perl. I can see how libgcrypt and a few others are in there. I get to eat up flash write cycles, power, time just because someone decided to include perl.

Program packages should be as small as possible. This is important in an energy constrained environment or just as a function of time.

Tuesday, December 24, 2013

removing the password from PDF files.

PDF files with passwords really do not make much sense. You can remove the PDF password easily, and for free. You just need ghostscript installed.
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=PDFnopass.pdf -c .setpdfwrite -f PDFwithPASSWORD.pdf

Sunday, October 27, 2013

Cross platform Makefile

I needed to change my Makefile to output different target information based on the Operating System. This turned out more difficult than I thought since Windows doesn't have uname. I asked some friends, and the gave me some code snippets. To start with find the OSCLASS and OSNAME.
ifeq ($(OS),Windows_NT)
    OSCLASS = windows
    OSNAME=windows
else
    OSCLASS = unix
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),Linux)
     OSNAME = linux
    endif
    ifeq ($(UNAME_S),Darwin)
        OSNAME = osx
    endif
endif
You can then do switches based upon the compiling OS. The biggest one was that I needed to output to a file. The problem with files that would write to both windows and unix is that the shell commands are different, so I need to address the differences in commands.
ifeq ($(OSCLASS),unix)
    FIXDIR = $1
    COMMANDCAT = cat
else
    FIXDIR = $(subst /,\,$1)
    COMMANDCAT = type
endif
Windows uses "type", whereas unix uses "cat". I then also fix the \ issue to go from the the unix / to the windows \ with the FIXDIR command. When I type "make test", the following will output the contents of info/chunk2.txt and append it to installer/test.inf.
test:
  $(COMMANDCAT) $(call FIXDIR,info/chunk2.txt >> installer/test.inf)
In unix, you will get: cat info/chunk2.txt >> installer/test.inf
In Windows, you get: type info\chunk2.txt >> installer\test.inf

Tuesday, October 15, 2013

Referencing datasheets in BIBTEX.

The CD4007 inverter pair is referenced as far back as papers from the early 1970's.  It's a great IC for teaching, but I really had to think of how to reference it using bibtex. I decided to go with the MISC tag.

@misc{CD4007,
    author={Texas Instruments},
    title={CD4007UB},
    url={http://www.ti.com/lit/ds/symlink/cd4007ub.pdf},
    note={original document from Harris Semiconductor},
    publisher={Texas Instruments},
    year={2012}
}

UPDATE:
Of course, once I decide on a method, I come up with a better method. Include:
\usepackage{url}
in your TEX document, and then you can have a prettier entry.
@misc{CD4007,
  author={Texas Instruments},
  title={CD4007UB},
  howpublished = "\url{http://www.ti.com/lit/ds/symlink/cd4007ub.pdf}",
  note={original document from Harris Semiconductor},
  publisher={Texas Instruments},
  year={2012}
}

Saturday, September 21, 2013

I lost my router...

I lost my router in the digital ether, so I pinged until I found my router. I used nmap to ping all addresses on my subnet.
nmap -v -sP 192.168.1.*

Sunday, July 21, 2013

Tuesday, July 16, 2013

Justice vs. idiots.

Idiot is a harsh word, but it's not difficult to not relate to someone and to feel superior to them. Here's an excerpt from http://observer.com/2013/07/fuming-protesters-shut-down-times-square-after-trayvon-martin-verdict/
Kerry McLean, 32, one of thousands who attended, said the protest was “empowering and cathartic.” Ms. McLean maintained that prosecutors had handled the trial badly. “I’m an attorney and it seemed like a circus to me,” she said. “It’s a travesty of justice. I’m really terrified of the message it has sent to the country and the world … The message that black people’s lives have no value in America.”
Here is my line-by-line breakdown of what is wrong with this complete quote.
Kerry McLean, 32, one of thousands who attended, said the protest was “empowering and cathartic.”
I will start with “empowering and cathartic”. A cathartic is a substance that accelerates defecation. catharsis would be to blow off steam, but considering the origin, I still think it would be misused in this case.

Ms. McLean maintained that prosecutors had handled the trial badly.
The handled the trial poorly, not badly. Also, one guesses in what way. Specifics would have helped the statement.

“I’m an attorney and it seemed like a circus to me,” she said.
I have found that most attorney's respect the system even if they disagree with it. I was also unable to find her bar number in the state of New York. I was curious which type of attorney she claimed to be.

“It’s a travesty of justice. I’m really terrified of the message it has sent to the country and the world … The message that black people’s lives have no value in America.”
I am not clear how a trial is a travesty of justice. The message that it sent to world was that a trial happened, which is unlike many other places. I tried to find a racial breakdown of acquittals based upon race of the jury, but I could not. I am not convinced that in modern America, race has much to do with acquittals. Considering that 1/2 of the jury was picked by the prosecution, I am sure the prosecution thought they had the best chance of conviction with their jury choices. If one thinks that the jury was imbalanced, where were the hispanic men?

I do not really care of the outcome of the trial of Zimmerman, but I am not one to second guess the jury. The quality of the observer article is really terrible, and it makes Ms. McClean look to be an idiot. If I were to get my information from the observer, I would probably not understand the facts, and I am sure that I would not agree with any position backed by Ms. McClean. Ms. McClean, the press made you look like an idiot, and I would keep that in mind when making decisions about others. Also, could someone please send Orla Ryan back to English class.

Saturday, July 13, 2013

Ubuntuのpopularity-contestはなんじゃそれ!

私はunixが好きけど、linuxがあまり。rootのメールにpopularity-contestからじゃまのことがいっぱいあった。 これすると:
 sudo dpkg-reconfigure popularity-contest  
メールが止まる。

Tuesday, July 9, 2013

wget with a certificate error (https://dl.dropboxusercontent.com)

I like to use wget when I get links in chat. I was getting a certificate error from dl.dropboxusercontent.com, which might just be from an old version of wget. The issue is solved with the --no-check-certificate flag.
wget --no-check-certificate https://dl.dropboxusercontent.com/u/XXXXXX

Wednesday, June 19, 2013

dumping postgres database via backup script

I came across an issue when trying to backup a database via pg_dump. The issue was that I needed to type the password. mysql will let me dump the database with the password on the command line, but postgresql does not and requires a prompt or a variable. You can use PGPASSWORD or .pgpass and I used the environmental variable.

In my BASH script, backup.sh, I have:
TIMEATSTART=$(date +%Y-%m-%d-%s) 
DIRECTORY_ARC=$USER_HOME/archive
FILENAME_DBBACKUP=db-$TIMEATSTART.gz

export PGPASSWORD=dbpassword
pg_dump -U dbuser database_name | gzip -c > $DIRECTORY_ARC/$FILENAME_DBBACKUP
The script makes a convenient backup of my database_name database to an archive/db-00000000000.gz file in my home directory.

Friday, June 14, 2013

Isn't public debt the debt of the public?

The art in Detroit cannot be sold because it is owned by the public. Considering that the debt is that of the public, it seems that something is logically wrong. Detroit is a city of "people", and those "people" voted for, or leveraged the use of money that caused the debt. Regardless of what the lawyers *think* the answer is, the correct answer is that the people owe on the debt.

Tuesday, June 4, 2013

When someone steals your keys, they might steal your car.

Summary: Someone breaks into your house and steals everything, including your keys, and then later steals the car. http://www.cbsatlanta.com/story/22434247/several-cars-damaged-before-chase-ends

sui: hello.
r: yo
sui: I'm meeting B. Wednesday for Frisbee!
r: oh nice
sui: totally miss playing frisbee with you
r: we should have done that more
sui: how are things?
r: things are alright did a pretty crazy camping trip over last weekend
got my truck stolen monday night
good stuff
sui:stolen?
r: heh yah
sui: you need to get out of ATL. it's a sign.
r: well when we got robbed they stole spare keys to my truck and D's bmw
sui: from your apartment?
r: we'd been being careful
parking our cars elsewhere
until we got them rekeyed
but my truck ended up at the apartment for like 4 hours one night
and it got jacked
sui: :/
r: they caught the guy though
sui: oh? that's good.
r: tried to pull him over bc he didn't have his lights on at 230am, he fled ended up hitting a residential speedbump, tubling over and totalling 5 parked cars on the side of the street, landed on the roof of a house got out and started running
i've got insurance to cover it
sui: ha, well, I think at least the insurance company will believe you
r: talked to insurance lady, and she was like, oh yah, i saw you on the news
http://www.cbsatlanta.com/story/22434247/several-cars-damaged-before-chase-ends
that video isn't worth watchign really
but the text is accurate
oh, so get this, atlanta police are not allowed to pursue
so if they try to pull you over
and you floor it
they're supposed to disengage
so running from the police is a totally viable option in atlanta
sui: wow
r: so this officer tried to pull guy over, he fled, officer stopped pursuit (i actually talked to the guy) and the fleeing guy got into an accident like a mile down the road
sui: wow, that guy seems to be a professional loser
r: yah...
we looked up his jail record
was never in jail for more than a month
wonder if we have like a 15 strikes and you're out policy in atl
sui: still a month is enough to make sure you don't have a real job
r: well
true
but not enough penalty on this shit
probably robs 10 places before getting caught
make a few thousands dollars, spend a month in jail
worth it
sui: Is the car being removed in the video yours?
r: dunno, that video keeps changing
i was in it for a while
but i was boring, tired, and annoyed they were interviewing me
so they took me off
all vehicles were towed at night
mine is kinda triangle shaped
sui: You need to work on your inherent sense of showman ship I guess. Still, what a few weeks for you

Saturday, June 1, 2013

Install SLIM for PHP in a single stroke...

I use SLIM for my web service for a personal project that I have been working on. It works great, but I forget the steps to install it because I revisit this project every 3 months or so. The BASH script below downloads the slim framework, writes the initial index.php file and sets up the .htaccess file. I run this from the root of my website directory.
 #!/bin/sh  
 #  
 #This installs the SLIM framework in a single command.  
 WEBSERVICE_ROOT=api  
 WEBSERVICE_FILE=index.php  
 echo "installing SLIM framework and dependencies in ./$WEBSERVICE_ROOT"  
 if [ -d $WEBSERVICE_ROOT ]  
 then  
      echo "api exists... slipping creation"  
 else  
      mkdir $WEBSERVICE_ROOT  
 fi  
 echo "{\"require\": {\"slim/slim\": \"2.*\"}}" > $WEBSERVICE_ROOT/composer.json  
 cd $WEBSERVICE_ROOT > /dev/null ;  
 curl -s https://getcomposer.org/installer | php -d detect_unicode=Off  
 php composer.phar install  
 echo "RewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^ $WEBSERVICE_FILE [QSA,L]" > .htaccess  
 if [ -f $WEBSERVICE_FILE ]  
 then  
   echo "$WEBSERVICE_FILE exists\n"  
 else  
      echo "<?php\nrequire 'vendor/autoload.php';\n" >> $WEBSERVICE_FILE  
      echo "\$app = new \Slim\Slim();\n" >> $WEBSERVICE_FILE  
      echo "\$app->get('/hello/:name', function (\$name) {\n" >> $WEBSERVICE_FILE  
   echo "echo \"Hello, \$name\";\n" >> $WEBSERVICE_FILE  
   echo "});\n" >> $WEBSERVICE_FILE  
      echo "\$app->run();?>\n" >> $WEBSERVICE_FILE  
 fi  
 echo "it should have worked, try http://127.0.0.1/api/hello/test and you should see \"Hello, test\""  

Friday, May 31, 2013

Semper Fidelis

I have been picking up Richard for years, as he hitch-hikes along HI 56. I am on his mailing list, and he sent this:

This past Monday, Memorial Day, I walked to the bus shelter in front of the Kapaa Neighborhood Center to hitch up north to Kilauea. It was after 6 PM, the sun setting fast in the west. An old man was seated at the bus shelter, apparently waiting for the bus. I recognized him as a man I rode with on the bus many months earlier. His name was Gordon, and he served in the US Marine Corps in World War Two.

As I approached the shelter, I asked Gordon if he was waiting for the bus north. He said he was. I broke the news to him the last bus had already left. Being a holiday, Memorial Day, the last northbound bus left Kapaa at 5:07 PM.

I said to him the only thing we can do is to hitch. I was going to Kilauea, and Gordon was going as far as Princeville. I started hitching, and he stood by my side. Us two guys, me 52 and he 80-something, waited one and a half hours for a ride. At least a couple of hundred cars must have passed us. Night fell, and the street lights came on. We were getting tired.

Finally, a pick up truck stopped and the younger man driving asked me where I was headed. By this time Gordon had sat down, and was just out of the light from the street light so the driver could see only me.

I told him I was headed to Kilauea, but that my friend over there was going all the way to Princeville, and there was no way I was going to leave him by himself waiting in the night here in Kapaa. I added that he is a veteran, and this is HIS day, Memorial Day.

The young man said he was not planning on going as far as Princeville, but for a veteran on Memorial Day, he would drive him anywhere he needed to go!

We strapped Gordon in the passenger seat, and I got situated in the back. The driver said he needed to make a brief stop to pick up some tools for his job tomorrow, and we would then continue on our way.

When we stopped in Anahola for the tools, we briefly talked story. I said that Gordon served our country during World War Two in the First Division of the US Marines in the Pacific. I added that my father also served in the US Marines in the Pacific during that war, but in the Third Division.

And the driver? Surprise, surprise, his father was a US Marine, and like my father, served in the Third Division, but in Vietnam many years later.

You see, US Marines have this tradition and duty of never leaving people behind the enemy lines, and apparently, lots of other places too.

We have a lot to be thankful for to all of our service men and women, including the US Marines. Service and duty and honor are not just things for war, but for life.

Those of us who hitch hike from time to time on Kauai have a saying that when you wait a long time for a ride, the one that comes eventually is a REALLY good one. This past Monday did not disappoint.

Richard

Monday, May 20, 2013

myTouch 4g, I hate you, and T-Mobile applications. I will send you all to binary heaven.

Somewhere along the way, the T-Mobile people forgot that a they are a phone company, that or Android forgot they are making it easy to make phones. I HATE the LG myTouch 4G. I have nothing installed but the base software, and it still is laggy. The solution (of course) is always to get the latest phone software. I decided to just remove all of the running software that wasn't important to phone functionality.

I created a step-by-step guide, but then I found an easier way. I had to find a windows machine though:
http://forum.xda-developers.com/showthread.php?t=803682 has a link to something called Super One Click. It rooted my LG phone in a single click. I then downloaded an application uninstaller. (Of couse, check what you are removing before you do it.)
I then removed things that I didn't want such as:
Tetris (default install, cannot remove... super)
Twitter
Facebook
T-mobile store

The TOS can go to binary hell with my crapware.

Monday, May 13, 2013

At least the NSF likes metric

The Metric Conversion Act of 1975, as amended, and Executive 
Order 12770 of 1991 encourage Federal agencies to use the 
Metric System (SI) in procurement, grants and other business
related activities. Proposers are encouraged to use the Metric 
System of weights and measures in proposals submitted to the 
Foundation. Grantees also are encouraged to use metric units 
in reports, publications and correspondence relating to 
proposals and awards. 
I am still waiting for road signs...

Saturday, May 11, 2013

This happened today:
http://www.freep.com/article/20130510/BUSINESS/305100093/McDonald-s-labor-protest-Detroit-wages
I respect the right of people to organize to improve their condition. Quotes like:
“They [McDonald’s] make $200 billion a year and they’re crying about 
giving minimum-wage workers $15 an hour?,” Rideout said in an interview.
make me wonder why reporters pick the quotes of ignorance.
McDonald's makes about $2 billion a quarter.
I question the value of minimum wage, rent control, or anything that gives an artificial value. I'm pretty sure that if NYC dumped rent control and minimum wage, everyone would make more money. I'll pay an extra $2 bucks for a papaya dog.