Wednesday, February 14, 2024

I bought a dashcam from Temu for $6.31 January 2024, and here is sample footage that includes three scenes: daytime, dusk, and daytime.

Product benefits

  • Easy mounting with suction cup
  • Easy power with 12V cigarette plug adapter
  • Battery lasts a few moments after car turns off
  • MicroSD card included
  • Cheap price

Problems

  • Cheap quality
  • Terrible video quality (despite product description)
  • Narrow field of view (despite product description)

Notes

  • It was a weird choice for it record in .avi instead of .mp4 container.
  • The product was discontinued on Temu.

Model (box): Y320
Manufacturer (box): shenzhen Hengxin Weiye Digital Co., LTD
Product title (Temu):
Dash Camera For Cars With 32G Memory Cards Wide Angle Full 1080P Driving Record...

Below is the product menu (PDF on Temu):
Intelligent voice reminder, built-in multinational voice pronunciation, no need to worry about language barriers 1080P highdefinition night vision, even in the weak light environment, can also shoot clearly Loop recording, no missing seconds, segmented storage, automatic monitoring of sto rage space, when the memory is full, automatically delete the earliest recorded video and save the new video Builtin gravity sensor, when a sudden brake or collision is sensed, the current video is instantly locked to prevent overwriting important files during loop recording Supported languages: English, French, German, Russian, Japanese, etc.

Wednesday, July 12, 2023

Timestamp precision in Snowflake

Timestamps in Snowflake have precisions 0 to 9 with a default of 9, which is a nanosecond, but the Snowflake documentation is not clear on precisions 0 to 8.

Storage difference

I did an empircal test by creating tables. Each table had one million rows and one column with random timestamps. The values have an original precison of one nanosecond, and I used random values because otherwise Snowflake would compress down any number of rows with the same values to a few KB.

create or replace table zzz_timestamp9 as
select dateadd(nanosecond, uniform(1,3e17, random()), current_timestamp())::timestamp(9) as time1
from TABLE(GENERATOR(ROWCOUNT => 1e6))
;
create or replace table zzz_timestamp0 as
select dateadd(nanosecond, uniform(1,3e17, random()), current_timestamp())::timestamp(0) as time1
from TABLE(GENERATOR(ROWCOUNT => 1e6))
;

The storage difference for 1 million rows was 3.5MB vs 7.0MB.

Precision difference

Again, I generated random rows and then copied the value into columns with varied precisions.

select
    dateadd(nanosecond, uniform(1,3e17, random()), current_timestamp())::timestamp(9) as "precision 9",
    "precision 9"::timestamp(3) as "precision 3",
    "precision 9"::timestamp(2) as "precision 2",
    "precision 9"::timestamp(1) as "precision 1",
    "precision 9"::timestamp(0) as "precision 0",
    datediff(ms, "precision 3", "precision 9") as "Precisions 9 vs 3 in milliseconds", /* alwayz zero */
    datediff(second, "precision 0", "precision 9") as "Precisions 9 vs 0 in seconds" /* alwayz zero */
from TABLE(GENERATOR(ROWCOUNT => 10))

Precision 0 is 1 second, precision 1 is 100 ms, precision 2 is 10 ms, precision 3 is 1 ms, etc.

Saturday, May 20, 2023

openwrt ssh connection refused

Symptom

Normal connection attempt
$ ssh root@192.168.1.1
Connection to 192.168.1.1 closed.
End of log with verbose ssh
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/z/.ssh/id_ed25519 ED25519 SHA256:XX//XX/XX agent
debug1: Server accepts key: /home/z/.ssh/id_ed25519 ED25519 SHA256:XX//XX/XX agent
Authenticated to 192.168.1.1 ([192.168.1.1]:22) using "publickey".
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: Sending environment.
debug1: channel 0: setting env LANG = "en_US.UTF-8"
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to 192.168.1.1 closed.
Transferred: sent 2488, received 1012 bytes, in 0.0 seconds
Bytes per second: sent 346691.3, received 141017.5
debug1: Exit status 1
System log snippet in OpenWRT's luci interface
Sat May 20 23:02:33 2023 authpriv.notice dropbear[7690]: Pubkey auth succeeded for 'root' with ssh-ed25519 key SHA256:XX//XX/XX from 192.168.1.X:X
Sat May 20 23:02:33 2023 authpriv.info dropbear[7691]: Exit (root) from <192.168.1.X:X>: Child failed
Sat May 20 23:02:33 2023 authpriv.info dropbear[7690]: Exit (root) from <192.168.1.X:X>: Disconnect received

Background

A few weeks ago, I installed OpenWRT 22.03.3 on my Belkin RT3200. SSH and everything else was working fine until I updated it to OpenWRT 22.03.5, and then immedietly SSH refused to connect.

Solution

I read a GitHub conversation about a similar problem. In their case, zsh was missing, and I remembered that earlier I installed Bash. I reinstalled it via LuCI, and then SSH worked again.

Sunday, December 4, 2022

Enable 5G standalone (NR SA) on Samsung Galaxy A13

I bought two Samsung Galaxy A13 5G phones from Google Fi for $100 each on promo, but by default, they connected in NR NSA (non-standalone) mode, which requires an LTE anchor. Performance was okay in NR NSA except in few geographic areas where LTE bands 2, 4, and 66 had high packet loss of 50-100% because of low signal or interference.

With a little effort, Samsung Galaxy phones can be put into NR SA ("pure 5G") mode. The process is similar to the Galaxy S22 (see guide by peacey8 at end), but there are a few differences. In particular, the A13 uses a Mediatek MT6769V/CU Helio G80 chipset instead of the Qualcomm SM8450 Snapdragon 8 Gen 1 on the Galaxy S22, so the serivce menus differ.

Pros and cons

Pros

  • Lower latency and packet loss (sometimes/generally).
  • Latest generation of cell network technology.

Cons

  • Requires compatiable carrier. (In the USA, it's only T-Mobile and their MVNOs such as Google Fi and Mint Mobile.)
  • Requires somewhat modern phone.
  • Requires compatible cell tower. (In my area, 5G coverage is excellent.)
  • T-Mobile does not support voice yet on NR SA mode. If band locking is set to NR SA, phone calls will not work. If band locking allows LTE and NR NSA, it will automatically fall back to LTE/NR NSA.
  • Allowing NR SA mode requires some initial technical set up.
  • Without band locking, the phone may often favor NR NSA over NR SA, even when NR SA has better network performance.
  • Band locking settings (optional) gets lost after phone reboot.
  • Set up varies by chipset.

Guide

This guide assumes your phone has the XAA (unlocked) CSC profile. If not, see peacey8's guide at the end. If you have TMB profile, then NR SA mode should already work. Once you have XAA, proceed here.

  1. On the phone, enable developer mode: go to settings (gear) - About Phone - Software Information - tap seven times on build.
  2. In phone settings (Gear) - Developer Options - enable USB debugging.
  3. Install Samsung USB driver for Windows. (Sorry, you need a laptop or desktop.)
  4. Launch the SamFW FRP tool on Windows.
  5. Connect phone by USB cable to Windows machine.
  6. In SamFW, enable secret code for Verizon. (You do not need to use Verizon as a carrier.)
  7. SamFW should stop at "Waiting for DIAG."
  8. In Samsung Phone app (with the blue icon), call *#0808#. (It does not work for me in the Google Phone app with the green icon.) After hitting the last pound (and before hitting the call button), the USB settings menu should appear.
  9. If you have two options, then you did not enable USB debugging. Start over.
  10. Tap DM+ACM+ADB and tap OK. (The Galaxy S22 has way more USB debugging options, by the way.)
  11. SamFW should stop at "Disabling DIAG."
  12. Then call *#0808#, and switch back to MTP.
  13. Phone can be disconnected from USB, if you wish.
  14. In the Samsung phone, app use the dialer code *#27663368378#.
  15. UE SETTING AND INFO -SETTING - PROTOCOL- NR -ALLOW LIST- ALLOW LIST OFF
  16. Three dots (top right), back
  17. NR5G SA / NSA mode control - SA / NSA enable
  18. Reboot phone.

Once it is working, you can disable the USB debugging and developer options menu on the phone, and you can uninstall SamFW.

Troubleshooting

Unlike the Galaxy S22, the *#2263# menu will not look any different on the A13. Even when NR SA is active, this service menu looks the same. It doesn't distinguish NR NSA and NR SA, so to confirm you are on SA, some options are:

  • Dial *#0011#. Pick relevant SIM. Check fourth line "Serving PLMN." If you see Nr5G, it's SA. If LTE, then it's not.
  • Use app such as CellMapper, Network Cell Info Lite, or NetMonster. They will all show the network type on the main page.

If you are still on LTE or NR NSA, some options:

  • Check your carrier supports NR SA. Right now, T-Mobile does, while Verizon and AT&T do not.
  • Check you have a 5G SIM and a 5G plan.
  • Turn off wifi. (It may use LTE only for power savings.)
  • Move closer to the tower.
  • Move to another tower.
  • Reset the connection like this: phone settings (gear) - Connections - Mobile networks - LTE/3G/2G. Wait a moment and set back to 5G/LTE/3G/2G. On our two A13, S22, and S22+ phones, we often need to reset the connection like this, and airplane mode does not seem to help. Otherwise, it may stick to LTE when NR NSA or NR SA are available.
  • Disable LTE like this: in the Samsung Phone app (green app icon), call *#2263#. Tap the relevant SIM. Tap CLEAR ALL BANDS. Tap "BLOCK SET BY AP," so the asterisk goes away. Tap NR menu to enter it. Select NR ALL. Go back to main. Apply selection. This may reset after rebooting the phone.
  • Alternate way to force NR: in Google Phone app (blue app icon), call *#*#4636#*#*- Phone Information - Set preferred network Type - NR only.

I tested this two Galaxy A13 phones running Android 12 with T-Mobile via Google FI. In case you want to join Google Fi, here's a referral code to get a $20 credit when you join: 2RD2V5.

On the Galaxy S22, voice calls do not work with NR SA: incoming calls go straight to voicemail, and outgoing calls stop a moment after dialing because VoNR apprently is not enabled. It is probably the same on VoNR.

Thank you much to the NR SA for Galaxy S22 guide from peacey8 and molexs's comment about the SCR01 hotspot.

Thursday, February 3, 2022

Generate random names and addresses from SAS

For testing data processing systems (e.g., CRM, record linkage), you may need to generate fake people. SAS makes it uniquely easy to generate an unlimited count of fake US residents because it comes with a data set of US zip codes, which include the city and state name.

The system uses four data sets: first names, last names, street names, and US zip codes. Initials are randomly generated from letters. The street addresses probably do not exist in the given zip codes.

You could extend this by:

  • Add street directions (i.e., N, S, E, W)
  • Add street post type (e.g., Dr., Ct.)
  • Add units (e.g., Apt B, Ste 101)
  • Add post office boxes and private mail boxes
  • Spell out the middle name
  • Add name prefix (e.g., Dr., Mr.)
  • Add name suffix (e.g., Jr., Sr.)

Thursday, December 10, 2020

Estimating birth date from age

This code demonstrates an algorithm for estimating birth date from age. We cannot know the exact birth date, but we can get close: the maximum error is half a year, and the typical error is one quarter of a year.


/* The %age macro was taken from the Internet---maybe from here http://support.sas.com/kb/24/808.html ? */
%macro age(date,birth);
floor ((intck('month',&birth,&date) - (day(&date) < day(&birth))) / 12)
%mend age;

/*
Generate 10000 fake people with random birth dates and random perspective days
on which their age was measured. Then, calculate age from that perspective date.
In reality, there is some seasonality to births (e.g., more births in July), but 
here we assume each day of the year has an equal distribution of births.
*/
data person;
	format birth_date submit_date yymmdd10.;
	do i = 1 to 10000;
		birth_date = %randbetween(19000,20500);
		submit_date = birth_date + %randbetween(0,100*365);
		age = %age(submit_date, birth_date);
		output;
	end;
	drop i;
%runquit;

/* Work in reverse from age to estimated birth date. */
data reverse;
	set person;
	format birth_date_min birth_date_max yymmdd10.;
	birth_date_min = intnx('years', submit_date, -1 * (age+1), 's') - 1;
	birth_date_max = intnx('years',birth_date_min,1,'s') + 1;

    /* check range of estimates for errors */
	min_error = (birth_date > birth_date_min);
	max_error = (birth_date < birth_date_max);

    /* estimate birth date as the middle of the range */
	birth_date_avg = mean(birth_date_min, birth_date_max);
    
    /* calculate variance */
	abs_days_error = abs(birth_date - birth_date_avg);
%runquit;

/* Both errors should always be zero. */
proc freq data=reverse;
	table min_error max_error;
quit;

/* Error of estimates range from 0 to 183.5 with a median of 92 and average of 91.*/
proc means data=reverse n nmiss min median mean max;
	var abs_days_error;
quit;

/* Distribution of errors is uniform */
proc sgplot data=reverse;
	histogram abs_days_error;
quit;

Tested with SAS 9.4M6

Monday, July 22, 2019

How to connect from Linux to BleemSync 1.1

After installing BleemSync 1.1 on my PlayStation Classic, I could connect to the BleemSync UI from Windows but not from Linux (Ubuntu 19.04). Google Chrome reported "unable to connect," and ping to 169.254.215.100 reported a network error.

dmesg showed that Linux identified the device, and RNDIS networking started

[23945.137399] usb 1-3: new high-speed USB device number 31 using xhci_hcd
[23945.286069] usb 1-3: New USB device found, idVendor=04e8, idProduct=6863, bcdDevice=ff.ff
[23945.286075] usb 1-3: New USB device strings: Mfr=3, Product=4, SerialNumber=5
[23945.286079] usb 1-3: Product: classic
[23945.286082] usb 1-3: Manufacturer: BleemSync
[23945.290633] rndis_host 1-3:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-3, RNDIS device, 8a:04:6f:1c:f9:72
[23945.291271] cdc_acm 1-3:1.2: ttyACM0: USB ACM device
[23945.339113] rndis_host 1-3:1.0 enp0s20f0u3: renamed from usb0

However, ifconfig showed it did not have an IPv4 address. This indicates a DHCP failure.

$ ifconfig enp0s20f0u3
enp0s20f0u3: flags=4163  mtu 1500
        inet6 fe80::adf4:a447:4b1d:f96c  prefixlen 64  scopeid 0x20
        ether 72:b7:b8:ae:c8:00  txqueuelen 1000  (Ethernet)
        RX packets 8  bytes 536 (536.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 81  bytes 12347 (12.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I bypassed DHCP by manual IP configuration.

sudo route add -net 169.254.215.0 netmask 255.255.255.0 metric 1024 dev enp0s20f0u3
sudo ifconfig enp0s20f0u3 169.254.215.2
ping 169.254.215.100

Now Google Chrome, ping, and even telnet worked.

Note: your interface name may vary. Mine was enp0s20f0u3.

This solution worked until rebooting Ubuntu. Later I found a permanent solution: BleemSync 1.0 on Ubuntu thanks to DDFoster96.

I bought a dashcam from Temu for $6.31 January 2024, and here is sample footage that includes three scenes: daytime, dusk, and daytime. ...