Self Learning
2018年2月15日星期四
Regex Hong Kong Mobile Number Format
^((4|6)\d{7}$|(5[1-9]|7[0-3]|8[1-3]|9[1-8])\d{6}$|(90[1-9])\d{5}$)
2017年6月15日星期四
Android Decode eNB & cell id from ci
TelephonyManager tm = (TelephonyManage) Context.getSystemService(Context.TELEPHONY_SERVICE)
List<CellInfo> mCellInfo = tm.getALLCellInfo();
CellIdentityLte cellid = cellInfo.getCellIdentity();
String cellidHex = DecToHex(cellid.getCi());
String eNBHex = cellidHex.substring(0, cellidHex.length() - 2);
String lcidHex = cellidHex.substring(cellidHex.length() - 2);
int eNB = HexToDec(eNBHex);
int localCellid = exToDec(lcidHex);
// Decimal -> hexadecimal
public String DecToHex(int dec){
return String.format("%x", dec);
}
// hex -> decimal
public int HexToDec(String hex){
return Integer.parseInt(hex, 16);
}
List<CellInfo> mCellInfo = tm.getALLCellInfo();
CellIdentityLte cellid = cellInfo.getCellIdentity();
String cellidHex = DecToHex(cellid.getCi());
String eNBHex = cellidHex.substring(0, cellidHex.length() - 2);
String lcidHex = cellidHex.substring(cellidHex.length() - 2);
int eNB = HexToDec(eNBHex);
int localCellid = exToDec(lcidHex);
// Decimal -> hexadecimal
public String DecToHex(int dec){
return String.format("%x", dec);
}
// hex -> decimal
public int HexToDec(String hex){
return Integer.parseInt(hex, 16);
}
Android Get LTE signal strength
Use PhoneStateListener:
PhoneStateListener _psl = new PhoneStateListener() {
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Log.v("DEBUG_JOB", "onSignalStrengthsChanged");
getLteDbm(signalStrength);
}
};
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(_psl, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
There are three methods that I found:
First: When Build.VERSION.SDK_INT >= 17, use getAllCellInfo() methods of TelephonyManager class. But on some mobile device, getAllCellInfo() always return null.
public int getLteDbm(SignalStrength signalStrength) {
int rsrp = 0;
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> mCellInfo = telephonyManager.getAllCellInfo();
if (mCellInfo != null && mCellInfo.size() != 0) {
int index = 0;
for (CellInfo cellInfo : mCellInfo) {
if (cellInfo.isRegistered() && cellInfo instanceof CellInfoLte) {
Log.v("DEBUG_JOB", "[" + index + "]==CellInfoLte");
CellInfoLte x = (CellInfoLte) cellInfo;
CellSignalStrengthLte cstr = x.getCellSignalStrength();
if (cstr != null) {
rsrp = cstr.getDbm();
Log.v("DEBUG_JOB", "RSRP=" + rsrp);
}
CellIdentityLte cellid = x.getCellIdentity();
int pci = cellid.getPci();
Log.v("DEBUG_JOB", "PCI=" + pci);
Log.v("DEBUG_JOB", "CI=" + cellid.getCi());
}
index++;
}
}
return rsrp;
}
======================================================================
Second: Use split string on SignalStrength to get mLteRsrp value. But different mobile device got different position of mLteRsrp value.
public int getLteDbm(SignalStrength signalStrength) {
String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");
int rsrp = parts.length >= 9 ? Integer.parseInt(parts[9]) : -1; // some devices is 11
return rsrp;
}
======================================================================
Last: Use the hidden getLteRsrp() method of the SignalStrength class.
public int getLteDbm(SignalStrength signalStrength) {
int rsrp = 0;
try {
rsrp = (Integer) signalStrength.getClass().getMethod("getLteRsrp").invoke(signalStrength);
} catch (Exception ex) {
Log.v("Error", "getLteDbm=" + ex.getMessage());
}
return rsrp;
}
PhoneStateListener _psl = new PhoneStateListener() {
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Log.v("DEBUG_JOB", "onSignalStrengthsChanged");
getLteDbm(signalStrength);
}
};
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(_psl, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
There are three methods that I found:
First: When Build.VERSION.SDK_INT >= 17, use getAllCellInfo() methods of TelephonyManager class. But on some mobile device, getAllCellInfo() always return null.
public int getLteDbm(SignalStrength signalStrength) {
int rsrp = 0;
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> mCellInfo = telephonyManager.getAllCellInfo();
if (mCellInfo != null && mCellInfo.size() != 0) {
int index = 0;
for (CellInfo cellInfo : mCellInfo) {
if (cellInfo.isRegistered() && cellInfo instanceof CellInfoLte) {
Log.v("DEBUG_JOB", "[" + index + "]==CellInfoLte");
CellInfoLte x = (CellInfoLte) cellInfo;
CellSignalStrengthLte cstr = x.getCellSignalStrength();
if (cstr != null) {
rsrp = cstr.getDbm();
Log.v("DEBUG_JOB", "RSRP=" + rsrp);
}
CellIdentityLte cellid = x.getCellIdentity();
int pci = cellid.getPci();
Log.v("DEBUG_JOB", "PCI=" + pci);
Log.v("DEBUG_JOB", "CI=" + cellid.getCi());
}
index++;
}
}
return rsrp;
}
======================================================================
Second: Use split string on SignalStrength to get mLteRsrp value. But different mobile device got different position of mLteRsrp value.
public int getLteDbm(SignalStrength signalStrength) {
String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");
int rsrp = parts.length >= 9 ? Integer.parseInt(parts[9]) : -1; // some devices is 11
return rsrp;
}
======================================================================
Last: Use the hidden getLteRsrp() method of the SignalStrength class.
public int getLteDbm(SignalStrength signalStrength) {
int rsrp = 0;
try {
rsrp = (Integer) signalStrength.getClass().getMethod("getLteRsrp").invoke(signalStrength);
} catch (Exception ex) {
Log.v("Error", "getLteDbm=" + ex.getMessage());
}
return rsrp;
}
2016年8月22日星期一
PowerShell Maintenance Script for Citrix Xenapp 7.6
Function Global:Enable-MaintenanceMode([string]$groupname) {
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $true
}
}
Function Global:Disable-MaintenanceMode([string]$groupname) {
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $false
}
}
Function Global:Logoff-AllSession([string]$groupname) {
#Get-BrokerSession | where { $_.DesktopGroupName -eq $groupname } | Stop-BrokerSession
Get-BrokerSession -DesktopGroupName $groupname | Stop-BrokerSession
}
Function Global:Restart-Machine([string]$groupname) {
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
New-BrokerHostingPowerAction -MachineName $machine.MachineName -Action Restart
}
}
Add-PSSnapin Citrix*
# Logoff all sessions by Delivery Group
Logoff-AllSession -groupname GROUP1
# Turn on maintenance mode by Delivery Group
Enable-MaintenanceMode -groupname GROUP1
# Turn off maintenance mode by Delivery Group
Disable-MaintenanceMode -groupname GROUP1
# Restart server by Delivery Group
Restart-Machine -groupname GROUP1
-------------------------------------------------------------
# Show all Citrix command
Get-Command -Module Citrix*
# Show help of a command
Get-Help New-BrokerHostingPowerAction -Full
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $true
}
}
Function Global:Disable-MaintenanceMode([string]$groupname) {
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $false
}
}
Function Global:Logoff-AllSession([string]$groupname) {
#Get-BrokerSession | where { $_.DesktopGroupName -eq $groupname } | Stop-BrokerSession
Get-BrokerSession -DesktopGroupName $groupname | Stop-BrokerSession
}
Function Global:Restart-Machine([string]$groupname) {
# Get the machine list
$machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
foreach ($machine in $machines)
{
Write-Output "$machine.MachineName : " $machine.MachineName
New-BrokerHostingPowerAction -MachineName $machine.MachineName -Action Restart
}
}
Add-PSSnapin Citrix*
# Logoff all sessions by Delivery Group
Logoff-AllSession -groupname GROUP1
# Turn on maintenance mode by Delivery Group
Enable-MaintenanceMode -groupname GROUP1
# Turn off maintenance mode by Delivery Group
Disable-MaintenanceMode -groupname GROUP1
# Restart server by Delivery Group
Restart-Machine -groupname GROUP1
-------------------------------------------------------------
# Show all Citrix command
Get-Command -Module Citrix*
# Show help of a command
Get-Help New-BrokerHostingPowerAction -Full
2013年10月31日星期四
Python2.5 Query ArcGIS point feature class, Read and Write csv
import csv
import datetime
import arcgisscripting
gp = arcgisscripting.create(9.3)
# Set workspace.
gp.Workspace = r"C:\Users\Administrator\AppData\Roaming\ESRI\ArcCatalog\MYDB.sde"
dsList = gp.ListDatasets("TARGET_DATASET", "")
fcList = gp.ListFeatureClasses("TARGET_FEATURE_CLASS", "", dsList[0])
# Create Search cursor for feature class.
cur = gp.SearchCursor(fcList[0], '"COUNTRY" = \'CHINA\'')
row = cur.Next()
# Write csv
csv_file = open("C:\\" + datetime.datetime.now().strftime('%Y%m%d') + ".csv", "wb")
writer = csv.writer(csv_file, delimiter=",")
while row:
feat = row.Shape
pnt = feat.GetPart(0)
writer.writerow((row.CITY, str(pnt.x)[1:6], str(pnt.Y)[1:6]))
row = cur.Next()
# Read other csv then append to the newly created csv
other_csv_file = open("D:\\other.csv", 'rt')
try:
reader = csv.reader(other_csv_file)
for row in reader:
writer.writerow(row)
finally:
other_csv_file.close()
csv_file.close()
import datetime
import arcgisscripting
gp = arcgisscripting.create(9.3)
# Set workspace.
gp.Workspace = r"C:\Users\Administrator\AppData\Roaming\ESRI\ArcCatalog\MYDB.sde"
dsList = gp.ListDatasets("TARGET_DATASET", "")
fcList = gp.ListFeatureClasses("TARGET_FEATURE_CLASS", "", dsList[0])
# Create Search cursor for feature class.
cur = gp.SearchCursor(fcList[0], '"COUNTRY" = \'CHINA\'')
row = cur.Next()
# Write csv
csv_file = open("C:\\" + datetime.datetime.now().strftime('%Y%m%d') + ".csv", "wb")
writer = csv.writer(csv_file, delimiter=",")
while row:
feat = row.Shape
pnt = feat.GetPart(0)
writer.writerow((row.CITY, str(pnt.x)[1:6], str(pnt.Y)[1:6]))
row = cur.Next()
# Read other csv then append to the newly created csv
other_csv_file = open("D:\\other.csv", 'rt')
try:
reader = csv.reader(other_csv_file)
for row in reader:
writer.writerow(row)
finally:
other_csv_file.close()
csv_file.close()
Python2.5 Convert datetime format
import datetime
mydate = datetime.datetime.strptime('12/31/2013', '%m/%d/%Y')
mydate = mydate.strftime('%Y%m%d')
'20131231'
2013年10月18日星期五
C# Debug an ASP Project with Visual Studio 2003
When I try to debug the project, it always say "Unable to find project on the web server. Unable to set server into correct debugging state.".
In order to debug the ASP project, I have to change the following setting:
In order to debug the ASP project, I have to change the following setting:
- In VS 2003:
------------- Project - properties Configuration Properties Debugging - Enable ASP Debugging - Enable ASP.NET Debugging - In the IIS:
This sets an application name for the Website and changes the icon from a default folder icon to a Website icon.---------------------- Default Website - Properties Home Directory TabApplication Settings -Configuration Button Debugging Tab - Enable ASP server-side script debugging Website (the project you want to debug) - Properties Directory tab Application Settings - Create Button - Add IIS process account to Debugger Users group:
--------------------------------------------------- In Computer Management: System Tools Local Users and Groups Groups Debugger Users - properties Add user IWAM_machine-name (the "Launch IIS process account") - Now, to debug in VS 2003:
------------------------ right-click the .asp page that the application should start from select "Set as Start Page"
訂閱:
文章 (Atom)