Monday, December 7, 2020

L2TP with Raspberry PI

Make sure the debug dump option is not used -- otherwise it will crash pppd.

/etc/ppp/options.l2tpd.client:


ipcp-accept-local

ipcp-accept-remote

refuse-eap

require-mschap-v2

noauth

mtu 1200

mru 1200

noipdefault

debug

defaultroute

usepeerdns

connect-delay 5000

name <username>

password <password>


/etc/ipsec.conf:


# ipsec.conf - strongSwan IPsec configuration file


# basic configuration


config setup

  # strictcrlpolicy=yes

  # uniqueids = no


# Add connections here.


# Sample VPN connections


conn %default

  ikelifetime=60m

  keylife=20m

  rekeymargin=3m

  keyingtries=1

  keyexchange=ikev1

  authby=secret

  ike=3des-sha1-modp1024!

  esp=3des-sha1!


conn myvpn

  keyexchange=ikev1

  left=%defaultroute

  auto=add

  authby=secret

  type=transport

  leftprotoport=17/1701

  rightprotoport=17/1701

  right=<IP address>

Thursday, March 26, 2020

Overscan monitor issues on HP 2509m

If you're noticing that you can't see the title bar and the bottom status bar, it's because the overscan settings need to be changed.

The instructions at the bottom of this blog post (https://ishan.co/external-monitor-underscan) worked for me:

 1. Make a backup of the current file:
 2. cp /var/db/.com.apple.iokit.graphics /tmp/.com.apple.iokit.graphics.backup
 3. With the “troubled” monitor connected, open Display Preferences, and change its settings. For example, I changed the rotation.
 4. Run the “diff” command to see what had changed in that file after you made the changes:

56a57,58
>   framebuffer-rotation
>   0
58c60
<   10000
---
>   9000

5. I derived 9000 from -10% less overscan, which works great!

The process is automated in this Bashmatic script! (https://github.com/pioneerworks/lib-bash/blob/master/lib/osx.sh#L41-L53)

Sunday, February 3, 2019

How I fixed a 17-year old HP scanner...

Fixed! I've had this HP LaserJet 3330 multi-function printer (3300mfp) since 2002, but one day it started making a clicking/grinding noise, which is a common issue in this printer. The key to fixing is taking apart the entire unit and cleaning the mirrors and lens on the scanner unit (see YouTube video)


What exactly is the issue? It turns out that the scanner during startup tries to find its home position at the edge. When the scanner lid is closed, the light will reflect down onto mirrors. There are 5 of these mirrors that eventually bounce the light towards a CCD sensor:

I had done this mirror cleaning a few years ago and it worked miraculously. However, this time around the problem started happening again but the mirrors seemed fairly clean. What I didn't realize and what the repair videos don't mention is that I also had to clean the lens.  You can clean the front easily but to get to the back of the lens, the board on the back of the scanner unit has to be removed. This article seems to suggest you can get access to the scanner unit without taking the entire printer apart, but if you need access to the board, there are really no shortcuts.


There were small glue residue on the screws, so I had to use a power screwdriver to remove them. You can see in the pictures how the lens is fogged up:


After cleaning with a Q-Tip and alcohol, this lens starts to become cleaner:


Upon putting everything back, I noticed the printer continued to show "warming up bulb" on startup. I think the problem could be traced to some of the residue from the glue when I removed the board causing issues on the board. I managed to scrape away the residue and use painter's tape to lift it off the board. 

To verify whether the circuit board that I had just removed was at issue, I also started using a voltmeter and testing the ground and power (Vcc) pins of each of the integrated chips on the board while the board was plugged in while leaving the gray scanner lid off. There are a few commodity parts, which includes the CCD sensor (UPD8861), an inverter (74vhc04), a Schmitt trigger, and a voltage regulator that outputs 12 volts.

It suddenly worked! And I didn't have to buy a new unit (51000104-0000 on Ebay).

Note: I did try to reset the printer's memory by holding down "*" and # on power-up.  But I stopped doing it after it didn't seem to help.

Other notes from the HP forum here.

Wednesday, November 21, 2018

Seeing ints instead of booleans from your memcache?

The latest PyLibMc has changed the way in which booleans are stored from strings to integers to avoid conflicts in which python-memcached manages them. The end result? If you were noticing that your cache is returning ints instead of True/False, this change in PyLibMC cached this issue!

https://github.com/lericson/pylibmc/issues/242

If you have API responses that are returning invalid values, you'll need to wrap the value in bool() to fix the issue!

Friday, November 24, 2017

Testing SSL on Erlang

ssl:start().
{ok, ListenSocket} = ssl:listen(8443, [{certfile, "server.pem"}, {keyfile, "server.key"}, {cacertfile, "server.chain"}, {reuseaddr, true}]).
{ok, Socket} = ssl:transport_accept(ListenSocket).
ok = ssl:ssl_accept(Socket).

Wednesday, March 9, 2016

Project Fi and B010 error codes


  • If you purchase a Google phone, make sure to buy it under the @gmail.com account that will activate the Fi service.  Otherwise, you will end up seeing B010 error codes when trying to activate!

    Otherwise, you will have to call Project Fi specialists and have the "asset id" transferred to the account owner that intends to activate service.  You need to have both parties on the phone to have this info transferred.  This lesson took 3 weeks to resolve after calling multiple times to their 24x7 support line!
  • Google Fi leverages the Google Voice infrastructure.  You have to decide upfront whether to port your existing Google Voice line or port your cell phone.  If you decide to test out Project Fi and wish to bring your own phone line over later, you must cancel the service and then order another SIM card.  Google currently has no way of letting you to try before committing.  


Thursday, April 23, 2015

Redcarpet

Redcarpet is a Ruby library for rendering markup language.   When updating a CodePath Wiki guide entry, which hosts these documents outside of GitHub, I noticed that the list items not to be including the image tags that I used in a separate line:

1. Inside the Google Play Store for your project, navigate to `Settings` -> `API Access`:

    <img src="http://imgur.com/0n7ihzM.png"/>

I would see:

<ol>
<li>Inside the Google Play Store for your project, navigate to...
</ol>

<p><img src='http://imgur.com/0n7ihzM.png'/&amp></p&amp>


But if I added 4 spaces to the image tag, the problem went away:

1. Inside the Google Play Store for your project, navigate to `Settings` -> `API Access`:

        <img src="http://imgur.com/0n7ihzM.png"/>
 
Turns out that a change was made in Redcarpet v3.1.0 that changes the parsing behavior so that at least 4 spaces are needed for the line to be considered part of the list item.  It also is very likely that GitHub must be using an older version of this library, since this problem doesn't appear on native GitHub Wiki pages.   If GitHub should ever decide to upgrade to this new library, they're likely to cause their Wiki collection to experience similar problems!

https://github.com/vmg/redcarpet/commit/b7d5e017385a8ae35a594ff9535d31bd081ce973

Monday, March 30, 2015

Brain surgery on a Nexus 5

A few days ago, my Nexus 5's display started turning colors.  A few minutes later, it stopped showing.

Rather than buying a new phone, I decided to see if it could be repaired with some surgery.  I bought a $70 replacement frame and digitizer and $5 in tools.  The video walkthrough seemed pretty straightforward right?



Little did I realize that I would have to move everything from the old unit to the new frame, including the two power buttons, the battery (the video warns about puncturing and inhaling the toxic chemicals), the front and back camera, antenna board, and the main CPU.   Not to mention the microphone pieces (watch very carefully the video about the additional part you must bring over too!)

You don't really need a dryer gun since the adhesive is pretty easy to remove.  The tricky part is getting the shell of the phone off -- they are connected with small snap-ins that can break if you're not careful. Once I managed to get a few of these snap-ins loose, I could use a flathead screwdriver to remove the rest around the edge.  The video also shows what you need to do if you don't have a replacement digitizer like the part that I ordered -- I skipped over that step.

3 hours later, after making sure every single part was moved over (again, check the microphone and the part that sits below it!) it's working great. At first I thought I had failed because only the screen turned on. The battery had apparently drained so upon plugging in, I was able to see the Android Lollipop screen.  My only major issue is that I may have damaged on of the two antenna ports on the board, but the phone operates fine with just a single one plugged into it.  I plan to solder the other cable onto the socket just in case.

Nonetheless, I hope I just saved myself $400 on a new Nexus phone!


Wednesday, February 11, 2015

Want to verify your W2 submission form?

A few weeks ago, I got a letter from the SSA notifying me that my electronic employer W2 submission was wrong. I knew it was related to the electronic file format generated by Wave, but wasn't sure what was happening. After waiting 2 weeks for a response from their support team, I decided to write a small script to figure out what was happening...

https://gist.github.com/rogerhu/bef3c9cba4005f346002

It confirmed to me that their generation was off by a factor of 10.  It was fixed later by the company without notifying customers about the issue.

Also, it turns out that the SSA provides a Java applet called AccuWage that allows third-party companies to verify that their file format generation is correct...

Saturday, February 7, 2015

How to get IntelliJ to recompile Android resource files

If you want to use IntelliJ to build your Android projects, make sure that the SDK versions in your Project SDK matches that in your Preferences->Module SDK. Otherwise, you may find that you have to click Rebuild Project each time you make changes to the XML version!

Monday, December 29, 2014

User location API's in Android

With the new framework with Google Play, you have to update your code now to use this unified GoogleApiClient.Builder() approach:

http://android-developers.blogspot.com/2014/02/new-client-api-model-in-google-play.html

There are now actually two ways to get location from Android. The 2nd way attempts to unify the various LocationProviders (GPS, network, other applications, etc.) into one API:

http://www.rahuljiresal.com/2014/02/user-location-on-android/

Friday, December 12, 2014

How to map multiple keyboards to the same OSX mappings

If you're trying to use Karabiner to support key remappings for multiple devices, you can take advantage of the templating syntax:

You can have your product and vendor ID definitions here:



You define your main key remappings here:

Wednesday, December 10, 2014

Using padding in ListViews

Don't forget to use scrollbarStyle and clipToPadding according to this post!

https://plus.google.com/+AndroidDevelopers/posts/LpAA7q4jw9M

The difference between gravity and layout_gravity -- one deals with the parent (layout_), the other deals with the child.

http://stackoverflow.com/questions/13965883/what-is-exact-difference-between-gravity-and-layout-gravity

Monday, November 24, 2014

How Nginx computes the ETag header for files.

Curious how the ETag: header is generated in Nginx?

Turns out it's a combination of the last modified time and the content length:
etag->value.len = ngx_sprintf(etag->value.data, "\"%xT-%xO\"",
                                  r->headers_out.last_modified_time,
                                  r->headers_out.content_length_n)
                      - etag->value.data;

You can determine the last modified time in hex by using this Unix line:
printf "%x" $(stat -c%Y <file>)

The content length is determined here:
stat --format="%s" <file>

Sunday, November 9, 2014

Implementing Splunk SSO with Google Apps

Trying to setup Splunk with Google Apps authentication?

1. You can download a reverse proxy module for Nginx released by Bit.ly's engineering team. It requires installing Go (apt-get install go). You can compile it by typing go build, and the binary should be built.  The download link is listed below:

https://github.com/bitly/google_auth_proxy

The instructions in the README walk you through what you need to do to setup with Google's API console. Since Google is phasing out OpenID support, using Google Oauth is now the expected way to authenticate.

To start running the proxy, you'll need the accepted Google Apps domain, the callback URL (should end with /oauth2/callback), client ID, and client secret from the Google API console.

./google_auth_proxy -cookie-domain=mydomain.com -cookie-secret=abcd -google-apps-domain=googleappsdomain.com -http-address=127.0.0.1:4180 -redirect-url=http://myhost.com/oauth2/callback -upstream=http://www.cnn.com --client-id=1234.apps.googleusercontent.com --client-secret=1234

2. Setup your Nginx configuration to reverse proxy to 4180:

server {
  listen 80;

  location / {
      proxy_pass http://127.0.0.1:4180;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Scheme $scheme;
      proxy_connect_timeout 1;
      proxy_send_timeout 30;
      proxy_read_timeout 30;
  }
}

3. Next, you'll have to setup your configuration in etc/system/local/web.conf with this config. The goal is to use the email address used during login, which gets passed as X-Forwarded-Email, to Splunk. SSOMode set to strict will require all logins to depend on this header.  The tools.proxy.on seems to be used for older Apache reverse proxy setups, but doesn't need to be used for this setup.

SSOMode = strict
trustedIP = 127.0.0.1
remoteUser = X-Forwarded-Email
tools.proxy.on = False

4. Before you restart Splunk, make sure to create your usernames as the email address.  If you need to rename your existing ones, you'll need to edit the Splunk etc/passwd entries manually.

5. Once you restart, Splunk provides a /debug/sso endpoint, which lets you verify that the X-Forwarded-Email is being set correctly.   If you have any issues, turn off SSOMode = permissive until your are confident that the reverse proxy is setup correctly.


Tuesday, October 21, 2014

Why do you need colons for gesture recognizers

Apparently stuff that interacts with Objective C API's needs them..

http://stackoverflow.com/questions/24007650/selector-in-swift

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_26

What does the parenthesis in Swift does..

http://stackoverflow.com/questions/24071334/blocks-on-swift-animatewithdurationanimationscompletion

The completion parameter in animateWithDuration takes a block which takes one boolean parameter. In swift, like in Obj C blocks, you must specify the parameters that a closure takes:
UIView.animateWithDuration(0.2, animations: {
    self.blurBg.alpha = 1
}, completion: {
    (value: Bool) in
    self.blurBg.hidden = true
})
The important part here is the (value: Bool) in. That tells the compiler that this closure takes a Bool labeled 'value' and returns void.
For reference, if you wanted to write a closure that returned a bool the syntax would be
{(value: Bool) -> bool in
    //your stuff
}