Where It All Started.

Where It All Started.

Life, Stock Trading, Investments, Business and Startup. Most are programming stuff.

Tag: linux

Checkout Specific Directory Within Git Repo

I believe that the first test of a truly great man is his humility. Really great men have a curious feeling that the greatness is not in them but through them. And they see something divine in every other man and are endlessly, incredibly merciful.

— John Ruskin.

One day I was working on a driver port to macOS (Apple Macintosh OS) and the only opensource code for it can be found on Linux kernel.

Heck! The Linux kernel repository is around 2GB including all history and I only needed a specific directory inside the repository. After searching the whole internet I found an answer1.

Here are the steps to clone a specific directory from a git repository:

  1. First and foremost you need to create a local blank repository on your workstation. git init <repo-url>
  2. Inside the created bare repository, map the remote URL of the remote repository you want to clone. cd <repo-name> git remote add origin <remote-repo-url>
  3. Then, setup the git config and specify that you’ll be doing a sparse checkout. git config core.sparsecheckout true
  4. Create and add all the directories you want to checkout in the sparse-checkout file that can be found in .git/info/sparse-checkout. echo "<needed-directory>/*" >> .git/info/sparse-checkout
  5. When all the above steps is done, finally pull the repository objects. git pull --depth=1 origin master

So guys if you have any questions? hit me up on my social media accounts. That’s all there is that is needed. Now its already cloned and can now be worked on.

❌ Originally posted on August 5, 2019.


  1. https://stackoverflow.com/a/28039894 ↩︎

Disable mDNS and SSDP Discovery in Google Chrome

We’re born alone, we live alone, we die alone. Only through our love and friendship can we create the illusion for the moment that we’re not alone.

— Orson Welles.

If you ever check your task manager you’ll notice chrome is listening to port 5353 on Linux. Did you know you could stop it? as what this sub-process is specifically doing – listening and doing some device probing like an auto discovery which is similar to avahi. In order to disable this Chrome functionality you need to first create a directory and policy file. You could do this by executing the command below.

sudo mkdir -p /etc/opt/chrome/policies/managed/
sudo touch /etc/opt/chrome/policies/managed/block_mdns_ssdp.json

What this does is first create a directory inside the /etc/opt/chrome which will be used to store manage policies and create the initial policy file that we would be editing.

Then we edit the block_mdns_ssdp.json file that we created earlier and then we put the contents below.

{
	"EnableMediaRouter": false
}

This would specifically disable media router and probing of cloud printers utilized by Chrome.

NOTE: Don’t disable this functionality if you use cloud printers.

So to conclude there are some hidden sub process/services Chrome is running under the hood to manage specific Chrome functionality. So guys, what functionality or sub-process you want to disable inside Chrome? Let me know and as always live life and hope you enjoyed this article!

Check Total File Size of Files with Specific File Extension

Posted on by Edward Fitz

It is simply this: do not tire, never lose interest, never grow indifferent—lose your invaluable curiosity and you let yourself die. It’s as simple as that.

— Tove Jansson in Fair Play.

Recently, I wondered on how to check the file size of all files with a specific file extension on a folder / project. This is what I’ve found out after several experimentation using command line tools in Linux, this specific task could be accomplish with just one line of command. Check below for the actual command:

find . -name "*.dart" | xargs cat | wc -c

What this command does, is first find all file with the dart extension. Then pipe the output of that command in xargs converts the standard input to command arguments. After that pipe the output of xargs again to our favorite word counter wc.

Here are the command line tools use in the process.

  • xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command. Some commands such as grep and awk can take input either as command-line arguments or from the standard input. Wikipedia
  • find is a command-line utility that locates files based on some user-specified criteria and then applies some requested action on each matched object. Wikipedia
  • wc is a command in Unix and Unix-like operating systems. The program reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow. Wikipedia

That’s it!

So guys, do you have any one-liner commands that you want to share? Just message me on my social media accounts. Hope you guys enjoyed this article!

Fixing GTK Dark Themes on Firefox

The world is a comedy to those that think; a tragedy to those that feel.

— Horace Walpole.

If your using Linux and run Firefox1. One thing you will notice on Firefox when on a dark themed GTK2 based environment in Linux is the HTML content would adapt to the theme color.

And for some reason I don’t know why Firefox still doesn’t fix this stuff. Here is the link related to the issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1527048

UPDATE: Seems this problem has been fixed in Version 67 of Firefox.

Here is the workaround for it:

  1. Open about:config inside Firefox. You should type this in the URL bar.
  2. Right click on the content and click New > String with key widget.content.gtk-theme-override and value Arc-Darker.
  3. Restart Firefox.

The steps above would set Firefox content to adapt to white based theme while retaining chroma theme dark. You could also use Adwaita as value.

So guys, have you ever encountered this bug specifically in Gnome 3 while using Firefox? Hope you guys enjoyed this article and as always live life!


  1. Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, Mozilla Corporation. Firefox uses the Gecko layout engine to render web pages, which implements current and anticipated web standards. ↩︎
  2. GTK is a free and open-source cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU Lesser General Public License, allowing both free and proprietary software to use it. ↩︎

Disable Snap Daemon in Archlinux

Carry out a random act of kindness, with no expectation of reward, safe in the knowledge that one day someone might do the same for you.

— Princess Diana.

One day I woke up and I just don’t want to use Snap apps anymore. So how do I remove it from my workstation? Here are the things I’ve did to completely removed it from my workstation.

In order to disable Snap apps on your workstation you must first list all snap services and the included PID (Process Identifier) sockets running.

systemctl list-unit-files | grep snap

After you listed all of it, you must disable all known snap services. Below is just a gist of running snap services on my workstation (on Fedora Linux).

sudo systemctl disable snapd.service  
sudo systemctl disable snapd.seeded.service  
sudo systemctl disable snapd.socket  
sudo systemctl disable var-lib-snapd-snap-core-6130.mount

After you completed the steps above you must then restart your workstation for a much more cleaner startup.

So guys, if you have any problem running the above command let me know? That’s it guys as always live life and hope you enjoyed this article!

Debugging PHP with Xdebug over SSH

The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.

— Winston Churchill.

Back in days before Xdebug1 came to light, debugging PHP2 was pretty simple like in C3 on which you use print or var_dump. Today with improving tools and setup, PHP can now be debugged remotely with the help of ssh + xdebug.

To do this first you must connect to the remote development station on where PHP server is located (e.g. PHP direct dynamic server, Nginx, Apache HTTP).

ssh -R 9000:localhost:9000 [email protected]_goes_here

The -R stands for return remote callback connection on SSH on which server --(poll)--> host (xdebug server).

After running a remote port forwarding you will need to setup xdebug on the remote server, point it on which address it would bind and listen. For my use case I’d point mine to the loopback address 127.0.0.1 (as I’d only use it for development purposes) on which we setup remote port forwarding to listen to. Edit the php.ini file and at the xdebug configuration make it similar to the sample below.

[xdebug]
zend_extension="/usr/lib64/php/7.1/modules/xdebug.so"
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log=/tmp/xdebug_remote.log
xdebug.remote_connect_back=0

The most notable part in the config is the xdebug.remote_host and xdebug.remote_port, this is where xdebug would bind. After all the changes have been done, just restart the server (e.g. for Apache HTTP running on CentOS).

service httpd restart

And at our workstation editor with PHP debugger extension we would just point it to 127.0.0.1:9000. That’s all now we can debug PHP remotely.

🧡🧡🧡🧡🧡

Hope you guys enjoyed this article!


  1. Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol. ↩︎
  2. PHP is a general-purpose programming language originally designed for web development. It was originally created by Rasmus Lerdorf in 1994; the PHP reference implementation is now produced by The PHP Group. ↩︎
  3. C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. ↩︎

Solidity Series – Building Your First Hello World

Knowing others is wisdom, knowing yourself is enlightenment.

— Lao Tzu.

It’s the start of decentralization age but how to start programming on decentralize environment?

Ethereum1, considered as second wave of blockchain innovation. The pioneer and first blockchain ecosystem to implement and handle smart contracts. So how do you start developing system and application DApps (Decentralize Apps) in it?

The answer is “Solidity” — a programming language that interface EVM (Ethereum Virtual Machine) and your app.

Prerequisites

In this tutorial we assume you have some basic knowledge in programming.

The main requirements in developing a blockchain app is first its compiler then the secondary requirements but optional are the bootstrap framework like truffle.

  • Node 10 and above

Building Hello World

To start the development, we must get the required dependency in developing a structured smart contract project. The tool and framework that we will be using is truffle, which handles all the bootstrapping procedure and creates the base of your project. Installing it is just breeze, all you have to do is type npm install -g truffle.

Also install ganache which is the old ethereum-test-rpc project. To install ganache you have an option whether to install it on a desktop or a CLI (Command Line Interface) build. For this project I’ll be using the CLI build, so to start we install ganache using the command npm install -g ganache-cli. Both truffle and ganache is under the truffle software development platform.

And now we start building the project, after all dependencies installed we need to create an empty project directory with the command truffle init. As a note, the init sub-command only works on an empty directory. This sub-command will create a base structure for our project.

Project Structure

Below is a structure that I recommend to bootstrap your project.

  • contracts: Storage of smart contracts source.
  • migrations: Migration script to deploy smart contract.
  • test: Test directory for smart contract.
  • truffle-config.js: Truffle configuration for Windows users (for backward compatibility).
  • truffle.js: Truffle configuration for *nix system.

To test if everything’s okay we must run truffle compile.

Running a test RPC for Ethereum

So in order to start, we first need to generate test accounts and run a test environment. Start by typing ganache-cli in a separate non-occupied terminal window. The tool ganache will generates 10 ETH addresses with an initial balance of 100 ether.

Coding your first hello

With ganache-cli running at background, we continue building our hello world project. To start, we must create a new contract using truffle create contract Hello on which this command will create a new file under contracts ⇒ Hello.sol. Edit the newly created file and add a new function that will return the string Hello in EVM.

pragma solidity ^0.4.24;

contract Hello {
	function greeter() public pure returns (string) {
		return "Hello World";
	}
}

In the next step, will be creating and editing the migration file. To create the file execute touch migrations/2_deploy_contracts.js, then edit the new file and link that to the file we created earlier Hello.sol. This is a very crucial step in order to deploy our Hello solidity file on test blockchain environment.

Here are the changes we need in migrations/2_deploy_contracts.js.

var hello = artifacts.require("./Hello.sol");
module.exports = function(deployer) {
	deployer.deploy(hello);
}

After we edit the migration file, we can now connect the truffle project to ganache test blockchain RPC environment. To do that we’ll be editing truffle.js and point it to ganache host and port which is localhost:8545.

module.exports = {
	networks: {
		development: {
			host: "localhost",
			port: 8545,
		},
	},
};

When everything’s done, execute truffle migrate. This command will automatically compile and deploy the smart contract into ganache test blockchain RPC environment. Remember and copy the Hello function address in the output console, we will be using this later.

To test the function if its already deployed in the test environment, we will execute a REPL console using truffle console. Then inside the console, we type Hello.at(address).greeter() (note the address here is the one we copy earlier).

If everything is correct it should output Hello World. That’s it, now you’re on your way to become a blockchain developer.This is the link to the whole source code.

Conclusion

Hey guys, now that you’ve finish the setup you are now on the path of becoming a blockchain software developer. Follow us on our next adventure developing deep into the blockchain ecosystem. Stay tuned for the next follow up series for solidity.


  1. Ethereum is an open source, public, blockchain-based distributed computing platform and operating system featuring smart contract functionality. It supports a modified version of Nakamoto consensus via transaction-based state transitions. ↩︎

Flutter Series – Creating Your First Hello World

When you can’t find the sunshine, be the sunshine!

— Anonymous.

Have you ever dream of building your own app, but think its too hard. Why don’t you try flutter…​

Flutter is a new way to build multi-platform app which is currently backed and develop by Google. Its often compared to react native, but the difference is performance. React Native runs on JavaScript bridge while Flutter on dart bridge. What dart bridge does best is AOT (ahead of time) compiling to native ARM code.

Prerequisites

First of all you need flutter, just follow the steps below in order to run install it.

  • Flutter 1.0

Building Hello World

First we will install flutter, depending on your operating system you could find the details on how to install flutter here. On arch Linux you could find it on AUR repository.

After installing the flutter package. Run flutter doctor to check for any dependency error.

And now we begin, to start a flutter project you need to type in flutter create <project-name>. For example I’m building a hello world project named stocks.

flutter create stocks

The command will create a directory named stocks which contains minimal running app template. What we do first is open the file lib/main.dart using your favorite text editor and rename the app title Flutter Demo to Hello World. Then remove the whole Scaffold block as we will create our own scaffold. After the changes your _MyHomePageState class would look like this.

// ....
class _MyHomePageState extends State<MyHomePage> {
	int _counter = 0;
	
	void _incrementCounter() {
		setState(() {
			_counter++;
		});
	}

	@override
	Widget build(BuildContext context) {
		return Scaffold();
	}
}
// ....

Clean up the unused functions and variable like _counter and _incrementCounter. If your editor has integrated linter and dart analyzer it would complain regarding unused variable. Once cleanup’s done, implement now a centered hello world text by adding body to the scaffold.

class _MyHomePageState extends State<MyHomePage> {
	@override
	Widget build(BuildContext context) {
		return Scaffold(
			body: Center(
				child: Text('Hello World!'),
			),
		);
	}
}

Now run your code using the command flutter run. If a device’s connected it will show an app displaying a centered hello world. You could also use an emulator by running flutter launch before running flutter run.

So what’s next?

Now after everything’s done, we will continue building our stocks monitor app on the next chapter. Stay tuned. Hit like if you like, subs if you love and as always live life.

Creating A Browse-able Virtual File Archive In Linux

In Linux, there are many ways to create a virtual file archive. A virtual file archive is a storage file which immitates an inode storage device, meaning its similar to what a physical drive can do but contained in a single archive. So how do we create this virtual file archive? What we will be using is the most primitive way to create a virtual file archive using Linux built in tool set.

The secret to happiness is freedom…​ And the secret to freedom is courage.

— Thucydides.

Prerequisites

The tooling that we will be using is already built in Linux. To be transparent what I’m currently using is Arch Linux.

  • dd
  • losetup
  • mount

So what do we do now?

Create the file that will be using as file archive.

dd if=/dev/zero of=gem.bin bs=1024 count=0 seek=1G

Setup a loop block device to handle input/output (emulating physical drives).

losetup /dev/loop0 gem.bin

Create the mountable directory.

mkdir -p /mnt/vfa

Mount the loop block device to the mountable directory.

mount -t ext3 /dev/loop0 /mnt/vfa

So guys, if you like this article hit like and subscribe. Hope you guys, enjoyed this article and as always live life!

Fun Fact

  1. losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device. If only the loopdev argument is given, the status of the corresponding loop device is shown.
  2. dd is a command-line utility for Unix and Unix-like operating systems, the primary purpose of which is to convert and copy files.
  3. mount command serves to attach the filesystem found on some device to the big file tree.

Changing Xserver Default Applications Using XDG Tools

XDG (freedesktop.org) which stands for X Desktop Group is a group which develop the X11 and xdg utilities which currently runs as barebones of linux desktop. So how do we change the defaults when opening a file on XServer?

Be free, and live life fully.

— Caroline Shaw.

So how do we configure XDG?

Tools that we will be using to configure xdg can be found in xdg-utils package (utilities like xdg-settings and xdg-mime).
So to set the default application to open a certain mime type, you need run the code below:

xdg-mime default Thunar.desktop inode/directory

The command above would add the new mime application settings to ~/.local/share/applications/defaults.list. It basically tells xdg-mime to open a directory using Thunar (XFCE filemanager).

Fun Fact

  1. freedesktop.org (fd.o) is a project to work on interoperability and shared base technology for free-software desktop environments for the X Window System (X11) and Wayland on Linux and other Unix-like operating systems. It was founded by Havoc Pennington, a GNOME developer working for Red Hat in March 2000. The project’s servers are hosted by Portland State University, sponsored by Hewlett-Packard, Intel, and Google. ↩︎