ThinkOrSwim: Line Tracks Current Price

Often I find it helpful to have a continuous current price line in my chart to easily follow the current price of a security within ThinkOrSwim. One of the ways to add this script is to create a custom Study (see below).

# Track current price w/ constant price line.
#
input lineLength = 1000;
def lastBar = !IsNaN(close) && IsNaN(close[-1]);
def lastClose = if lastBar then close else lastClose[1];

plot data = if IsNaN(close[-lineLength - 1]) then lastClose[-lineLength] else Double.NaN;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetDefaultColor(Color.GRAY);

Candle chart prior to enabling script

Candle chart after enabling script:

Create a custom Study to add script above:

  1. Select Tools -> thinkScript
  2. At the upper-right hand side of the screen, Select “+” -> Study
  3. Name the study, for example: “LineAtPrice”
  4. Copy and paste script above.

Once added, activate within your Chart by adding the Study.

Posted in General-Tech | Leave a comment

PC Engines – The Best Economical Firewall Hardware: apu4d4 APU.4D4 4GB/120GB

Just received from Switzerland (PC Engines) a backup firewall ready to receive PfSense — apu4d4  APU.4D4 4GB/120GB SSD. This unit will provide high availability once coupled with the existing unit. Quick specs:

CPU: AMD Embedded G series GX-412TC, 1 GHz quad Jaguar core with 64 bit and

AES-NI support, 32K data + 32K instruction cache per core, shared 2MB L2 cache.

DRAM: 4 GB DDR3-1333 DRAM

Storage: Boot from SD card (internal sdhci controller), external USB or m-SATA

SSD. 1 SATA + power connector. mSATA is shared with miniPCI express.

12V DC, about 6 to 12W depending on CPU load. Jack = 2.5 mm, center positive

Connectivity: 4 Gigabit Ethernet channels (Intel i211AT)

I/O: DB9 serial port, 2 USB 3.0 external + 2 USB 2.0 internal, three front
panel LEDs, pushbutton

Expansion: 3 miniPCI express (J13 USB or mSATA, apu4*4: with SIM; J14 USB only,
with SIM; J15: full miniPCI express, but no SIM, intended for wifi).

GPIO header, optional I2C bus, COM2 (3.3V RXD / TXD).

Board size: 6 x 6″ (152.4 x 152.4 mm) – same as apu1d, alix2d13 and wrap1e.

Firmware: coreboot

Cooling: Conductive cooling from the CPU to the enclosure using a 3 mm alu heat spreader (included).

Conducted a memory test to ensure all was well!

In case you are wondering how to connect to the unit from your MacBook w/ OSX you will need one of these: USB to DB9F serial cable

# screen /dev/tty.SLAB_USBtoUART 115200

Note: You need to be root for access to /dev/tty.SLAB_USBtoUART.

Posted in *Nix, General-Tech, Security | Leave a comment

Python-3.11: Where is pip?

Just spent the last five minutes trying to locate pip3 as if it was installed by default — after installing python3.11. Sure, pip3 was there for versions < 3.11, but not pip for 3.11. I continued with no avail trying to find pip:

which pip
which pip3
pkg search pip3.11
ls /usr/local/bin/*pip*

Finally, reached out to the Internet and came upon the solution provided by mfurseman: Can’t run pip on python 3.11

On FreeBSD after installing python3.11, to get pip3.11 was as simple as:

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

Note: This will install pip locally in your home folder. This was the message I received after pip was installed:

WARNING: The scripts pip, pip3 and pip3.11 are installed in '/home/icon/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.3.1 wheel-0.38.4

Update your path to reference the new location of pip. Since I use ZSH, I edited: ~/.zshrc and ensured my path was updated accordingly:

export PATH=$HOME/.local/bin:$HOME/bin:/usr/local/bin:$PATH
Posted in Programming, Python | Leave a comment

PKTD: Running Full Node on FreeBSD

For kicks, compiled and ran #pktd, the daemon that helps verify transactions within the #PKT network. Fairly straight forward. However, you may run into a build failure, for which a submitted a pull request that was recently merged, during your build on FreeBSD. My pull request was merged in develop branch, but should be in master by the time you ready this. Otherwise, use the develop branch prior for your build:

Install Git & GoLang

$ sudo pkg install -y lang/go devel/git

Clone pktd Repo & Build

$ git clone https://github.com/pkt-cash/pktd
$ cd pktd
$ ./do

Build Failure?

In case you encounter the following build failure

$ ./do
Building pktd
go build -o ./bin/pktd -trimpath -ldflags=-X github.com/pkt-cash/pktd/pktconfig/version.appBuild=pktd-v1.4.0-2-g12f53b23 .
... output truncated ...
go: downloading gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
# github.com/pkt-cash/pktd/database/ffldb
database/ffldb/disk_posix.go:25:21: invalid operation: stat.Bavail * uint64(stat.Bsize) (mismatched types int64 and uint64)
panic: exe(go, [build -o ./bin/pktd -trimpath -ldflags=-X github.com/pkt-cash/pktd/pktconfig/version.appBuild=pktd-v1.4.0-2-g12f53b23 .]) -> exit status 2

goroutine 1 [running]:
main.die(...)
        /some/usershome/othercrypto/pkt/pktd/contrib/build/build.go:18
main.exe(0x5, {0x4e7e16, 0x2}, {0xc00011a2a0, 0x6, 0x6})
        /some/usershome/othercrypto/pkt/pktd/contrib/build/build.go:55 +0x67f
main.build({0x4e7fba, 0x4}, {0x4e7d86, 0x1}, 0xc000093f50)
        /some/usershome/othercrypto/pkt/pktd/contrib/build/build.go:75 +0x3b6
main.main()
        /some/usershome/othercrypto/pkt/pktd/contrib/build/build.go:127 +0x2d3
exit status 2

Simply edit the file: database/ffldb/disk_posix.go and change the line from:

return stat.Bavail * uint64(stat.Bsize), nil

to

return uint64(stat.Bavail) * uint64(stat.Bsize), nil

We converted our left hand side operand from uint64 to uint64 to satisfy our build error: “mismatched types int64 and uint64”. Afterwards build should complete and ./bin/pktd should launch without issue:

$ ./bin/pktd 
1635118388 [INF] config.go:676 Creating a .cookie file
1635118388 [INF] pktd.go:64 Version 1.4.0-5129c0ea-dirty
1635118388 [WRN] log.go:547 THIS IS A DEVELOPMENT VERSION, THINGS MAY BREAK
1635118388 [INF] pktd.go:308 Loading block database from '/some/user/.pktd/data/pkt/blocks_ffldb'
1635118389 [INF] pktd.go:328 Block database loaded

1635118389 [WRN] server.go:2914 Can't listen on :64764: listen tcp6 :64764: socket: address family not supported by protocol family
1635118389 [INF] server.go:2631 Committed filter index is enabled

1635118389 [INF] chainio.go:1158 Loading block index...
Posted in General-Tech | Leave a comment

Cardano: [FBSD] Update FreeBSD Relays to v_6 (alonzo V2 (1.30.1))

September 11, 2021 brought the Alonzo hard fork allowing the implementation of smart contracts on Cardano mainnet in order to enable a host of new use cases for decentralized applications (DApps). Stake pools are encouraged to update all nodes to Alonzo v2 (1.30.1).

Below is a quick way using Ansible to update Cardano relay nodes running on FreeBSD installed using the Ansible role: cnode_stakepool. The advantage of using this Ansible role is there is very little to no manual work required. Simply point to your relay nodes and let Ansible do all the work.

gLiveView after update

Take System Snapshot

Prior to updating the system and upgrading the relay nodes take a snapshot of your system prior to proceeding.

Stop cardano daemon on 1st relay node

We stop the daemon on the 1st relay node prior to launching our ansible-playbook. Login to relay node #1 and stop the node with below command:

  • # /opt/etc/rc.d/cnode_relay stop

Update System

  • pkg update
  • pkg upgrade -y

Run Ansible on 1st relay node first

Prior to launching the playbook run. Edit: vars/main.yml and change tagged_version to 1.30.1. Example:

---
# vars file 
basename: cnode
type: relay
cnode_type: "{{ basename }}_{{ type }}"

tagged_version: 1.30.1

cluster: mainnet

...output truncated...

Launch Playbook

Feel free to checkout and clone the cnode_stakepool ansible role from my github repo.

  • $ ansible-playbook -i inventories/cardano/fbsd-stake-pool.ini playbooks/cnode_relay_install.yml –limit ‘relays[0]’ –diff

On completion output should indicate

  • ansible-playbook -i inventories/cardano/fbsd-stake-pool.ini playbooks/cnode_relay_install.yml --limit 'relays[0]' --diff
  • Repeat for the number of relays you have.

    Use the following link to update your producers if you are using Linux: UPDATE CARDANO NODE to 1.30.1 – FOR CNTOOLS users

    Posted in General-Tech | Leave a comment

    Cardano: Now fully decentralized (D=0)!

    Today, March 31st 2021 marks the day, the Cardano network is now fully decentralized. As stated by the team at IOHK:

    Cardano is a proof-of-stake blockchain platform, founded on peer-reviewed research and delivered through evidence-based software development processes, by a team of world-leading researchers and engineers. From this technocratic core, Cardano exists to steadily redistribute power to the edges – to a community of individuals. And to empower them as an enabling force for change and progress.

    IOHK

    Stake pool operators like myself are in full control of the blockchain. The more of us that exist the faster and more nimble the Cardano network becomes. Glad to be part of this event and looking forward for more to come.

    Posted in General-Tech | Leave a comment

    Cryptocurrency: Cardano (ADA) — Setting up a PoS Node

    screen-shot-2021-03-12-at-7.21.56-pmLooks like I went down this rabbit hole that is Cardano, so much so that I am in the process of setting up a stake pool. A stake pool for the purpose of helping decentralize the blockchain network. As of this writing the cardano blockchain is 90% decentralized. The other 10% are block producer-nodes operated by the Cardano Foundation.Looks like I went down this rabbit hole that is Cardano, so much so that I am in the process of setting up a stake pool. A stake pool for the purpose of helping decentralize the blockchain network. As of this writing the cardano blockchain is 90% decentralized. The other 10% are block producer-nodes operated by the Cardano Foundation.

    Posted in General-Tech | Leave a comment

    [Google Cloud] IAM – Service Accounts

    Google Cloud Service Accounts:

    Service accounts are accounts used for the sole purpose of running your application. Some may also refer to this as the application processing identifier. Google uses the term service account. To identify a service account an email identifier is typically used. The email address used for a service account is an Identity & Access Management (IAM) account used as an identifier for reference purposes.

    Here we use the command-line to create a new service account called: gdev1sa to represent the first development service account for our project. There is a tight coupling between the command-line console and web interface. Almost instantaneously when the service account is created via command-line it is also reflected in the Web GUI. For example as can be seen below our Services Accounts page only contains the default Compute Engine service account:

    Screen Shot 2017-10-01 at 12.20.47 PM.png

    Likewise, we see the same output via command-line:

    ~ gcloud iam service-accounts list
    
    
    NAME EMAIL
    Compute Engine default service account; 637540065038-compute@developer.gserviceaccount.com
    

    Create Service Account via Command-Line

    ~ gcloud iam service-accounts create gdev1sa --display-name "Primary Development Service Account"
    
    Created service account [gdev1sa].
    

    Likewise, after refreshing the Web Console we see the account creation reflected here as well (2nd row):

    Screen Shot 2017-10-01 at 12.49.22 PM.png

    By default when created each service account will not have its key pair created.

    Service Account Keys

    Service account keys are private / public key pairs unique to each service account. By default when a service account is created the service account has its own internal key pair used for service-to-service authentication within GCP that are also managed by GCP. With the default internal keys you do not have to worry about management tasks such as key rotation or misplacing them. The keys are exclusively managed within GCP. However, external keys can be created and downloaded after they are generated within GCP. As of this writing there are two types of external private keys: json and the older p12  format.

    Create External Service Account Keys

    Via command line… Note you need to specify the internal email identifier we spoke of earlier to reference the service account when create the private key. How will GCP know which private key to create? Good question! By default all private keys are created using the .json format unless .p12 is otherwise specified via the option: –key-file-type=p12

    gcloud iam service-accounts keys create gdev1sa.json --iam-account=gdev1sa@project-good.iam.gserviceaccount.com
    created key [0821b6693b9c974b466474c51a974a1405f530c5] of type [json] as [gdev1sa.json] for [gdev1sa@project-good.iam.gserviceaccount.com]
    

     

    Posted in Google | Leave a comment

    [Swift] Extra argument ‘completion’ in call

    xcodeIn iOS 8 SDK Development, the use of a closure to act on a response from the user when we ask them to use their twitter account produces the following compilation error:

    Extra argument 'completion' in call
    

    The error is misleading because there is no “extra argument” in the call to “accountStore.requestAccessToAccountsWithType“. Below the problem is on line #6. See it?

    func reloadTweets() {
      let accountStore = ACAccountStore()
      let twitterAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
      
      accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil, completion:
        { (granted: Bool, error: NSError) -> Void in
          if (!granted) {
            println("account access not granted")
          } else {
            println("account access granted")
          }
        })
    }
    

    It does not stand out and I only figured it out because I recognized the closure for ‘completion:‘ is a type-alias to ‘ACAccountStoreRequestAccessCompletionHandler‘, which is documented as:

    typealias ACAccountStoreRequestAccessCompletionHandler = (Bool, NSError!) -> Void
    

    Adding the exclamation mark (!) after NSError to force unwrap solve the error. The confusing part to me is NSError is not an optional type (at least it is not clear in the definition of NSError and I am not too familiar with Objective-C). Why does it need to be forced unwrapped? Would appreciate any further explanation on this from anyone watching. 🙂

    Posted in Programming, Swift | Leave a comment

    [Swift] How to Pass By Reference via The Use of ‘inout’

    xcode  When defining a function the keyword ‘inout‘ is used in front of the variable name to denote an in-out parameter, which sets up the function as a kind of “pass-by-reference” function. Note, this is not real pass-by-reference as the variable is still copied within the function, manipulated and the passed back out. 

    What is an in-out parameter?
    An in-out parameter is a parameter that has the keyword ‘inout‘ at the start of its definition. This parameter is like an alias or reference to the variable in the calling function. Changes made to the inout variable inside the function are retained when the function call completes. For example, we define our function as such:

    Look at this function that swaps the values of two variables: swapCEO

    func swapCEO(inout person: String, inout withPerson: String) {...}
    

    Where the keyword ‘inout‘ denotes the parameter ‘person‘ and parameter withPerson of type ‘String‘ will have a value passed in and then passed out. The value passed out may or may not be changed, but should it be changed this will be perfectly acceptable.

    When the swapCEO function is called, each of its two arguments must have prefixed an ampersand (&), like so:

    swapCEO(&amp;amp;amp;appleCEO, &amp;amp;amp;microsoftCEO)
    

    By prefixing an ampersand (&) to our arguments we are indicating the variables passed in may be modified.

    Note: It is an error to use the keyword ‘inout‘ in a function definition but not prefix an ampersand(&) to an argument when that function is called.

    Let’s See This in Action

    We declare two variables to serve as place holders for the names of well known CEO’s. Time Cook the current CEO of Apple is stored in the variable appleCEO and Satya Nadella the current CEO of Microsoft is stored in the variable microsoftCEO.

    var appleCEO = &amp;amp;quot;Tim Cook&amp;amp;quot;
    var microsoftCEO = &amp;amp;quot;Satya Nadella&amp;amp;quot;
    

    As previously mentioned, to swap the values of our two variables we simple call swapCEO and prefix the ampersand (&) to each of variables.

    swapCEO(&amp;amp;amp;appleCEO, &amp;amp;amp;microsoftCEO)
    

    We can now print the variables and see if this worked.

    See the full execution from a Playground Session Below

    playground

    playground

    This same concept may be used on any type, not just String, when you need a function to modify its variable parameters.

    Posted in Devel | Leave a comment