fabiochiu/medium-articles huggingface dataset:
2 most popular ways of debugging in Ruby (on Rails)
By: Szymon Lipka
Tags: Ruby, Ruby on Rails, Monkey Patching, Debugging, Ruby On Rails Development

“binding.pry”

The “binding.pry” is in my opinion the best way of debugging in Rails. Whenever you have problem and you have no clue how to solve it, the “binding.pry” is coming to help you.

In any place in your code whenever you have installed gem 'pry' you can place the binding.pry line. The program will stop and you’ll be abled to check every variable and call every method from place where you’ve placed the line.

I encourage you to see the magic gem “pry” at https://github.com/pry/pry to see more features which it brings.

2. Monkey patching methods

There are some situations when you cannot use gem “pry”. For example never ever you should use this on a production environment.

Usually in cases like this I monkey patch methods which are problematic and look closer onto them.

For example we have class Cars::Toyota like:

class Vehicle

def initialize(wheels)

@wheels = wheels

end



attr_reader :wheels

end module Cars

class Toyota < Vehicle

def drive

wheels.map(&method(:spin))

end



def spin(wheel)

number_of_spins.times.inject(0) do |distance, x|

distance += wheel[:radius]

end

end def number_of_spins

1000

end

end

end

And something is not right in it. But there is too many afford to reproduce this problem locally.

The way I suggest to solve this problem is checking what is going on inside spin method.

The way I would’ve probably done that is Monkey patching the method like:

$ bundle exec rails c

irb(main):001:0> module Cars

irb(main):002:1> class Toyota

irb(main):003:2> def spin(wheel)

irb(main):004:3> number_of_spins.times.inject(0) do |distance, x|

irb(main):005:4* p "Distance: #{distance}"

irb(main):006:4> p "x: #{x}"

irb(main):007:4> distance += wheel[:radius]

irb(main):008:4> end

irb(main):009:3> end

irb(main):010:2> end

irb(main):011:1> end

=> :spin

irb(main):012:0> ::Cars::Toyota.new([{radius: 1000}]).drive

And now we clearly see that we messed up order of arguments of our chained enum #times #inject. The method should’ve looked like this:

def spin(wheel)

number_of_spins.times.inject(0) do |_x, distance|

distance += wheel[:radius]

end

end

The underscore before argument is basically telling the block that the variable won’t be use in it and it’s recommended to use it always.
Debugging your website with chrome developer tool
By: Temitayo Bakare
Tags: Chrome Extension, Debugging, JavaScript

We all in one way or the other have come across issues while developing a website ranging from errors from the server to javascript code not working on the frontend and we are so confused on what might be going on behind the scenes. Don’t get frustrated cause there is a way around it “On of the secrets of every efficient web developer” CHROME DEVELOPER TOOL . Chrome developer tool reveals what goes on behind the scenes when you carry out an activity on the website. When you click on a login button you can see the request it makes to server, when you click on a drop down button the event can also be seen in the developer tool.When you can detect where an error is coming from then it points you in the right direction where you should focus your fix on. Let us take a look at how to detect a server error issue.

What you can see above is a website where an excel assessment can be taken, while testing the website I discovered after submitting I couldn’t get my scores. With my knowledge of chrome developer tool I accessed the developer tool with (option + command + i) for mac users and (ctrl + shift + i) for windows user. I clicked on the network tab and saw the request made to the server and there it was a server error returning a 500 status code. With this known i knew there was an error on my backend code and went in there to fix it.

You can check all requests made when you launch a website from the network tab including requests to fetch your css files,javascript files, third-party api’s and server request.

Secondly you can check the performance of your website ranging from how long it takes to load the page to loading the scripts. To do that just open your chrome developer tool click on the performance tab and click on record. After you have done that try to load the website and it gives you the recorded results of your website performance. You can reload the page for performance results by clicking on the reload button on the performance tab page.

There are many more issues you can detect with chrome developer tool these are just few of them. Apart from debugging you can also use the developer tool to get insights to how a website works and what are the components that makes up the entire website. You can view the css files,js files and third-party api’s that were used, you can also check out part of the codes that were writing for the frontend and much more. Exploring the chrome developer tool is one of the best thing that can happen to you as a web developer. It makes issues easy for you to detect and fix, it also gives you insight to how things works behind the scenes. Take the time to explore the huge benefits the chrome developer tool has to offer and you will be amazed by the power it gives you.
Getting Started
Tags: Wtforms, Flask, Debugging, Cs50, Web Development

I’ve been contemplating getting back into blogging again, and I figured that there is no better time to start than today, now.

My intention of creating this blog is to share my journey as I teach myself to code. I’ll be journaling my day-to-day life as well.

I’ve been taking CS50’s Web Development with Javascript and Python course, the 2018 version. Although project 1 is outdated and no longer valid for submission (now that they are running the 2020 version), I’ve decided to challenge myself to do it anyway, simply for the sake of learning.

Today’s post will be about the bug I fixed today. Every day presents a new bug for me to fix to there will surely be no lack of posts. I hope that by posting the errors I’ve made and how I managed to debug it, I’ll be helping fellow noobs, and more knowledgeable experts could weigh in on the root of the problem and provide their expertise on how I can do things better.

This particular bug caused me to nearly throw in the towel because I simply couldn’t find out where I went wrong — no error messages whatsoever! But I overcame it, and this momentous moment calls for some documentation.

The Problem

Having created a registration (and login) form using Flask WT Forms and HTML, I was delighted to find that my forms showed up perfectly in the browser, only to find that the form validators do not work.

Typing ‘a’ in every field, and nothing changes after clicking ‘Submit’. Pictures of my code below would have it that I did determine validators and error messages.

After some googling, I realized that I had left out {{ form.csrf_token }} in my HTML file. Apparently the CSRF token is a default in WTForms, so my form would surely fail if I did not include it in. So I amended it accordingly and removed the </form> tag right after …Method =’POST’, as I realized that there was already a closing tag at the end of the page.

Almost there…..

By now I figured that the problem must be in the HTML file because there seemingly isn’t anything wrong with my 2 other Python files. I took a closer look and…

Code with extra erroneous stuff removed

Since the previous step entailed removing an extra tag, I figured the same thing might be happening. So, I removed the <!DOCTYPE Html> tag at the top of the page, seeing as there was already an opening tag on line 2.

Error messages are showing up!

Typing in a username and password the fulfills the stated conditions

Et voila!
ADB cannot connect to daemon
By: Abdullah Aimen
Tags: Android, Adb, Debugging, Kotlin, Wifi

About more than two years ago, Google has brought a new debugging tool that will facilitate the process and replace the old one (connecting over a cable) to be over WIFI. But some times when you start configuring your device to work over WIFI you discover issues like the below!

ADB server cannot connect to daemon

This error comes from being unable to restart the ADB-server or unable to kill all processes. Also, maybe due to the process id you are trying to preserve is being used by another process.

After a while of searching, I found out that I have to manually kill the ADB server and start it again from the SDK platform.

To do so, Navigate to the ADB location inside SDK, in my case ~\home\Android-SDK\platform-tools, then type the below command:

adb kill-server: this command will kill the daemon server and all its processes adb start-server: this command will restart the daemon server again.

After that, you can follow the normal steps for connecting your device.

plugin your phone to the laptop and open the terminal or android terminal then follow the commands below:

adb devices

adb tcpip 5555

then, connect over the same network and get the IP address to connect over, then type

adb connect <ip address>:5555

Now you can execute ADB commands or use your favorite IDE for android development — wireless!

Hope this will work for you! if so, share and Clapp is appreciated ;)
Debugging Blazor Web Assembly Apps
By: Ali Bahraminezhad
Tags: Dotnet Core, C Sharp Programming, Blazor, Debugging, Wasm

Getting Started

Debugging BlazorWasm is possible in Google Chrome (version 70 or later) or Microsoft Edge preview.

I have this simple Razor page in Blazor:

I want to debug the IncrementCount method.

To be able to debug, you need to run the Blazor app with a debug configuration profile. For doing this open a terminal inside the root of the project and execute the command below:

dotnet run --configuration Debug

Navigate to the URL your app will be run on it. (https://localhost:5001).

Press Shfit+Alt + D (on Mac Shift + Cmd + D)

Most of the time, Blazor and Chrome debugger cannot connect to your app and give you an error like this:

If you saw this window, copy the command and run Chrome with these arguments in Run:

chrome --remote-debugging-port=9222 --user-data-dir="\Temp\blazor-chrome-debug" http://localhost:5000/

It will open Chrome, press the debugger key combination to open the debugger. Inside Sources and file:// you can see your source codes, set or remove breakpoints to control your application workflow.

Sample of debugging

As you can see, I cannot see the values of properties even by hovering mouse or add a watch. To be able to see the values inside your application, you can write data in the browser console by Console.WriteLine in Blazor code.

When running your app (debug profile is not needed), every-time the app reaches Console.WriteLine it will log it inside browser console.

Console logging

Error diagnosis

Consider the code below:

@code {

private int currentCount = 0; private int currentCount = 0; private void IncrementCount()

{

int a = 0;

int b = 0; currentCount = a / b;

}

}

The code above will throw an exception. If we run the app, you will see the error and stack state in the browser console.

It tells you what exception has occurred.

You can see what method and what line caused the error.
Debugging browser Web Workers
By: Raphael Yoshiga
Tags: Software Development, Typescript, Debugging, JavaScript, Development

This is a short post on debugging web workers.

One important aspect of being a software engineer is to quickly isolate the errors between layers (Browser/Backend/Database). On the browser, we are used to the Developer Tools. That tells us what errors happened, allow us to debug javascript or spy on the network tab to see what requests/responses went through the network. But in some applications, work is done inside a Web Worker, which the Developer tools doesn’t seem to debug by default. Or does it?

With chrome, you can navigate to chrome://inspect/#workers.

Chrome inspect web workers.

There you go, you have the developer tools in the context of the WebWorker.

Developer tools inside a web worker

Now you can debug the scripts or see what is going on in the network tab.

But what are Web Workers?

Web workers are a simple way to run things in the background, in a separate thread than the UI one. Their use is common on applications that require a high degree of processing in the browser, so we can run this processing in more threads and not interfere with the main UI thread.

Final thoughts

So if sometimes you are expecting HTTP requests on the network tab, but they mysteriously do not appear at all. Maybe the requests are being made inside the web worker, so it’s worth double-checking—happy debugging.
Here’s Why You Should Be Using Overrides in Chrome Devtools
By: Shahed Nasser
Tags: Debugging, Technology, Programming, Development, Web Development

How to Use Overrides

To use Overrides, open the Devtools either from the settings or using the keyboard shortcut CTRL+SHIFT+I .

Then, Click on the Sources tab. You’ll see at the top of the left menu 3 tabs: Page, Filesystem, and Overrides.

Click on Overrides. Below it you will see “ Select folder for overrides.” Click on it and choose a folder. This folder will store all the overrides you make.

Once you select a folder, a prompt will show up at the top of the page. Click Allow.

When you do, you are ready to use overrides on this website. You can go back to the devtools Sources tab, then click on Page. Choose a file like a Javascript or CSS files, right click it and choose “ Save for overrides.” The file you choose will now appear in the Overrides tab.

Now, any changes you make to the file will persist throughout page reloads and navigating pages in the website as long as the devtools is running.

To stop overriding files on the website, go to the Overrides page again and click on the icon for “ Clear configuration” and the overrides will be gone.
Debugging your Python code easier — Hot module reloading for Python
By: Milk Zheng
Tags: Development, Debugging, Python

An example to reload a function

I was working on a Python project used for data analysis. Basically, it’s a workflow that some of the analyses rely on previous results. When you found a bug in your code, you make some changes to your file. To make the change effect, you have to restart the interpreter, reimport your library, rerun the code. This is very inconvenient and tedious, I need to repeat the process many times to fix a bug.

So, I went on to search for a solution, I found that IPyhon comes with a magic command % autoreload and a deepreload function. However, this doesn’t work on function with a decorator (check this issue). And it only works on import X syntax.

And then I found another two packages that might fit my need, auto-reloader, and reloadr. The first one uses a class as a proxy, it simply reloads everything for you when you access the attributes, it’s similar to IPython’s reload, only works for import X syntax. The second one uses watchdog to monitor file changes and then reload the function or class for you. However, it’s intrusive, you need to add a decorator to the object you want to reload. Alright, why not bind the two things together. So here comes the python-hmr.

python-hmr

The “hmr” stands for “hot module reload”, simply install it with:

pip install python-hmr

It’s very easy to use, import your package as usual. And then replace it with the Reloader . Then you are ready to go. Use it exactly as before.

If you want to reload a function or a class , it’s exactly the same.

If you like it, it would be so nice if you could leave a 🌟 for me on Github.
Beginner’s guide on debugging Redux issues
By: Yuliya Kandratsyeva
Tags: Software Development, Redux, Software Engineering, Debugging, Beginners Guide

Beginner’s guide on debugging Redux issues

A comprehensive (yet short and sweet) guide on how to debug Redux issues like a pro Yuliya Kandratsyeva Jan 22·4 min read

Being new to React/Redux ecosystem and programming in general implies that you will run into a lot of issues. It’s not as easy as it seems you might think. There are situations when your store is silently overridden with something you didn’t even intend to override. Yikes…

So how do you know where exactly your program is failing, where do you even start? What’s the first thing that comes to mind?

Console logs!

No…

While console logs are great, there’s a good reason not to use them. Yes, you can log an entire state object into your browser console, but there’s a much better solution — Redux Dev tools! And here’s why:

Dev tools allow you to go back in time and and see the timeline of events that had happened since you refreshed the page and loaded a fresh state.

Highlighted rows are actions that were dispatched in response to some event. In my example here my web app dispatches SET_ROBOTS, SET_PROJECTS on page refresh and SET_SINGLE_ROBOT when I’m accessing a page with a single robot.

Cool, right?

By replaying the timeline, you can clearly see which actions were fired at a given moment in time and what your state tree looked like. In addition to that, Diff tab has a lot of info what exactly changed in your state. If you realized that something is getting accidentally overridden, this might be a good place to start.
Snowflake: How to debug stored procedure efficiently
By: Martin X.
Tags: Stored Procedure, Snowflake, Azure Data Factory, Debugging, JavaScript

From Snowflake website below about stored procedure:

So, why not just console.log(), hmm?

Or PRINT (for SQL server folks),

Or DBMS_OUTPUT.PUT_LINE for Oracle folks?

Why it is so hard that I have to define a log table, blah, blablah…https://docs.snowflake.com/en/sql-reference/stored-procedures-usage.html#logging-an-error-version-2

At least, the given example does not fit for my purpose.

As a developer, I often need to debug, what is the result of the function/procedure, why it fail(error message), at which line it fail.

Currently, Snowflake fall short of these.

What alternative option available?

OK, it is JavaScript. I should make use of it, especially,{} and [] — object and array.

Personally, I don’t think it is a good idea to use JavaScript instead of native language or dataframe support language, like Python. Data lineage tracking would be quite different, compared with SQL which can be parsed to AST.

CREATE OR REPLACE procedure MY_PROC(PARAM float)

RETURNS VARIANT NOT NULL

LANGUAGE JAVASCRIPT

AS

$$

try {

var msg = [];

msg.push({prc:'MY_PROC checkpoint 1:'+ new Date().toISOString(),txt:'test'});

A= snowflake.execute({ sqlText:`select 1/`+ PARAM});

A.next();

return_val = A.getColumnValue(1); msg.push({prc:'MY_PROC checkpoint 2:'+ new Date().toISOString(),txt:'test finished.'});

return {status:1, ret:return_val, msg:msg};

}

catch(err) {

msg.push({prc:'MY_PROC checkpoint 3:'+ new Date().toISOString(),txt:'FAILED:' + err});

return {status:0, ret:null, msg: msg};

}

$$;

Explanation, let me dive into the code snip a bit more.

1) msg array to hold execution message, check point x…

2) return object of the function is: {status: 0, ret: placeholder, msg:[]}, where: status indicates whether procedure run successfully or not.

ret: returns value of the procedure, msg: keeps the messages.

First test:

CALL MY_PROC(3);

Result is as below:

{

"msg": [

{

"prc": "MY_PROC checkpoint 1:2020-11-22T03:41:44.244Z",

"txt": "test"

},

{

"prc": "MY_PROC checkpoint 2:2020-11-22T03:41:44.322Z",

"txt": "test finished."

}

],

"ret": 3.333330000000000e-01,

"status": 1

}

status = 1 means it ran successfully, with the return value is 3.333330000000000e-01 as expected. Yeah!

Second test:

CALL MY_PROC(0)

{

"msg": [

{

"prc": "MY_PROC checkpoint 1:2020-11-22T03:13:33.884Z",

"txt": "test"

},

{

"prc": "MY_PROC checkpoint 3:2020-11-22T03:13:34.105Z",

"txt": 'FAILED:Division by zero'

}

],

"ret": null,

"status": 0

}

status = 0 means it ran with error, with the return value is null as expected. Bingo!

So, now I know somewhere error happened between checkpoint 1 and checkpoint 3.

It is not a ideal solution, but works well for me, I can debug the code more efficiently.

Also, I can define complex JavaScript function with in the stored procedure. However, it can not be use as common function or library, then I’d rather not making it too complicate.

Stay tuned for the next article: Snowflake: Nested Stored Procedure.
Python remote debugging with PyCharm, CUDA, and Conda
By: Niranda Perera
Tags: Cuda, Python, Deep Learning, Debugging, Pycharm

#DeepLearning, #CUDA, #PyTorch, #tensorflow are the hype in software engineering these days, and I am also working on some HPC-Deep learning integration.

One requirement I had was to create a debugging setup that includes PyCharm, CUDA, and Conda. I do not have an Nvidia GPU device on my laptop, but my workstation has one and I have ssh access to it. This I think, is a common setup for most of us, and hence I think this would be a quick summary of how you can set up ‘remote debugging’.

So, my setup is,

Local laptop without Nvidia device, running PyCharm Pro as the IDE

Remote workstation with an Nvidia device, running CUDA, and python environment running on Anaconda.

Remote access to the workstation is set up through ssh

Following test script (from PyCuda docs)

Steps:

Steps are quite straight forward. But there are a couple of ‘Aha…’ points!

Create a new project and add the above test script. Add a new SSH remote interpreter for PyCharm. Refer PyCharm docs. In the interpreter, set python path to conda python binary (path from the remote machine). Ex: In my workstation, conda python was in /home/niranda/anaconda3/bin/python Setup remote debugging for the project. Refer PyCharm docs. This is the most important step. Set PATH and LD_LIBRARY_PATH in the debug configurations. These values should be taken from the remote machine.

That’s it! Now you can simply debug your code, pointing to the remote python interpreter than has CUDA, pycuda and/ or anything you like! :-)

Cheers
A hassle-free, zero dependency way to handle console.log() & co. in a production Angular application
By: Manuel Heidrich
Tags: Javascript Tips, Angular, Debugging, JavaScript, Javascript Development

console.log() and its siblings likely are the most used methods any JavaScript developer has ever used. And that's totally fine, because console.log() most definitely is a huge help if not even a life saver when debugging an application.

And there is the challenge right there: as helpful as output in the browser’s console is when debugging, it is absolutely not a good idea to leave this output when deploying your application to production. At least any output below the error level.

So one solution could be to not leave any console methods in the code (except maybe console.error() ). Fortunately linters like tslint or eslint have built-in rules to help you with that. But let's be honest, we developers usually are lazy af. Also often there are situations where we want to have console output permanently when developing. So it would be a huge hassle to add, remove, re-add (and so on) the console methods.

I wrote about a custom logger service a couple of years ago, which is environment agnostic, but I’m no longer using it. The main reason is that you are not able to see the file and line the output was generated. Plus I do not always want to import and inject a service first. Using console.log() is just so much more convenient.

My solution

For my current side project Monitornator I added a method called handleConsole() to my AppComponent that looks like this:

private handleConsole(): void {

let methods: string[] = [];



switch (environment.name) {

case ‘production’:

case ‘staging’:

methods = [‘log’, ‘debug’, ‘info’, ‘warn’];

break;



default:

break;

}



if (methods.length) {

console.warn(`🚨 Console output is disabled on ${environment.name}!`);

}



methods.forEach((method) => {

console[method] = function(): void { };

});

}

What it does is basically overriding any console method with an empty function, depending on the current environment. So leaving console.log() in the code in this case will just print nothing while on staging or production. Using switch case allows me to quickly add different log levels for different environments. And before overriding the methods I print a warning to the console, because... let's say SOMEONE more then once spent a huge amount of time wondering why console.log() suddenly stopped working while on staging 🤦🏼‍♂️.

Conclusion

Of course there is a fair amount of logging libraries out there, some better than others, but I personally don’t want to add another dependency for something I can solve with just a couple lines of code. The above solution works pretty fine for me.
Easy way to debug and externalize logs from CloudWatch when log events are more
By: Doyle Wilson
Tags: Ec2 Instance, AWS Lambda, Cloudwatch Logs, Debugging, AWS

Easy way to debug and externalize logs from CloudWatch when log events are more Doyle Wilson Sep 4, 2020·3 min read

In this section, I will tell you an easy way of how we can debug logs from CloudWatch when the log events are more.

Problem Description: Consider we have a Lambda that processes more than 1000 records and for every processing of the data, an event will be logged in to CloudWatch. Now some of the data in the processing failed. We need to identify how and why the data has failed.

To check the above issue,

Login to AWS Console, look for CloudWatch services

2. Get the log group for the respective lambda, (for e.g, the lambda name is hello_world)

3. Look for the log stream and the time stamp for when the data has failed processing by getting into the log group

4. Click on the log stream you will find the log events on how the data got processed.

Issue: Consider our lambda process 1000 records. If we need to identify the particular data for which it has failed, we need to keep on clicking the Load more as shown below until our data shows up which is time-consuming.

In order to avoid this, we can externalize the log stream and look for the data that we need using grep or find option, which will be a very a quick task.

Solution:

Login to any of the EC2 box launched in the respective region where the lambda runs through Putty or SSH via Terminal Get the log stream of the log group by using the below command

aws logs describe-log-streams — log-group-name /aws/lambda/hello_world — log-stream-name-prefix 2020/08/17/ — region “us-east-1”

3. Get the log stream name you need based on the prefix passed as mentioned in Step.2 and create a JSON file in the below format and save it as log-events.json

log-events.json

4. Copy the log stream to a log file log-events.log. To do that use the below comment,

aws logs get-log-events — cli-input-json — region “us-east-1” file://log-events.json > log-events.log

Now all the log events, logged by the lambda will be available in the log file. To get the log file to your local desktop location from the EC2 box, use FileZilla or scp command.

Trouble Shooting:
Chrome Trace Profiling Tool with Python
By: Tian Gao
Tags: Python, Logging, Debugging, Profiling, Programming

You might be familiar with the chrome trace profiling tool if you are a front-end engineer and often work with Chrome. In fact, you can open chrome://tracing and record your browser’s behavior. The result will look like the image below:

Record of Chrome by Chrome Trace Viewer

It is a great tool for both performance analysis and debugging, because it shows every single thing happened in all the threads in chronological order. You can zoom out the get a general idea of the whole picture, or zoom in to check the details of a single function.

Zoom in for details

This is especially helpful when you try to profile or debug a multi-process or/and multi-thread program, when a traditional profiler/debugger can’t layout concurrency intuitively.

In fact, this UI, called trace-viewer, does not only live in Chrome. Android systrace is using this as well(and of course that’s a Google thing too).

Now, you can enjoy the powerful tracing visualization tool with Python, using an open-source library — VizTracer.

VizTracer generates similar data that complies to chrome trace event format so you can visualize that using the exact same tool. Actually, VizTracer can generate the standalone report directly, so the only thing you need to do is to open the file in the browser.

It’s super easy to use VizTracer. Install it through pip:

pip install viztracer

Then, instead of using python to run your program, use VizTracer

viztracer your_script.py

VizTracer will produce a result.html file with the log of your program. Something like:

Log with VizTracer

VizTracer supports multi-thread and multi-process, Linux, MacOS and Windows. You can enjoy the power of Chrome trace viewer on Python.

In addition, VizTracer has many features to make your life even easier without any source code change.

For example, you can log

Function arguments and return value

Any variable or attribute matching certain RegEx

Exceptions raised, caught or not

Garbage collection

All stuff print() function send to stdout

There are more features to explore once you are familiar with the tool. You can check it out at https://github.com/gaogaotiantian/viztracer
Postmortem
By: Julian Mendez
Tags: Debugging, Issues, PostMortem

On 9–04–2021 PDT at midnight, our company released a new project where there were issues. We were tasked with finding the cause of the problem by the end of 14–04–2021. This is the postmortem of that bug.

The Service Interruption

A WordPress website, running on a LAMP stack, was returning a 500 status code to all get requests. The website itself is a simple HTML page, but a problem with MySQL or PHP can still disable the website.

Timeline

9–11–2021, 12:00 am PDT, Project released.

9–12–2021, 12:00 pm, Begin working on a project with Madison Burke, with help from Mitali Sengupta and Victor Nguyen. Notice missing error logs.

9–12–2021, 12:30 pm, Error logging has been enabled and ‘no such file’ error is seen.

9–12–2021, 12:40 pm, typo is manually fixed and requests return 200 status code.

9–12–2021, 1:53 pm, Rough draft of Puppet code written.

9–12–2021, 5:56 pm PDT, Puppet code finalized.

The Bug

The first clue came from /var/log. Apache and MySQL both had error logs, but PHP’s was conspicuously missing. After enabling PHP’s various error configurations in /etc/php5/apache2/php.ini, I restarted the server and used the command curl localhost:80 , and the response stated an error on line 137 of the file /var/www/html/wp-settings.php. Going to the file, the line reads require_once( ABSPATH . WPINC . ‘/class-wp-locale.phpp’ ); , a clear typo.

The Solution

To fix this server, the file var/www/html/wp-settings.php can be changed directly, but if the issue exists on multiple servers a script will be handy. Here’s a Puppet script that accomplishes the task.

# fixes typo in config file

exec { ‘replaces line in config file’: command => ‘sed -i “s/.phpp/.php/g” /var/www/html/wp-settings.php’,

path => ‘/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin’,

onlyif => ‘test -f /var/www/html/wp-settings.php’

}

After implementing the solution, a get request returns a normal HTML page with a status code of 200.

Prevention

This is a very glaring error to find in production, so I assume this would likely be caused by someone manually changing one thing in a config file and accidentally changing something else. It’s also possible that a seemingly unrelated part of the program hosted on the server changes this config file as an unforeseen side effect. I would check other servers for the same bug, and implement more rigorous testing.
Visual Studio Code & C programming on Linux
By: Tarang Patel
Tags: Visual Studio Code, Centos, C Programming, Debugging, Linux

I have been playing with Visual Studio Code(VSCode) to develop C code on Linux. Lately, I have became a fan of Visual Studio Code which I believe is a great free product from Microsoft for developers in a long time.

I will show how to setup a Visual Studio Code on Linux CentOS and setup debugging C programming so that developers can step through the breakpoints in code. Please keep in mind that support for C/C++ on Visual Studio Code(VSCode) is still in preview so some things might not work as expected. The VSCode team is working hard to weed out some of the issues and release new features.

Disclaimer: I am not part of the Visual Studio Code team at the time of this writing.

Installing VSCode on CentOS

Microsoft has fallen in love with Linux since May 2015. That strategy helps them attract and become more developer friendly organization. That’s why the VSCode is available across Linux, macOS and Windows environments.

The details and most up-to-date steps are described here https://code.visualstudio.com/docs/setup/linux. I will show you a quick start guide for CentOS.

Open terminal instance and run following two commands:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'echo -e "[code]

name=Visual Studio Code

baseurl=https://packages.microsoft.com/yumrepos/vscode

enabled=1

gpgcheck=1

gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

Update the package and install the VSCode:

yum check-update

sudo yum install code

Installing VSCode was easy…

Installing C/C++ Extensions

VSCode needs special extension to provide rich code editing options for C. The extension is developed by Microsoft. Click on Extensions icon on the sidebar and search for “c”. The first search result, “c/c++” by Microsoft is the popular extension I used. Install it.
IntelliJ Setup for Jenkins Core Development
By: Sumit Sarin
Tags: Jenkins, Setup, Debugging, Intellij, Beginners Guide

1. Installation and Cloning

Install IntelliJ from here, and clone the latest Jenkins core source code from here (you can also fork it before cloning). In this tutorial, I have used IntelliJ IDEA Version 2019.3.1.

2. Setting up IntelliJ IDEA

Open IntelliJ IDEA.

Click on Import Project, and in the popup, choose the directory where Jenkins had been cloned.

Select ‘Create project from existing sources’, and click on Next.

Click on Next

Click on Next

Click on Next

Click on Finish. IntelliJ should be ready like below.

3. Building Jenkins

Now we want to build Jenkins. Run the following: (This will prepare the jenkins.war file without running tests)

mvn -am -pl war,bom -DskipTests -Dspotbugs.skip clean install

This may take a little time. If everything works well, you should get a successful build result like below:

Now, we can run Jenkins on our local machine using the following command:

mvn -pl war jetty:run

If it runs successfully, you should be able to view Jenkins console by going to http://localhost:8080/jenkins/

4. Debugging

Now, our next goal is to be able to debug jenkins by using breakpoints in IntelliJ. Close the previous running instance by (Ctr+c).

In the toolbar, go to Run -> Edit Configurations…

Click on the ‘+’ icon so we can add a new configuration.

Click on ‘Maven’.

Ensure that this configuration as same as above. Click on Apply and OK.

Now, you can choose either Run ‘Maven Run’ or Debug ‘Maven Run’ based on what you would like to do. Breakpoints can easily be applied alongside the code in the IDE.

Moreover, Groovy/Jelly views are re-compiled every time a browser requests a page, so the changes can be observed with just a simple browser refresh. This is also true for help files.

Also, you can run ‘Build’ in IntelliJ to hot-swap code, which means that some changes like method bodies and annotations changes will take effect without having to restart Jenkins.
[Mal Series #8] PE Fixing & Unpacking
Tags: Malware, Cybersecurity, Debugging, Reverse Engineering, Malware Analysis

In this blog, I will discussed some of the technique that can be used when we encountere with the corrupted PE or IAT obfuscated samples.

1. Obfuscated IAT

Sample: Mugatu.exe (FlareOn 2019 Chal 10, writeup pdf)

As state in the writeup given, the original import thunks has been reversed in the memory. In order to beat this kind of obfuscation, we can use Scylla to dump out the executable after the import address table has been fixed. Once the IAT has been fixed, the API will be resolved 😎 and appears again in the static decompiler tools.

You may refer to the screenshot below for the guidance. ✌

How to Scylla dump a PE

Before

After

It can see that the decompiled code after the deobfuscation function makes more sense than before. 😃

Afterwards, it will need to rebuilt the IAT to get the second payload (In this case PE-Sieve will comes in handy). Will leave this to the those are interested.

2. PE Unpacking

Sample: Refer to [Mal Series #7]

For the payload unpacking, I will mention on the common one that I used often, which is placing breakpoint on the common Windows API to let it unpack itself. Here comes the famous guys 🎉 VirtualAlloc , VirtualAllocEx , WriteProcessMemory , VirtualProtect 🎉

Other than that, there are a lot of unpacking method for different packers such as UPX (Finding the far jump to the entry point of the code) etc.

3. Corrupted/Misaligned PE

Sample: Refer to [Mal Series #7]

When Windows loads a PE file, it will try to map the address of the physical address to memory address.

Mapping (Translate from physical address from disk to virtual address, usually refer to memory address).

When we dump the payload out of the memory, it might require to unmap the dumped files so it can interpret by the static analysis tools correctly. Usually just to make the sections can be continuously read by the tools by merging those padded section into one. E.g:

Raw Data Size of a section 1 = VA Section 2 - VA Section 1

In order to do that, we will use PE-Bear to fix the alignment of the PE section headers. Make sure Raw Address align with Virtual Address in this case after aplied the calculation above for each section.

Repeat this for the rest of the sections and you will see something afterwards.
API Logging using Middleware in Laravel
Tags: Middleware, Logging, Debugging, Laravel, API

Have you ever been in situation when you wanted to log a specific API to debug an issue in running production application API?

Here is the easiest way to do that using middleware.

If you would like to watch it step by step then you can watch this tutorial.

Let’s start!

What is middleware?

Middleware provides a convenient mechanism for filtering HTTP requests entering your application.

You can think of middleware as a series of “layers” HTTP requests must pass through before they hit your application. Each layer can examine the request and even reject it entirely.

Create a middleware using command

php artisan make:middleware LogRoute

Open LogRoute.php

It has a simple handle function here which is taking in request and passing it to next Closure.

Write your logic for the information about API that you want to log like this:

Open Kernel file. Assign a key log.route to your middleware.

protected $routeMiddleware = [

...

'log.route' => LogRoute::class

];

Open api.php

Set middleware on the route that you want to log.

Route::get('me', 'AuthController@me')->middleware('log.route');

That’s It!

Now try calling your API using a rest client like Postman or Any application consuming the API and you will see them being logged into your storage/logs/laravel.log file.

You can get the entire code here.
How to remote debug using software failure replay
By: Undo Bytes
Tags: Remote Working, Software Development, Software Engineering, DevOps, Debugging

With new social distancing measures and most people now being advised to work from home, what do you do when a key customer reports a failure with your software in production?

Traditional production troubleshooting

Today, your debugging workflow might look like this:

Get initial description of problem from customer

If issue cannot be resolved remotely, send Field Application Engineer or developer on customer site

FAE or dev reviews issue, using artefacts such as logs or core dumps

If issue cannot be resolved at this point, an R&D engineer is assigned

Logs, core dumps and/or other information is fed back to the R&D engineer for debugging

R&D engineer makes a new build containing a speculative fix based on the limited information available and waits for feedback from customer

FAE or dev deploys the new build at the customer site

Depending on customer feedback, the issue is resolved or another iteration of the workflow takes place

FAE or dev confirms fix has resolved the issue and closes support ticket

The guesswork that needs to be spent on speculative bug fixing of this kind is time-consuming and frustrating for everyone involved.

A new world order

In the current climate, you can no longer send your engineers on customer sites. So how are you meant to diagnose and resolve production issues if you can’t access the live environment?

Software failure replay systems offer a solution. Imagine a CCTV camera recording an event. You don’t have to be in the same place at the same time as the recorded event to see what happened. A recording file is produced which can be subsequently replayed and reviewed to figure out what happened.

LiveRecorder is based on this next-gen diagnostic technology. It can capture a failed process (down to instruction level) for offline replay.

Here is how it works when LiveRecorder is embedded into your product when you deploy:

When things go wrong in production, ask your customer to activate LiveRecorder to capture the failed process inside a recording and send you the file (note: the recording serves as a standalone reproducible test case)

The customer sends you the recording file for you to replay the original environment and debug

After analyzing the recording by stepping forwards and backwards in the code execution, you can determine the root cause of the issue, develop a fix, and deploy that fix!

Go get yourself a well-deserved coffee and get on with developing the feature you were working on before you got interrupted.

The beauty of a recording is that you don’t have to waste time trying to reproduce the problem. The recording represents a 100% reproducible test case. And that recording can be debugged offline, in the comfort of your own home/office. Once the failed process is recorded, you can relive the defect — without impacting the live environment.

LiveRecorder enables engineering teams to debug remotely and debug faster than with traditional debugging methods — allowing business to continue for both software vendors and their customers.
New debugging possibilities with Ivy and Angular 9
By: Alexander Martens
Tags: Developer Productivity, Developer Tools, Debugging, Angular Ivy

ivy compiled html-template

Angular 9 now compiles your html-templates to plain js as displayed in the image above. Check out this talk https://www.youtube.com/watch?v=wWQeMD38n2k&feature=youtu.be&t=291 for a good explanation of what that looks like.

This new compiling strategy opened up at least two novel ways to debug apps.

the ng object

You can debug current states of your components with the aid of the new ng object. It is available in the browser while running an ivy-compiled angular app in dev mode.

Find the selector of your component, i.e. “app-root” and query the html of your app for the according node. Do that by calling “document.querySelector” with it or find the tag by yourself, mark it and use $0 in the console.

$0, $1, … store the last selected nodes by the way.

Now call ng.getComponent with the node you found as the parameter. I suggest putting the result into a variable. Now you have access to your component. If you make a change to your component don’t forget to call ng.applyChanges on it in order to trigger a change-detection cycle.

2) Debugging ExpressionChangedAfterChecked Errors

Compiling html to js also provides improved error messages for template errors like the infamous ExpressionChangedAfterItHasBeenCheckedError. In Angular 8 it used to point you to the html file with the info that some value was undefined and is now something else after it was checked.

In Angular 9 the message hasn’t changed much but you can now navigate to the exact spot where the error occurred as you can see in the following image.

You can even debug your way through the — in this case “late” — interpolation. For that purpose they even put a “debugger;” into the function that throws ExpressionChangedAfterChecked Errors.
JavaScript Console Object
By: Johnnie Gonzalez
Tags: Tips, Debugging, JavaScript, Programming, Console

Photo by Boitumelo Phetla on Unsplash

JavaScript console is a command line interface that is used in your browser that executes snippets of code. It is highly useful in finding errors in your code in an attempt to debug them. I have used it plenty of times to test my code to see whether or not I was receiving the right data that I was calling within a fetch method to a specific API. It can also be used to view specific changes to variables, states, and messages to make sure your program is working as expected. Recently I have been using them in learning algorithms and data structures to make sure I am implementing the right code to get the desired end result. You can use them in numerous ways in the JavaScript console. Here are some ways you can use the console.

These are the directions to open the console depending on your browser.

Firefox: Menu Bar > Tools > Web Developer > Web Console

Chrome: Customize and Control Google Chrome > More Tools > Developer Tools

Safari: Safari Menu > Preferences > Advanced > Checkbox “Show Develop Menu” > Develop Menu > Show Error Console

It should look like so…

Now there are many different ways you can use the console. Mostly the ways that are extremely new to me because for the most part all I ever knew was “console.log()”.

Console.log()

Outputs a message to the console…

2. Console.warn()

Outputs a warning message to the console…

3. Console.error()

Outputs an error message to the console…

4. Console.clear()

Clears the console…before…

after….

5. Console.count()

Logs the number of times that this particular call to count() has been called…

6. Count.table()

Displays tabular data as a table…

7. Console.time() & Console.timeEnd()

Starts and stops a timer…

8. Console.group() & Console.groupEnd()

Creates a new inline group in the console…

There are more console methods you can use these are just a few I thought were pretty cool. Below are my resources. Thank you for reading!!!!
Debugging — The Process. Phase 2 was packed with a ton of…
By: Lawrence Chesbro
Tags: Coding, Ruby, Dsl, Debugging, Sinatra Project

Phase 2 was packed with a ton of things. It was almost overwhelming, but overall they were super interesting topics. They are almost oversimplified by all of the fancy gems we are able to use. It is easy to overlook a couple steps because some gems do so much for us, like corneal, and ActiveRecord.

In the beginning of my Sinatra Project for Flatiron I decided to build the scaffolding without Corneal. I wanted to create most of the files, add necessary gems, set up my config folder, I wanted to fully understand why and how my application was working. A couple of the Gem’s I decided to use that gave me some issues were, ‘Rake, and Sinatra’. Sinatra handles rendering the website, giving us the option of choosing what file to render for each route. Rake is used to handle the database, everything from creating tables to supplying the database with information. Starting from scratch came with a few caveats; rake itself does not have any predefined tasks, the session hash is not available to class methods or outside of controllers, and lastly setting up the public folder took me way too long.