Saturday, August 29, 2020

Pushing and Pulling Commits between Visual Studio Code and Github.com

CREATE NEW REPO, empty, from the github server side: (leave out README.md)
When presented with new URL, copy the URL
Locally, mkdir myrepofolder, cd myrepofolder, and create README.md (case-sensitive)

git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/mygithubusername/myrepofolder.git
git push -u origin master

PUSH COMMITS TO GITHUB
git add README.md
git commit -m "ongoing edits"
[master 6c0e1bd] ongoing edits
1 file changed, 1 insertion(+), 5 deletions(-)
git push -u origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 328 bytes | 328.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/myusername/myrepofolder.git
383e4f7..6c0e1bd master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'


PULL COMMITS FROM GITHUB
git pull origin master

TIPS FOR USING THE VIM EDITOR
i edit and use arrow keys to navigate
esc finish editing
:w!enter save changes
:q!enter quit VIM EDITOR
# comment-out line character

Mac Terminal Update

MacOS changed the default TERMINAL shell from bash to zsh with the Catalina release (10.15.x). (echo $SHELL tells you what shell terminal is using). This means customizing your terminal prompt from .bash_profile no longer works. The solution is to create a .zshrc file in your home (username) directory and insert the following line: (dot files are hidden by default on mac, view in finder by hitting command-shift-dot while in the folder with hidden files)

PROMPT='%F{green}%1~ $ %f'

This customizes the prompt to include the current directory name (%1~), to use the $ character as the prompt with a space on either side, and to be green (%F{colorselection}%f)

The customization automatically works with VISUAL STUDIO CODE (which I now am using in place of Sublime Text as a text editor / code editor, because it includes a Terminal window).

Sunday, June 21, 2015

Ethereum CLI - Go implementation - geth (frontier) installation on Mac

First a few words about the evolution of Ethereum. Alethzero is the current GUI (client) from the cpp (C++) implementation. Mist is the current GUI (client app) from the Go implementation. It used to be called Ethereal. As of right now, the clients do not appear to be ready for prime time. If you want to have access to the blockchain, you have to have a CLI (command line interface). There is a cpp CLI, and there is the Go CLI geth (AKA Frontier). Using geth, you can run commands from your Unix Terminal $ prompt directly, or invoke the JS console and have access to commands from the > prompt. $geth starts the former, and $control-C exits. $geth console starts the latter, and >exit exits. Installation Instructions for geth and Mist. 1. Install Homebrew (http://brew.sh has command-line instructions, install from Terminal) (as brew is installed, you may be prompted to install x-code) 2. $brew tap ethereal/ethereum 3. $brew install ethereal --with-gui Using geth You have to do a few things to make geth work. I like working from the geth console. $geth console >admin.peers() >admin.newAccount() >eth.coinbase >eth.getBalance(eth.coinbase) The peer function must return a list of peers. If it doesn't, something is seriously wrong, like your internet connection is down, or your clock is not synchronized with the network clock. I once started mining without checking this first, and I ended up with a balance of thousands of ethers, but it was invalid because it was mining from block one with no peers. The other three console commands create an ethereum address, assigns it to coinbase if it is the first one, and shows you the balance in the address. The eth functions are a shortcut to the web3.eth API. At this point geth should automatically download the blockchain. This takes many hours. The blocks come in in batches of 256 blocks. You can see your progress by looking at the last block# that came in and comparing it to the current block in existence on etherchain.org. There is a long delay of silence in the console before the blocks start coming in, but usually it tells you that it is about to synchronize with the blockchain before it starts. After that is done, you can mine. >admin.miner.start(2) That tells it to mine with 2 threads. Some CPU's allow 4 threads. As far as I know, right now geth does not support GPU mining directly yet. Before starting mining, the proof of work "DAG" must be downloaded. Starting the miner starts the download. It takes about 15 minutes, and you get a progress status report on this as it comes in. I believe the DAG makes the POW relatively ASIC resistant, at least for now. >admin.hashrate() tells you where you stand, after the DAG is 100% downloaded, and the blockchain is synchronized. Or, instead of mining, you can set up the RPC server using >admin.startRPC(). >admin.progress() also gives useful info.

Sunday, December 28, 2014

Passing multiple parameters from AppleScript to Node.js Server

Most previous solutions to moving data from AppleScript to a server on the same machine involve MAMP/PHP and passing the parameters via a GET or POST to the URL. It works, but it is slow and awkward. I have found another solution. The concept is to use Applescript to put all of the parameters into a single JSON string, and put the string on the system clipboard. Then open the URL. If your server is set up with node.js with express.js framework, you can retrieve the JSON data, and pass all the parameters to the jade node template engine. With very little code, you can use the data for display, encryption, messaging, or storage in SQL. Tricks to help make this happen: Enclose the JSON elements (both the keys and the values) in tildes instead of quotes before passing to clipboard. (Also clean out all the illegal characters like newlines. I like having them at the other end, so I substitute triple-dashes for every newline and change it back on the other end.) In node.js, FIRST, replace the tildes with double quotes, and change the newline placeholders to \n. THEN use json = JSON.parse(jsonstr); to turn it from a JSON string to a JSON object. THEN use res.render(‘Jadefilename’, json); in the routes/index.js file. Inside the jade template, the jsons value can be called simply with #{key} To pass multiple jsons at once, use res.render('Jadefilename', {item1:json1, item2:json2}; etc, and inside jade the values correspond to #{item1.key} An important afterthought: these passed json objects received by jade are available in the regular jade template but INACCESSIBLE inside javascript functions nested in jade. The correction to this problem is add the following one line to the top of your nested javascript function to make the json object into a local variable: var local_json =!{JSON.stringify(imported_json)}; Now you can call the values from local_json, instead of imported_json, (item1 in the example above) inside the javascript that is nested inside the jade template. While on the subject of node.js, here is a refresher on how to get started with express. first time: install node from nodejs.org then “sudo npm install” the following: -g express generator -g nodemon mysql crypto-js copy-paste returning - check install, versions: node -v npm -v express -V (yes that one is capitalized) nodemon -v And here is what you really need to know: create an express project: express projectname-version start application with nodemon: cd projectname-version nodemon bin/www start application with debug: DEBUG=my-application ./bin/www IDE: Sublime Text 2, Terminal, Safari, Applescript Editor, Remote Desktop Connection

Saturday, June 21, 2014

Setting up Java Eclipse IDE on Windows 7 and JRE

After installing and uninstalling both Eclipse and JRE (Java runtime environment) several times on a Windows 7 64-bit machine, I finally have a sequence I can recommend. In my case, I had to have my testing environment in eclipse be compatible with the runtime environment on a Windows Server 2008 R2 without access to the JRE on that machine. This meant it had to be JRE 1.6 and 32 bit. (Even though the default installation on the Windows 7 machine was JRE 1.7 and 64 bit). 1. Uninstall all the implementations of java from the control panel uninstall utility. 2. You can't uninstall the Eclipse IDE, you can just delete it. 3. Install the JRE (1.6.0.6) and verify it is working by going to the program file (x86) folder and/or the windows\syswow64 folder (these are where 32-bit programs reside on 64-bit machines) and from the command line java -version. You can also verify it's installed by going into control panel ->java->java->Application runtime settings->view. 4. Install the IDE but be sure to download the 32-bit version. I downloaded it to a mac, put it in dropbox, let it sync for about 20 minutes on the target machine, and then copied the whole folder (after renaming it eclipse_32_bit) from dropbox to desktop on Windows 7. You can still have eclipse_64_bit on the same machine, in another folder. 5. Launch the IDE, select a default workspace folder, open the workbench, and immediately go to Window->Preferences->Java->Installed JREs->Execution Evironments. 6. Click on JavaSE-1.6 and here is where the magic is. In the compatible JREs pane the freshly installed jre1.6.0.06 is there, and not only that (it is there for other execution environments) it says "perfect match". 7. Click the compatible jre1.6.0.06 checkbox. This should give you the correct JRE for testing your application within Eclipse.

Sunday, April 6, 2014

Eclipse ADT (Build v22.2.1 for Mac OS) Pointers

When you create a new app from scratch (file->new->Android Application Project) and select the defaults, it automatically opens the java file (from the src folder) for editing, and the main xml file (from the res->layout folder) for editing. The xml file has two panes, text and graphical layout. Start with the graphical layout to drag and drop objects like fields and buttons onto your UI. Then edit the xml text and the java file to handle events with the objects. The YouTube tutorials on this, called "Android: project 1(v1)", up to (v6), by "Lecture Snippets" are very efficient and provide simple java code for this. The YouTube tutorial "Android Basic SQLite Database" by "profgustin" gives some basic SQLite code, which I have enhanced below to interact with a field from Lecture Snippets. The main thing not to forget is: although SQLite is "built-in" to the Android Developer Tools SDK, the new app cannot use the classes until they are imported in the java code AND attached to the build path. I found that typing SQLiteDatabase in the java code, and either hovering over it or double clicking on it brought up a dialog box that allowed me to both make the import statement in the code, and add the android.jar file as a Source Attachment in the Java Build Path (this is otherwise found by right-clicking the project file in the navigator pane-> Properties->Java Build Class->Android. I use the Cursor class to manipulate SQL data, so I also had to import android.database.Cursor; as well. I think import android.database.*; may also work. package com.example.foo2; import android.os.Bundle; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.view.*; import android.widget.*; public class MainActivity extends Activity { Button btn1; EditText etxt1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null); db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (field1 VARCHAR, field2 VARCHAR, field3 VARCHAR);"); db.execSQL("INSERT INTO MyTable VALUES('red','green','blue');"); Cursor c = db.rawQuery("SELECT field1 FROM MyTable", null); c.moveToFirst(); final String MyString = c.getString(c.getColumnIndex("field1")); db.close(); btn1=(Button)findViewById(R.id.button1); etxt1=(EditText)findViewById(R.id.editText1); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { etxt1.setText(MyString); } }); }

Saturday, December 14, 2013

ADT - Android Developer Tools - with Eclipse: Starters.

Here is a refresher on how to start a new project by copying an old one. In my case, I keep my projects on a Mac in Documents->Android->Workspace folder. That is my default folder for new projects. For this example I have a same, working project that compiles with no errors and runs on a Kindle via USB cable called "Notepad". You must be sure to open the Eclipse IDE correctly. I select Eclipse from Spotlight, but I have more than one installation. It has to be the ADT version. Once Eclipse is open, in the Navigator bar on the left one has to be sure the project being copied is "open" (either double click it, or ctrl-click->open project. Can close projects the same way, for faster loading of Eclipse). 1. Highlight open project -> cmd-c -> unhighlight -> cmd-v -> select name for the project. 2. ctrl-click project -> Android Tools -> Rename Application Package -> follow instructions. 3. Navigate to res->values->strings.xml->app.name to rename the app for the device. This creates a new project in the default folder, opens it in Eclipse, allows you to independently name the folder it is in, the application package, and the app on the target device. All of 3 of these names can be the same or be named independently. This allows one to revert to a project in a skeleton form, but has all the right settings, jars, and so on to allow error-free compilation and installation to the desired target device. To run, click the run button. To stop from running, go to the app page on the target device, hold your finger on the app icon to delete the app.