2015-10-14

VZW Droid4 tethering enable

Enable tethering on a VZW Droid4:

use aSQLiteManager/aShell to edit:

/data/data/com.motorola.android.providers.settings/settings.db

set:

entitlement.check = 0

2015-10-13

where is the backup su stored by Voodoo OTA RootKeeper?

When you make a backup of su in Voodoo OTA RootKeeper 2.0.3 on Android 4.1.2 where does it go?
/system/usr/we-need-root/su-backup

I took a statically-linked version of an su which literally just changes the uid to 0 when its run setuid and stuck it there too, named unrestricted-su (it doesn't linkup with SuperSU for privilege prompts or anything).

Note this only works on Android < 4.2 since 4.3 mounts /system setuid and does not allow dalvik zygotes to run setuid binaries.

Forcing windows 8.1 to install google usb drivers for adb access

http://stackoverflow.com/a/25576781/2718295
I had the following problem: I had a Android phone without drivers, and it could not be recognized by the Windows 8.1. Neither as phone, neither as USB storage device. I searched Device manager. I opened Device manager, I right click on Android Phone->Android Composite Interface. I selected "Update Driver Software" I choose "Browse My Computer for Driver Software" Then I choose "Let me pick from a list of devices" I selected "USB Composite Device" A new USB device is added to the list, and I can connect to my phone using adb and Android SDK. Also I can use the phone as storage device. Good luck

2015-08-27

Get the DDL for a table in MS SQL Server

Query 1 gets you the actual column lengths from http://stackoverflow.com/questions/3854730/how-to-get-the-length-of-char-or-varchar-field-in-sql-server
SELECT
    sh.name+'.'+o.name AS ObjectName
        ,o.type_desc AS ObjectType
        ,s.name as ColumnName
        ,CASE
             WHEN t.name IN ('char','varchar') THEN t.name+'('+CASE WHEN s.max_length<0 then 'MAX' ELSE CONVERT(varchar(10),s.max_length) END+')'
             WHEN t.name IN ('nvarchar','nchar') THEN t.name+'('+CASE WHEN s.max_length<0 then 'MAX' ELSE CONVERT(varchar(10),s.max_length/2) END+')'
            WHEN t.name IN ('numeric') THEN t.name+'('+CONVERT(varchar(10),s.precision)+','+CONVERT(varchar(10),s.scale)+')'
             ELSE t.name
         END AS DataType
        ,CASE
             WHEN s.is_nullable=1 THEN 'NULL'
            ELSE 'NOT NULL'
        END AS Nullable
        ,CASE
             WHEN ic.column_id IS NULL THEN ''
             ELSE ' identity('+ISNULL(CONVERT(varchar(10),ic.seed_value),'')+','+ISNULL(CONVERT(varchar(10),ic.increment_value),'')+')='+ISNULL(CONVERT(varchar(10),ic.last_value),'null')
         END
        +CASE
             WHEN sc.column_id IS NULL THEN ''
             ELSE ' computed('+ISNULL(sc.definition,'')+')'
         END
        +CASE
             WHEN cc.object_id IS NULL THEN ''
             ELSE ' check('+ISNULL(cc.definition,'')+')'
         END
            AS MiscInfo
    FROM sys.columns                           s
        INNER JOIN sys.types                   t ON s.system_type_id=t.system_type_id and t.is_user_defined=0
        INNER JOIN sys.objects                 o ON s.object_id=o.object_id
        INNER JOIN sys.schemas                sh on o.schema_id=sh.schema_id
        LEFT OUTER JOIN sys.identity_columns  ic ON s.object_id=ic.object_id AND s.column_id=ic.column_id
        LEFT OUTER JOIN sys.computed_columns  sc ON s.object_id=sc.object_id AND s.column_id=sc.column_id
        LEFT OUTER JOIN sys.check_constraints cc ON s.object_id=cc.parent_object_id AND s.column_id=cc.parent_column_id
    WHERE o.name='YourTableName'
    order by 1,s.column_id

Query 2 gets you column names too but preserves the column order of the referenced table: http://stackoverflow.com/questions/1054984/how-can-i-get-column-names-from-a-table-in-sql-server
SELECT o.Name                   as Table_Name
     , c.Name                   as Field_Name
     , t.Name                   as Data_Type
     , t.length                 as Length_Size
     , t.prec                   as Precision_
FROM syscolumns c 
     INNER JOIN sysobjects o ON o.id = c.id
     LEFT JOIN  systypes t on t.xtype = c.xtype  
WHERE o.type = 'U' 
and o.Name = 'ctpt_upsebill_load'
--ORDER BY o.Name, c.Name

Use the above 2 queries as CTLs and join Query 1 to Query 2 to get full DDL in the correct order.

2015-05-04

Read file pattern (Python)

Here's a pattern that I've been using a lot to read files in Python 2.7:
import codecs
badrow_count = 0
goodrow_count = 0
rowcount = 0

filename = "somefile.txt"
encoding = "utf-8"
# see https://docs.python.org/2/library/codecs.html#standard-encodings
# for encodings

decode_error_handler = 'strict'
# this is the default
# see https://docs.python.org/2/library/codecs.html#codec-base-classes 
# for decoding error callbacks

f = codecs.open(filename=filename, mode='rU', encoding=encoding, 
    errors=decode_error_handler)
eof = False
while not eof:
    row = u''
    try:
        row = f.next()
    except UnicodeDecodeError as e:
        badrow_count += 1
        # do other things on this row
    except StopIteration:
        eof = True
    #except Exception as e:
        # handle other issues    
    else:
        goodrow_count += 1
        # do other stuff with row
    finally:
        if not eof:
            rowcounter += 1
        else:
            break
I prefer this to:
for row in f:
primarily in order to catch unicode decoder errors.

2015-02-27

postgresql unpivot

Given a monthly currency conversion table like:
iso4127_codeJanFebMarAprMayJunJulAugSepOctNovDec
JPY0.0096130.0097920.0097780.0097570.0098270.0097900.0098290.0097170.0093460.0092620.0086060.008375

I need to unpivot so that I get a table that is:
iso4127_codemonthrate
JPY10.009613
JPY20.009792
...
select iso4127_code, 
unnest(array[1,2,3,4,5,6,7,8,9,10,11,12]) as month,
unnest(array[jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]) as rate
from table

Strip HTML tags using regex

While for proper Markup Language parsing one should actually use an XML parser, sometimes you just want to strip all the markup using regex:
s/<\/?[^>]+>//

Query AD using ldapsearch

(Useful for troubleshooting AD logons if you have cygwin:

http://jurjenbokma.com/ApprenticesNotes/ldapsearch_ad_query.html)

Now at: http://jurjenbokma.com/ApprenticesNotes/ldapsearch_ad_query.xhtml
to force TLS_REQCERT never:

LDAPTLS_REQCERT=never ldapsearch ...