Posts
Setup Terraform
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi aws configure sso &REM Enter the access key (AWS_ACCESS_KEY_ID), secret (AWS_SECRET_ACCESS_KEY), default region (AWS_DEFAULT_REGION) Get-ExecutionPolicy &REM If this isn't Unrestricted, "Set-ExecutionPolicy AllSigned" / "Set-ExecutionPolicy Bypass -Scope Process" Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) choco install aws-vault https://www.terraform.io/downloads https://releases.hashicorp.com/terraform/1.1.4/terraform_1.1.4_windows_amd64.zip
Posts
Mariadb Column Store
On Debian Linux 10,
apt update apt-cache search mariadb apt install -y mariadb-server root@debian:~# mariadb Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 36 Server version: 10.3.34-MariaDB-0+deb10u1 Debian 10 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.
Posts
Java Modules
Features in Java since 1.8:
https://ondro.inginea.eu/index.php/new-features-in-java-versions-since-java-8/
https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features
//In module-info.java at root of packages module my.myModule { //requires their.theirMofile -- Compile time and run time dependency //requires static ... -- Compile time dependency //requires transitive ... //exports com.my.package.name //exports com.my.package.name to com.other.package //uses ... //provides MyInterface with MyInterfaceImpl } //See more at https://www.baeldung.com/java-9-modularity
Posts
Android Spinner Widget
spinner = findViewById(R.id.spinner); String[] strArrSpinner = { "A", "B", "C" }; ArrayAdapter spinnerAdapter = new ArrayAdapter( this, android.R.layout.simple_spinner_item, strArrSpinner ); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); Button btnShowSpinnerSelected = findViewById(R.id.btnShowSpinnerSelected); btnShowSpinnerSelected.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), spinner.getSelectedItem().toString(), Toast.LENGTH_LONG).show(); } });
Posts
Spring Data Repo Interface
//PersonRepository.java package com.pockettheories; import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface PersonRepository extends MongoRepository<Person, String> { //the 2nd generic is data type of ID List<Person> findPersonsByFirstName(String firstName); @Query("{'firstName': :#{#fname}}") List<Person> findPersonByDisplayName(@Param("fname") String displayName); @Query("{'firstName': ?0}") List<Person> findPersonByDisplayName2(String displayName); @Aggregation(pipeline = { "{'$match': {'firstName': ?0}}", "{'$sort': {'firstName': 1}}" }) List<Person> findPersonByGoodName(String name); } //PersonService.java package com.pockettheories; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @Service public class PersonService { @Autowired public PersonRepository repository; public List<Person> findPersonsByFirstName(String firstName) { return repository.
Posts
Android Widget Variable Generator
Declaring variables for Android widgets is very repetitive. This Ruby script generates the code that can be copy-pasted into onCreate. Use Android Studio (Cmd+Option+F) to refactor the variables into member variables.
#androidLayoutToVars.rb require 'nokogiri' class LayoutProcessor < Nokogiri::XML::SAX::Document def start_document end def start_element(name, attrs=[]) attrs = attrs.to_h if attrs.key?('android:id') varName = attrs['android:id'][5..] declaration = "#{name} #{varName} = findViewById(R.id.#{varName});" puts declaration end end def end_element(name) end def end_document end end parser = Nokogiri::XML::SAX::Parser.
Posts
Return Ibject From Javascript Lambda
Let’s say we have an array of strings like this:
vals1 = ["A", "B", "C", "D"] We want to run the array through a map function to get the structure:
[ { _id: 'A' }, { _id: 'B' }, { _id: 'C' } ] …and so we try writing a map function like this:
vals2 = vals1.map(e => {_id: e}) //Returns: [ undefined, undefined, undefined ] It seems odd at first, but Javascript interprets the squiggly brackets as a function, so the executing code looks something like this:
Posts
Recycler View in Android
This post is an example of the RecyclerView in Android.
package com.pockettheories.todoone; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { RecyclerView rvu; Button btnAdd; EditText txtNewItem; List<String> strValues = new ArrayList<String>(); //List.of("A", "B", "C", "D", "E"); RecyclerView.Adapter adapt; @Override protected void onCreate(Bundle savedInstanceState) { super.
Posts
HarperDB API
HarperDB provides a REST API at the endpoint localhost:9925. Commands are sent in JSON format as an HTTP request body.
Creating a schema and a table, and inserting data:
{operation: "create_schema", schema: "hr"} {operation: "create_table", schema: "hr", table: "employee", hash_attribute: "empno"} {operation: "insert", schema: "hr", table: "employee", records: [{empno: 1, name: "Nitin"}]} Fetching data
{operation: "search_by_hash", "schema": "hr", table: "employee", hash_values: [1], get_attributes: ["name"]} {operation: "search_by_hash", "schema": "hr", table: "employee", hash_values: [1], get_attributes: ["*"]} {operation: "search_by_value", schema: "hr", table: "employee", search_attribute: "name", search_value: "Nit*", get_attributes: ["*"]} {operation: "sql", sql: "UPDATE hr.
Posts
Rails SQL Bind
String concatenation is almost never the right answer when passing a parameter to an SQL query. For example, this is a bad idea:
sqltxt = "SELECT * FROM dept WHERE dname = '#{params['dname']}' " @results = ActiveRecord::Base.connection.execute sqltxt Replace it with a parameterized query like this:
sqltxt = "SELECT * FROM dept WHERE dname = ?" @results = (ActiveRecord::Base.connection.raw_connection.prepare sqltxt).execute params['dname'] Adding some more code around the logic…
sqltxt = "SELECT * FROM dept WHERE dname = ?