Tuesday, December 31, 2019

Copy windows directory (folder tree) preserving the directory source time stamps

If you copy a folder in windows, you may notice that the newly copied (created) folders will have the timestamp when the copy was done (not the original timestamps from source). However, the files inside would have kept the original timestamps.

To have the folder (directory) timestamp as well to reflect the same as the source folder, do below in command line

Robocopy E:\Source\Dir1 D:\Dest\Dir1 /DCOPY:DAT /COPY:DAT /E /R:0


Note: If you already had copied the files using explorer, this will not copy the files again. It will check all and copy only if there is a newer file; plus (more importantly) will also update the destination folder with source folder time stamp. It ran much faster too as it didn't do any new copies... just had to set the timestamps

Tested in windows 10 version 1909

Thursday, September 12, 2019

SAP Authentication with ODATA services

SAP ODATA service Authentication is a two step process

Step 1 - Get token
  1. Make a GET request to the service URL
  2. Make sure Authentication is set as Basic and username and Password are passed
  3. Set a header "X-CSRF-Token" with value "Fetch"
  4. Send the request to SAP
  5. Examine the response headers
  6. You should see a header "X-CSRF-Token"
  7. Get the value from this header

This token value is typically valid for 30 mins

Step 2: Send request with token
  1. Change GET to POST (if you are sending a payload to SAP ODATA Service)
  2. Authentication is set as Basic and username and Password are passed
  3. Set a header "X-CSRF-Token" and value received from last step
  4. Send the POST request


You may get "CSRF token validation failed" if CSRF validation is enabled (in SAP) and the token is not send in header.


Below shows the same steps as done via Postman

Getting the token in Postman
  1. Use a GET request to the Service URL
  2. Set header "X-CSRF-Token"
  3. Set value as "Fetch"
  4. Hit Send
  5. Examine the response headers 
  6. Pick the value for "X-CSRF-Token"


 Using the token for a service request
  1. Change service to POST
  2. In header, set "X-CSRF-Token" to value from last reponse header value
  3. Set the payload body and submit request



Tuesday, July 30, 2019

SQL Server database went to Recovery Pending State


My SQL server went to "Recovery Pending" state after I mistakenly enabled folder compression for the folder where the database files are residing.
To recover,

  1. Stop SQL services
  2. Disable folder compression in the folder where SQL database files are stored
  3. Start SQL services
  4. Execute below recovery steps if still having trouble to use the DB. in case the DB went to single user mode, just the last step from below is needed

ALTER DATABASE [SQL-DB-Name] SET EMERGENCY;
GO

ALTER DATABASE [SQL-DB-Name] set single_user
GO

DBCC CHECKDB ([SQL-DB-Name], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO

ALTER DATABASE [SQL-DB-Name] set multi_user
GO

Thursday, June 13, 2019

MS Office - Opening Word/Excel/PowerPoint file shows file is corrupt or problem with content message


You may get a file corrupt message trying to open a file in Microsoft Office (365) Word, Office Excel or Microsoft Power Point

You may also see
"PowerPoint found a problem with content in 'file'. PowerPoint can attempt to repair the presentation. If you trust the source of the presentation, click Repair."

 And clicking Repair, will give message "Sorry, PowerPoint can't read 'file'"


Alternatively, you may also get a message "The operating system is not presently configured to run this application."




To Solve:
  1. Check the file properties (Right click file and select Properties)
  2. If you see the Option Unblock, check it and click Apply
  3. Open again and see if the error goes away


If the error persist, we can use the Inbuilt Excel (or Word or PowerPoint) repair tool to try to fix

  1. Open new instance of Excel (or Word or PowerPoint) - do not double click the file you need to fix
  2. In the menu, select Open on left
  3. Select Browse



4. Locate the file that need to be fixed and single click to select it
5. Click the down arrow next to the Open Button
6. Select "Open and Repair"


7.  Select Repair


 8. Click Close

9. Open the file again

Wednesday, June 5, 2019

GameMaker Studio 1/2 - replace black bars with sprite

To replace the standard black bars on side, that appear if the room/view size do not match the device size (resolution), do below

  1. Create a sprite with an image that can be tiled. ex: spr_tile_bg
  2. Create a object and place in room
  3. The object created should have just one event, "Pre-Draw" with this line draw_sprite_tiled(spr_tile_bg, 0, 0, 0);

This will tile the image as a background across the entire screen

Sunday, April 14, 2019

Youtube not showing dropdown menu (where you can switch to dark mode, etc...)

To enable drop down on your name after you sign in (top, right), go to https://www.youtube.com/new and enable the new youtube experience

After the page loads, you can switch to dark theme etc


Wednesday, April 3, 2019

Query a XML string for a specific field value in oracle SQL



1
select extractvalue(XMLTYPE(inputxml), '/ROOT/DATA/ELEMENT') "Value" from MYTABLE 


Where inputxml is a varchar2 column (storing xml as a string)
if you are storing data in a Xml datatype, you can remove XMLTYPE() function call

Tuesday, April 2, 2019

How to debug an aspx file with Visual Studio in IIS, that is not part of a project (or catch website exceptions with Visual Studio)

You have a file in IIS, you want to debug/step through

Open new instance of Visual studio (you may want to run it as Administrator)
File -> Open -> Web Site
In the left side, select Local IIS
Expand and locate the IIS Website your aspx file is part of

Any exception on this site will be caught now by VS

Monday, March 11, 2019

Unity capture animation to sprites (with transparency)

  1. Create a new Scene
  2. In game tab, set the resolution to be the same as your captured sprites should be
  3. Drag your prefab or gameobject for animation into your scene and position it as you like
  4. Save below code as FrameDump.cs
  5. Drag the FrameDump.cs to camera object
  6. Set the "frame count" to number of frames to capture. For, example, if you have created an animation with Samples 60 and it runs for 1 minute, set this to 60. Open your animation on your animation tab in Unity to see this
  7. Run your new Scene in editor by clicking Play
  8. You can stop after the "frame count" counts down to 0
  9. The files are saved to c:\temp\cap


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class FrameDump: MonoBehaviour {
 string folder = "C:\\temp\\cap";
 [SerializeField]
 int frameCount = 60;
 int MAXFRAMES = 0;

 // Initialization
 void Start() {
  // delete folder (and anything inside it) if it exists
  if (System.IO.Directory.Exists(folder)) {
   System.IO.Directory.Delete(folder, true);
  }
  // create the folder for dumps
  System.IO.Directory.CreateDirectory(folder);
  MAXFRAMES = frameCount;

 }

 private void OnPostRender() {
  if (frameCount <= 0)
   return;
  string filename = string.Format("{0:000000}", (MAXFRAMES - frameCount));
  Debug.Log("File: " + filename);
  //Create a new texture with the width and height of the screen
  Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
  //Read the pixels in the Rect starting at 0,0 and ending at the screen's width and height
  texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
  texture.Apply();
  File.WriteAllBytes(folder + "\\" + filename + ".png", texture.EncodeToPNG());
  Destroy(texture);
  frameCount--;
 }
}


Saturday, January 12, 2019

Consuming from specific Offset, in a Topic, with Confluent Kafka .Net client


From the example in the home page help here https://github.com/confluentinc/confluent-kafka-dotnet#basic-consumer-example 

Change below
c.Subscribe("my-topic");

and update it as below (assuming topic is "my-topic" and offset is 123456)

c.Assign(new TopicPartitionOffset(new TopicPartition("my-topic", new Partition()), new Offset(123456)));


Monday, January 7, 2019

Confluent-kafka-dotnet Consumer (client) - sasl configuration example

To use SSL Auth via SASL for Confluent's .NET Client for Apache Kafka,
update the example in the home page help here https://github.com/confluentinc/confluent-kafka-dotnet#basic-consumer-example with below config


var config = new ConsumerConfig

{
    BootstrapServers = brokerList,
    GroupId = groupId,
    EnableAutoCommit = false,
    StatisticsIntervalMs = 5000,
    SessionTimeoutMs = 6000,
    AutoOffsetReset = AutoOffsetResetType.Earliest,
    SecurityProtocol = SecurityProtocolType.Sasl_Ssl,
    SaslMechanism = SaslMechanismType.ScramSha512,
    SaslUsername = "mykafkausername",
    SaslPassword = "mykafkapassword",
    SslCaLocation = "MyKafkaCA.pem" //PEM file location (you may have to copy this to the .bin location
};


Note: 1.0 beta3 has the below changes
AutoOffsetReset = AutoOffsetReset.Earliest,
SecurityProtocol = SecurityProtocol.SaslSsl,
SaslMechanism = SaslMechanism.ScramSha512,

Windows - check to see if a remote server port is open

We can use portqry tool for this. Windows server editions should already come with this tool.

if not already in windows, you can download a command line or UI version from below
https://support.microsoft.com/en-us/help/310099/description-of-the-portqry-exe-command-line-utility

Usage is as below.
For example, to check if servername has port 80 open, do below

portqry -n servername -e 80

Friday, January 4, 2019

Unity - How to take a screenshot in game with script (at a specific resolution)

Attach below script to any object in your game. Click Play in editor and at the desired point, press "z" in keyboard to take your screenshot as a png file (if game is built, use Ctrl-Z). The screenshot will be stored (ie; the save location) in your Unity project's root folder


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TakeScreenShot : MonoBehaviour {

 // Update is called once per frame
 void Update () {
#if UNITY_EDITOR
        if (Input.GetKey(KeyCode.Z))
#else
     if((Input.GetKey(KeyCode.RightControl) 
      || Input.GetKey(KeyCode.LeftControl)) 
        && Input.GetKeyDown(KeyCode.Z))
#endif
        {
            Debug.Log("Taking screenshot");
            ScreenCapture.CaptureScreenshot("ScreenShot-" + 
             UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + 
             ".png");
            Debug.Log("Done");
        }           
    }
}


Tip: If you want a specific resolution of screenshot, make sure to set this in the player (ie; in Game tab)
In the below example, we are setting resolution to 2400 x 1200. When you use above script, the saved screenshot will have the same resolution.

See example below. Use + symbol to add custom resolutions

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...