3 things you need to start scripting

Do you want to learn how to script? Do you want to make your own web app? You need to get started on scripting something.

At least you need the followings as the bare minimum to get you started.

1. Scripting Language

Choose the scripting language you want to work with. Some of the example scripting languages you can use are: Python, Go, JavaScript, PHP.

Choose something suits your needs. If you are doing more data science work, you might want to choose Python. If you are doing back-end work, most of the scripting languages I mentioned here would work but you might want to explore Go. For front-end, you might want to check out JavaScript with the use of some frameworks. Do also some research which scripting language(s) suite your needs. In below link, it shows the comparison between scripting languages. You might want to consider the community supports that language. More stronger the community is, higher the chances more libraries are available.

JavaScript vs. Python vs. Go (stackshare)

https://stackshare.io/stackups/go-vs-javascript-vs-python

2. IDE

Next, you need to decide which IDE to use. IDE is stands for Integrated Development Environment. You can use Notepad or some Text Editor application but it is way more efficient to use one of the IDEs.

There are tons of IDE out there but you need to find the IDE suits you and your language. There are IDEs you need to purchase but also there free IDEs which have decent features and functionality. I personally choose Visual Studio Code by Microsoft for couple of reasons.

  • free, open source
  • relatively lightweight
  • supports multiple languages
  • supports multiple OS platforms (Mac, Windows, Linux)
  • customizable and more…

Let’s dig a little bit more on some of the reasons I listed.

Free, open source / lightweight

This is no brainer. Especially if you are on budget, you are tend to rely on open source app but you don’t want to sacrifice your efficiency. Visual Studio Code does not comprise developer’s efficiency.

It is also lightweight that footprint is relatively small. Easy and very quick to install.

Supports multiple languages and multiple OS platforms

It is important for me to focus on one IDE but that IDE needs to be able to handle multiple scripting languages seamlessly. Some IDE needs to install separate add-ons / plug-ins or even separate app. Visual Studio Code by far can handle multiple languages with less friction.

It also supports multiple OS platforms. This is very helpful as sometimes you might be on Mac or Windows or on Linux but you want to have a IDE which is you are familiar with. Using Visual Studio Code, you can switch around OSs without compromising your efficiency dealing with different IDEs.

I mainly focused on Visual Studio Code but you may explore other options such as Atom, Eclipse.

Repository (Repo)

Once you decided the scripting language and IDE to use. I would recommend to setup your private repository on either Bitbucket or GitHub.

What is Repo and why you need it?

Repository or short for Repo is your bestfriend when developing an app. It is a place where you put your codebase and it gives you couple of benefits such as below to list a few.

  • Version Control
  • Sharing Codes (personally or group)

Version Control is very useful. For example, you want to add new feature but you do not want to affect your main codebase, you can create a “branch” where you develop your new feature, test it before you merge back to the main branch. It is also useful to rollback your code. Sometimes, things may go wrong. Version Control will give you an ability to rollback to the previous commit(s) to correct the mess you created.

Sharing Codes also a big advantage. You might be working on couple of different workstations. Having a common repo, you can share your own codebase in multiple work environment. Not to mention, it is also very effective on team collaboration work. Some developer can work on one feature and other on another feature, at the end of the day, both of them can push their codes to the repo.

Wrap Up

In this post, I put the bare minimum things you need but it is not limited to those things as you continue to develop your app. Down the road, you might be needing a web hosting, or you might need to setup a database. This is all depends on what you will develop but with above, at least you can get started get your hands dirty.

How to embed GitHubGist Code into your WordPress

Background

Have you ever wondered what is the best way to share the coding work you’ve done? Have you thought about you want to share only the part of your codes or perhaps he full details of your code?

Have you had an experience on looking for a WordPress Plugin to support the code format?

One option to maintain this less difficult is to use the GistPress plugin. Thanks to this website, By using the GitPress plugin, you can use the WordPress ShortCode block to embed the code written in GitHubGist.

Setup

  1. Install the GistPress plugin and activate it. (Refer to this site on how to install WordPress plugin)
  2. Create a new GitHubGist file here. (Make sure you have a GitHub account)
  3. Once you have completed your coding in the GitHubGist, make that file a public gist by clicking the “Create a public gist)
  4. Once the Gist file is created, it should have generated a custom URL. You will need the id portion of it. (e.g. https://gist.github.com/[username]/4509aa990c4fdfd301869693c7f1c9bf
  5. Keep that id.

Embedding the full code

Once you have the file created in GitHubGist, you can embed the GitHubGist Code into your WordPress by using the WordPress Shortcode block. Create a new block in WordPress and enter such as below:

gist id="4509aa990c4fdfd301869693c7f1c9bf" 

Note: don't forget to wrap with the bracket []

This will embed your code as below:

def foo():
a = 'test'
return a
view raw foo.py hosted with ❤ by GitHub

Highlighting the line(s) in the code

You can also use highlights by adding highlight=”[line]” parameter in the short code. Such as:

gist id="4509aa990c4fdfd301869693c7f1c9bf" highlight="2"

gist id="4509aa990c4fdfd301869693c7f1c9bf" highlight="2-3"

Highlighting a single line (use highlight=”[line]”)

def foo():
a = 'test'
return a
view raw foo.py hosted with ❤ by GitHub

Highlighting multilines (use highlight=”[starting line]-[ending line]”)

def foo():
a = 'test'
return a
view raw foo.py hosted with ❤ by GitHub

If you want to just show the portion of your code, you can limit the lines you want to display by using the lines=”[starting line]-[ending line]”

gist id="4509aa990c4fdfd301869693c7f1c9bf" lines="2-3"
a = 'test'
return a
view raw foo.py hosted with ❤ by GitHub

Daily Coding Problem – cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair.

Daily Coding Problem sends daily coding problem sample when you subscribe to their service. This service is very useful to practice your coding ability and think through the logic you will be using to solve the problem.

Problem

This problem was asked by Jane Street.

cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair.
For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4.

Given this implementation of cons:

def cons(a, b):
    def pair(f):
        return f(a, b)
    return pair


Implement car and cdr.

Context

So what is car and cdr anyway? You can check out some more details about car and cdr in Wikipedia.

A cons cell is composed of two pointers; the car operation extracts the first pointer, and the cdr operation extracts the second.

Solution

For the solution for this problem, I reference the code from this github.

Code Example

def cons(a, b):
    def pair(f):
        return f(a, b)
    return pair

def car(cons):
    return cons(lambda a, b: a)

def cdr(cons):
    return cons(lambda a, b: b)

print(car(cons(3, 4)))
print(cdr(cons(3, 4)))

Sample Code Download

Download from here