Monday, October 17, 2016

(SSAF) - Using Javascript with Google Sheets









Due to the beginning of the SSAF* project being very frustrating and the Google Sheets tutorials being unforgivably vague, I've decided to make a more in-depth post about a small script I wrote for my new job at Aqua Tots.


Warning: Google sheets uses bound scripts so you have to open the script from Google sheets by selecting 'Tools > Script editor'. Without doing that you won't be able see the results from your script.




The first thing we need to do is to confirm which sheet we're working on. While it's always going to be the one open, we need to confirm the link to it using a prompt. I used the following code:
function showPrompt() {
  Logger.log('(SSAF): Requesting spreadsheet link');
  var ui = SpreadsheetApp.getUi(); // Same variations.
  var result = ui.prompt(
      'Please enter the link to the schedule you would like sorted',
      '(Google Sheets links ONLY)',
      ui.ButtonSet.OK_CANCEL);
  // Process the user's response.
  var button = result.getSelectedButton();
  var text = result.getResponseText();
  if (button == ui.Button.OK && text != "") {
    // User clicked "OK".
    return text;
  } else {
    showPrompt();
  }
}

Which resulted in this:










Our schedules came in the following format:












But they needed to be converted into this format:















The Task:
The schedules needed a lot of work. The had to be organized by Staff /Time, the time column had to be converted to Standard format and moved to the first column and after the excess information was deleted, they needed to be indented by comparing class and staff.


The Function:
This is the function I used to sort my data and organize it as necessary. Hopefully this will help those of you struggling to integrate Google Sheets Scripts into your work.

function sortSchedule() {
   var link = showPrompt();
   var spreadsheet = SpreadsheetApp.openByUrl(link);
   var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
   var tableRange = "A2:I200"; // What to sort
   var range = sheet.getRange(tableRange);
   var lastCol = sheet.getLastColumn();
   var lastRow = sheet.getLastRow();
   Logger.log('(SSAF): Sorting ' + String(tableRange) + ' by name and time..');
   var r = sheet.getRange(2, 1, lastRow - 1, lastCol); // assumes headers in row 1
   r.sort([{ column: 5, ascending: true }, { column: 3, ascending: true}]);
   Logger.log('(SSAF): Sorting Complete!');
   Logger.log('(SSAF): Deleting extra data...');
   sheet.deleteColumn(9);
   sheet.deleteColumn(8);
   sheet.deleteColumn(7);
   sheet.deleteColumn(4);
   Logger.log('(SSAF): House keeping...'); 
     for (i = 2; i < 1000; i++) { 
       var range = sheet.getRange(i,3);
       var range2 = sheet.getRange(i+1,3);
       var range3 = sheet.getRange(i,4);
       var range4 = sheet.getRange(i+1,4);
       var data = range.getValue();
       var data2 = range2.getValue();
       var data3 = range3.getValue();
       var data4 = range4.getValue();
         if (data.localeCompare(data2) != 0 || data3.localeCompare(data4) != 0) {
           sheet.insertRowAfter(i);
           Logger.log('(SSAF): Adding indentation in row ' + i); 
           i++; // skips newly created row
         } else if (data.localeCompare("") == 0) { //empty field
           Logger.log('(SSAF): Indentation loop broken at row ' + i); 
           break;
         }
         }
 
   Logger.log('(SSAF): Moving time to Column One...');
   sheet.insertColumns(1, 1);
   var valuestocopy = sheet.getRange("E1:E1000");
   valuestocopy.copyValuesToRange(sheet, 1, 1, 1, 1000);
   sheet.deleteColumn(5); //deleting duplicate column
   Logger.log('(SSAF): Converting to standard time...'); //Column 5
   for (i = 2; i < 1000; i++) {
     var range = sheet.getRange(i,1).getValue();
     if (range == "" && sheet.getRange(i+1,1).getValue() == "") {
     Logger.log('(SSAF): It broke at ' + i);
     break;
     }
     var h = range.substr(0,2);
     var mm = range.substr(3);
     //var m = +mm;
     Logger.log('(SSAF): time broken down ' + range + ' to ' + h + ':' + mm);
     if (h > 12) {
       h=h-12;
       var val = h +':' + mm;
       sheet.getRange(i,1).setValue(val);
       Logger.log('(SSAF): Converting ' + range + ' to ' + r); //Column 5
       sheet.getRange(i,1).setNumberFormat("HH:mm");
    }
   }
   Logger.log('(SSAF): Schedule Complete.');
}

Wednesday, April 29, 2015

Working smarter, not harder

I'm currently interning at Loadmaster, an oil rig design company based in Houston. Yesterday I was tasked with writing a script to delete files in our scanned files directory that were over 45 days old.

Doesn't sound too complicated right? Well a quick google search revealed that many others have done similar projects.

Starting with a script from TechnicalKeeda as a base, I saved time by tweaking his script to my needs instead of starting from scratch. After adding a few printlns to readout more information, increasing the scan to target all file types in the directory, and changing the days required for deletion eligibility I had a working script in 15 minutes.

After that I wrote a simple batch file to run the .jar, set it up on our server's task scheduler and voilĂ . Here's my finished code, and an example of the readout.
.

/**
 *
 * deletes files in the scan directory
 */
import java.io.File;


public class ScanDelete {


  private String dirPath = "\\\\utility\\scans";

  public static void main(String[] args) {
    ScanDelete deleteFiles = new ScanDelete();
    deleteFiles.delete(45, "");
  }

  public void delete(long days, String fileExtension) {
 
    File folder = new File(dirPath);
 
    if (folder.exists()) {
   
      File[] listFiles = folder.listFiles();
   
      long eligibleForDeletion = System.currentTimeMillis()
        - (days * 24 * 60 * 60 * 1000L);
   
      for (File listFile : listFiles) {
        System.out.println("browsing...");    
        System.out.println("File Name: " + listFile.getName());
        System.out.println("Last modified: " + listFile.lastModified());
        System.out.println("Eligible for deletion: " + eligibleForDeletion);
        if (listFile.lastModified() < eligibleForDeletion) {
          System.out.println("Deleting File" );
          System.out.println("-----------------------------------" );
          listFile.delete();
        } else {
          System.out.println("File Spared" );
          System.out.println("-----------------------------------" );
        }
      }
    } else {
      System.out.println("Error: Folder Doesn't Exist!");
    }
  }

Here's the point: One of the most valuable skills you can learn as a programmer is resource management. Take advantage of the fact that there have been thousands before you trying to solve the same problems, and don't waste time writing small scripts that have already been written for you.

Tuesday, April 28, 2015

[Release] Juche! The North Korean RPG

"The interactive text based informative thriller Juche will keep you enthralled for minutes! Nay, tens of minutes! - I.G.N.

Info about the story and earlier posts showing the progression of Juche

Dislaimer: The game isn't fully complete. Inventories, quests, and shops haven't been finished. You're welcome to do anything you'd like with the source as long as I'm credited if you release anything.

Features: 
  • Amazing randomized fighting dialog
  • 6 maps, 10 enemies, tons of NPC's and Tons of Bugs  other features :)
  • Load & Save system
  • Admin command system
  • Unique NPC dialog (Including North Korean News NPC's and the tip giving Sensei of ultimate wisdom)
  • Minimalistic game art
  • Tray message system that drops alerts in the bottom right corner of screen when needed




Spoiler - Inside the source there's a list of admin commands you can use to cheat if you'd like. Enjoy!

Sunday, April 26, 2015

Pass Phrase Lite!

With the addition of grueling bug fixes, a tutorial, and the credits page, the free version of Pass Phrase is now complete! (Pass Phrase Lite)

Featuring 5 unique categories and hundreds of phrases P.P.L. sports a surprising amount of entertainment.

Unfortunately Pass Phrase Lite won't be released until Pass Phrase Plus has been finished.
Pass Phrase Plus will be available for $1 in the Windows Store, features 10 categories, anti-phrase repeat algorithms and over 800 phrases.

Tutorial & Credits page screenshots:



Sunday, March 15, 2015

Pass Phrase Rev. Two & Becoming Official!

Continuing towards my goal of being a published programmer I'm now a registered Windows Developer. As fancy as that sounds it just means I gave Windows $20 and a bunch of my personal information to gain the ability to publish apps in the store. WOO

Pass Phrase has received heavy updates as the release date closes in:
- New Simplified GUI
- Bug fixes and sound effects
- Refurbished graphics
- Hundreds of new phrases


As of right now I've been using Windows Visual Studio 2012 but I'm thinking of switching to Unity as it makes porting to other platforms incredibly easy and has better graphics handling.

Tuesday, February 17, 2015

More Windows Phone Development? Pass Phrase!

Don't worry folks, Juche is still in progress. However as the result of a recent chain of events I'm taking a semester off from school & I'm going to use this time to get a few more lucrative apps onto the Windows Marketplace.

Pass Phrase is a phrase game similar to Catch Phrase(But with way more innuendo!), where the person in possession of the phone has to make the others on their team guess the phrase using words other than those on the screen.

I've recently joined a development group called Final Turn Studios, and plan to release Pass Phrase at the end of the month under that name. Here's a few screenshots of the game as is (WIP)




Sunday, November 16, 2014

As promised I've done a little work on Juche WP edition and it's coming out surprisingly easy to port. Java and C# are highly similar in terms of syntax.

It's going to take a pretty significant amount of time to cover the extra features windows phone has to offer in terms of stacks and stackcollections, but I believe Juche WP will be here in a short matter of time.

Today I finished character creation and the stats pages to hold character information.

Thursday, October 30, 2014

Update after hiatus

It's been a while since I've posted and I'd just like to update you all on what's going on in my programming world. I've postponed my work on Juche unfortunately, and will be releasing the unfinished version of the game soon.

I've moved on to working on apps for Windows Phone. Programming in C# and XAML has been difficult to get used to but I think I have some interesting ideas that show promise. Currently I have three separate apps in development.

For those concerned about the future of Juche don't fret! Juche is currently being ported to Windows Phone where I think it will be better perceived than as a Java application on Windows.

Sunday, August 10, 2014

Juche Updates

It's been awhile since I've posted anything about Juche (Everyone's favorite North Korean RPG) but I'm back with a giant slew of updates. Since I have college coming up, it's questionable how much time I'll be able to spend on the game, however I assure you progress will be made.


  •  Loading now works
  •  Inventories work
  • Added shop/shopfactory classes & admin command to open shops
  • began shop implementation in maps
  • Shops now display in menu
  • Started adding /buy
  • Added menu for changing maps
  • Buying use items works
  • Ultimate abilities require 1/2 of your mana
  • Added JToaster library for more advanced dropmsgs
  • Combined all inventories into one
  • Straightened out battle narration
  • Added new NPCS
  • General cleanup
  • Added Sensei of Ultimate Wisdom (Gives tips)
  • Mana cost labeled on 4th skill
  • Admin mode now enables at level 25 
  • Added basic map navigation
  • Added other scenarios to /run
  • Mana is reset upon death
  •  new stuff: 6 skills/2 mobs/2 NPCS/Treetop Town/Trunk Arena
  •  Fixed map menu
  •  Fixed '[command] not recognized' msg after battle is over
  •  Named the last 4 maps

Friday, March 14, 2014

Juche Updates! (Now with 100% more pictures)

Juche now uses HTML for text/image formatting (Multi-Language swag?) and contains 4 new images with more to come.
 New login screen -

               New class selection page -


 Here's a list of the most recent updates: 
 - Added 16 more random phrases 
- HTML now used for formatting text in big box
 - Added Juche image to title
 - Added 12 skills
 - Each job now starts w/ different skills
 - Login page image shown after logout
 - Added 3 images to job selection
 - MP now displayed in stats
 - All characters start w/ 0 MP
 - Mana builds up as you battle
 - Equip/Quest inventory work 100% now


Wednesday, February 5, 2014

North Korean Dungeon Crawl - Where'd it go?

N.K.D.C. has been formally renamed to Juche 
  • Previous name was too long
  • It's no longer a dungeon crawling game
  • Juche is defined as the idea that the North Korean people are the masters of the countries development.
        I found the fact that this "political thesis" of Kim Il-Sung's even exists incredibly humorous, and immediately decided this would be the name for the game. Even though the situation in North Korea isn't anything to joke about I predict by creating a hilarious/slightly informative game could raise awareness about how bad it really is there.  

        More information on Kim Il-Sung's political theory Juche

         Aside from renaming the game, in the past two months the idea behind it has changed slightly to have laughs/actual information as the main selling points. I'm up to 17 classes with a few thousand lines. 

        Here's a list of the most recent updates:

* - Added /logout command for switching characters
 * - Cleaned up lots of narration
 * - Fixed loading bugs with Intel & North Korean Won
 * - Added arrays of Equip & Item for inventories
 * - Changes to the item & itemfactory classes
 * - Added UseItem class
 * - Added randomBattlePhrases for enemies and players
 * - Added /run
 * - Methods for updating inventories
 * - '/inv [quest/use/equip]' to toggle inventories
 * - Inventories tested and working!
 * - Cleaned up ItemFactory
 * - giveItem(String type, int id) added
 * - inventory display completely working (except quest)
 * - '/item [quest/use/equip] [id]' added for admins
 * - Minor narration changes
 * - giveItem method now updates inventory if it's the one selected
 * - Inventories now save (Except quest -.-)
 * - Quest inventory fixed!
 * - Partial equip inv loading
 * - Equip inv loading works! (Minor bug when loading adds a null instead of last item
 * - Fixed bug where null is loaded as last item
 * - UpdateInventory method reworked w/ switch statements & exception handling
 * - Saving and loading equip inventory works completely
 * - Reworked giveItem method using switch statements
 * - Started quest item saving
 * - Simplified equip loading
 * - Added new battle phrases
 * - Added gainExp method
 * - Characters/Enemies now have a speed stat
 * - NPC's now have dialog framework
 * - added /npc command & error checking for /battle
 * - Renamed characters class 'character'
 * - Renamed the game Juche
 * - Added the KCNAFactory(North korean news) + 12 quotes
 * - Added '/news' command
 * - Reworked battle, squished some bugs(Player & monster death weren't handled correctly)
 * - You no longer receive damage after killing something unless it has greater speed
 * - Speed stat now saves correctly
 * - Starting inventory saving rework
 * - Each character saved now has it's own folder
 * - Character data is split into multiple files
 * - Only directories can be selected when loading now
 * - Added new mob & 4 new skills
 * - Added commanding officer NPC
 * - Added dropPopUp method for NPC dialog
 * - You now recieve NKWon & experience from killing enemies
 * - Added the levelUp method (you gain stats upon leveling & exp works as it should)
 * - Max exp now displays corectly in stats
 * - Fixed bug w/ gaining negative gold
 * - Fixed a bug preventing leveling up
 * - Exp now resets correctly after leveling

As you can read in the above list, most of the stuff has been behind the scenes work, and I'm just starting to get into the visual/game play side of things. So I only have one screen to share with you containing any new features, here's an example of NPC dialog.




Wednesday, December 4, 2013

NK DungeonCrawler

The most recent project I've adopted is a post apocalyptic text based game about North Korea in which North Korea turned out to be the incredible power they pretend to be in modern day.

Unlike traditional text based games I built an interface for the game in swing, however it still has the traditional feel.

Currently I have about 10 classes going and 1500 lines, but yet to implement maps. Here's my dev. log.
* Development started - December 26th
 * Updates:
 * - Established basic layout
 * - Created player class & stats
 * - Tweaked GIU settings
 * - Created starting stats for classes
 * - Added message for if a message is submitted and no commands are done
 * - Added names
 * - When creating a character it now correctly assigns job
 * - Text field is cleared after hitting enter
 * - Enter key now works instead of button
 * - Fixed spacing in stats
 * - Added narration class
 * - Added currency(North Korean Won)
 * - Added MaxHP & MaxMP
 * - Characters class is now extended by player/npc/enemy
 * - Added skills to Player & Enemy (4 skills spots avaliable)
 * - Added SkillFactory & CharacterFactory classes (SkillFactory gets skills from id's & CharacterFactory is responsible for names/shit)
 * - Coded CharacterFactory getChar(id) method for getting NPC's/Enemies
 * - Added Skill & Skillfactory classes along w/ test NPCs/enemys/skills
 * - Added Battle class & got the basic battle system implemented
 * - Fished Battle basics :) You can fight now! (4 different skills)
 * - Improved look of battle text
 * - Added skill descriptions and made it easier to add skills
 * - Skill descriptions added to battle narration
 * - Added Admin commands /heal & /battle [mobid]
 * - Reworked enemy creation, much easier
 * - Saving now works
 * - You can now load saved characters :)
 * - Privatized some variables that needed it
 * - Added Item/equip/itemfactory classes




Tuesday, December 3, 2013

Twitter Client update!

I've been continually updating the client and here's the current look. Far from done(There are few bugs Ex. Profile tab doesn't work), but it's on hold for another project that I've started with a few friends. 

As you can see I've opted for bigger profile images, there are multiple feeds to choose from, and there are more search options including a pull down menu for what feed you'd like to search. 

Tuesday, October 1, 2013

Twitter Client 1.0 Sneak peak!

Hey all! Schools been getting in the way but I've still poured an unhealthy amount of time into my Twitter client.  I'm still not ready to release it, but I've added Avis, cleaned up a lot of code, and squashed a few bugs. 

Here's a overview of the app. 

 Copy the link into your browser

 Then replace the link in the client with the 7 digit code.
 After that you're in, and your feed should have updated. (Including pictures!)
 You can also tweet or refresh your feed when you'd like to using the top menu or hot-keys.
 Lets test the tweeting function.
 Success! :)


This project was made using the libraries Twitter4j and jToaster.

The most difficult part of the project thus far was finding adequate examples for the libraries I've been using.
This app is far from done! Even though it's already the most extensive swing app I've created (~800 lines of code) I'm still theory crafting the end game. Hopefully it's useful as an example of how to use swing with libraries.

Thanks.       - Redeemer34

Saturday, September 14, 2013

Quick update after a long hiatus..

News:
I've been working on a Twitter client. (runs on Twitter4j) Not sure if anyone's going to use it but if you're trying to learn how to interact w/ imported libraries this is a great example. Right now I'm putting the finishing touches on the basic functions of the client before diving into anything really interesting.

Considering re-uploading most of the projects on here to reduce the amount of messy code, but I haven't quite decided.


XSPro:
P.S. I've put XSPro on hold until Kevin releases the next revision of Moople, I figure it'll be easier to port what I've already done later & not have to worry about it.

                                                   - Redeemer34

Wednesday, March 20, 2013

Updates on programming and XsPro

I've gotten a little distracted from my current main project, (XsPro MapleStory V83) however never fear, because I am still updating it.


XsPro:
I'm almost finished adding weapons leveling up, after that I have to fix a few more bugs and make sure every class can use the starting area and whatnot and it'll be set for release.


Other Projects:
I've taken up learning another few languages on Code Acadamy to try and expand my programming horizons, and I enjoy the site so much that I might even write lessons for it!

I've also started thinking of an interesting twitter app using the Ruby to Twitter API, I'll give more info on that later in the month.



Sunday, March 3, 2013

[XsPro]Updates! Auto-Medal system and Auto-Job system!


Its been a while since I've talked about any of my developments with XsPro so here's a little sneak preview of whats been going on.



Auto Job System:
  • Automatically advances your job when available (Ex. Aran/Cygnus/3rd and 4th job)
  • There's now a command to job advance instead of having to talk to a NPC or whatever
  • '@jobadvance [job]' also displays available job options if you mistype/choose a non-available job







Auto-Medal System

  • Aran Combo medals
  • Job advancement medals
  • Level 200 Medals
  • Clean Language medal
  • Be my Friend medal
  • Automatically puts the medal in your inventory when you earn it
  • If you don't have enough space in your EQUIP inventory, it saves your most recent medal earn so you can drop something and use a command to access it later



Also I fixed the Aran Combo bug where combos were only counted for people with fourth job.


Tuesday, February 26, 2013

[Release] MySQL Data Runner

Features:
  • Auto-Fill for some queries in case your knowledge of MySQL is iffy
  • Command line interface
  • Six Commands
  • Importing .SQL files works
  • Faster for small data interactions
  • Less of a pain than MySQL WorkBench
  • Open source
Download: http://www.mediafire.com/download.php?9p4rep98danc3ea




Note: May be less successful in running large scripts.

Monday, February 25, 2013

Quick MySQL runner

I've been working on a custom MySQL Query runner to replace the bloated MySQL 5.2 workbench using the java to MySQL API.

The idea is that instead of having to open up a huge memory sucking program to run a few lines of SQL, you can just open up this bad boy and run your code.

Here's a few screens. Not sure about release time. Lemme know if you're interested.

Planned features:

  • Open/Run SQL scripts saved on your computer
  • Run custom SQL script straight from the program
  • Easy command line based interface
  • Doesn't let you past first screen if it can't connect to DB







Sunday, February 24, 2013

XsPro V83 is BACK!

I've gotten quite a few messages regarding my V83 Maplestory Repack, 'XsPro', and wondering whether it would ever be available again. Now I can proudly say that it will be back. It's going to take a while to get all of the features of the old pack back, but I've already been working on it for a little while, and its going well.


Here's a screenshot preview and my update log so far. :)





  • Started with clean MoopleDev rev. 118
  • Removed all .SVN folders
  • Renamed everything
  • CreateServer.bat and LaunchServer.bat now read serverName off of serverConstants.java
  • Moople police --> Maple Police
  • Added doReborn() and dropServerMessage() in MapleCharacter
  • Added some more customization availiable in ServerConstants
  • Changed dropMessage to blue O_O
  • Removed GMchat being in gmcommands 2x
  • !exprate - now an admin command
  • Added dropoverhead method 
Stay tuned for more info!