teleren/devto huggingface dataset:
Koa middleware for serving static files
Tags: npm, node, koa
Published: 2015-08-12 13:19:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Koa middleware for serving static files
slug: koa-middleware-for-serving-static-files
date: 2015-08-12 13:19
published: true
tags:
 - npm
 - node.js
 - koa
---

Quite often I find myself using the same snippet of code over and over in projects for serving up static files as part of projects that use Koa. Today I exceeded my limit for copy pasting, so I've bundled this together into a module called `koa-serve`.

It's probably a lot simpler than `koa-static` but it works well for what I want and need.

    var koa = require('koa'),
        serve = require('koa-serve'),
        app = koa();

    app.use(serve('assets'));
    app.listen(8000);

You can also define where you root dir is, if isn't `__dirname`.

    var koa = require('koa'),
        serve = require('koa-serve'),
        app = koa();

    app.use(serve('assets', '/path/to/your/root'));
    app.listen(8000);

Example if your client files are in the parent directory, and index.js is in server/ for example:

    var koa = require('koa'),
        serve = require('koa-serve'),
        path = require('path'),
        app = koa();

    app.use(serve('assets', path.join(__dirname, '..', 'client'));
    app.listen(8000);

## Install it

    npm install koa-serve
    
## More links

GitHub: https://github.com/adamkdean/koa-serve  
NPM: https://www.npmjs.com/package/koa-serve
Node.js IsDirectory 
Tags: node, snippet
Published: 2015-08-12 13:12:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Node.js IsDirectory 
slug: node-js-is-directory
date: 2015-08-12 13:12
published: true
tags:
 - node.js
 - snippet
---

Here's a useful snippet for checking if a path is a directory in Node.js, this obviously requires('fs').

    fs.lstatSync(path_string).isDirectory()
    
Also available to you:

    fs.lstatSync(path_string).isFile()
    fs.lstatSync(path_string).isDirectory()
    fs.lstatSync(path_string).isBlockDevice()
    fs.lstatSync(path_string).isCharacterDevice()
    fs.lstatSync(path_string).isSymbolicLink()
    fs.lstatSync(path_string).isFIFO()
    fs.lstatSync(path_string).isSocket()
Customize User Login, Register and Forgot Password  Page in Drupal 7
Tags: drupal
Published: 2020-10-05 10:54:54

---
title: Customize User Login, Register and Forgot Password  Page in Drupal 7
published: true
date: 2015-08-11 00:00:00 UTC
tags: Drupal
canonical_url: 
---

Did you ever want to customize your registration or login page on Drupal 7, but did not know how? Customizing these pages by adding new text or changing theme is not a difficult task. To help you out with that, I have compiled some simple steps to customize your registration or…

   
[Read On](https://www.loginradius.com/engineering/blog/customize-user-login-register-and-forgot-password-page-in-drupal-7/)
Boot2Docker on WindowsでMinGWのパス変換を回避する
Tags: windows, docker, boot2docker
Published: 2015-08-09 03:20:00

---
title: Boot2Docker on WindowsでMinGWのパス変換を回避する
published: true
tags: Windows, Docker, boot2docker
date: 20150809T03:20Z
canonical_url: https://qiita.com/shiena/items/39bd32156b8d04ea5b92
---
WindowsのBoot2Dockerで`docker exec`のようなパスを渡すコマンドを実行すると以下のように失敗してしまいます。

```
$ docker exec -it 500e4b38e0fd /bin/bash
exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/Program Files (x86)/Git/bin/bash: no such file or directory
```

これはMinGWの[Posix path conversion](http://www.mingw.org/wiki/Posix_path_conversion)によってパスがいい感じに変換されてしまうためです。
このルールとエラーメッセージから`/bin/bash`は`C:/Program Files (x86)/Git/bin/bash`に変換されている事が分かります。
それではどうすればいいのかと言えば、パスの先頭の`/`を二重にすることで変換を抑制できます。

```
$ docker exec -it 500e4b38e0fd //bin/bash
root@500e4b38e0fd:/data#
```

MinGWの[Posix path conversion](http://www.mingw.org/wiki/Posix_path_conversion)はコマンドライン文字列のすべてに影響するので`-f`オプションなどでファイルのパスを指定する際も同様に対処が必要になります。
Common git commands
Published: 2022-07-18 08:10:20

---
title: Common git commands
published: true
date: 2015-08-06 20:00:45 UTC
tags: 
canonical_url: https://www.funkysi1701.com/posts/2015/common-git-commands/
---

I use git as my source control system. Here are some of the most common git commands in no particular order.

- Check Out a git Repository **git clone /path/to/repository**
- Add files to commit **git add <filename></filename>**
- Commit files to **git git commit -m “Commit message”**
- Push changes to server **git push origin master**
- Show status **git status**
- Create new branch **git checkout -b <branchname></branchname>**
- Switch to a branch **git checkout <branchname></branchname>**
- Get remote changes **git pull**
- Merge a different branch into the current one **git merge <branchname></branchname>**
- View merge conflicts **git diff**
- Temporarily stash uncommitted changes **git stash**
- Undo a commit **git reset –hard <commit></commit>**
- Show details about a commit **git show <commit></commit>**
- Show version history of current branch **git log**
- Gets all remote branches **git fetch origin**

Most of the time I use the [git extensions](https://sourceforge.net/projects/gitextensions/) tools to do my git work, but there are times when only the command line will do.
Writing better Git commit messages
Published: 2022-07-25 07:32:49

---
title: Writing better Git commit messages
published: true
date: 2015-07-25 20:00:45 UTC
tags: 
canonical_url: https://www.funkysi1701.com/posts/2015/writing-better-git-commit-messages/
---

![](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2015/07/git_commit.png?w=439&ssl=1)

I always use source control for my coding changes, however some of my commit messages leave something to be desired.

I always try to write a commit message but I often think that the change themselves should be enough to indicate what I did. I also don’t need to include who made the change or the time and date and that gets included automatically.

Here are some tips I have found that may help me in the future.

1. Ask yourself why you are making this change. The Who, When and What are already being covered so it is only the why that needs including in the commit message.

2. If your commit breaks something or causes side affects or a new dependency this should be included in the commit message. If your commit breaks functionality, consider if you really need to commit it yet, maybe only commit once fixed?

3. If your commit includes a long list of changes consider if the commit needs splitting into several commits. It is easy to only commit one or two files write a specific commit message and then commit the rest of the changes separately.

4. Consider including a subject for larger commits. The following comes from the git manual.

```
Though not required, it’s a good idea to begin the commit message with a single short 
(less than 50 character) line summarizing the change, followed by a blank line and then 
a more thorough description. The text up to the first blank line in a commit message 
is treated as the commit title, and that title is used throughout Git.

```

1. If you use a subject follow the following conventions:

- Limit of 50 characters
- Start with a capital letter
- Do not end with a full stop
- Use the imperative mood i.e. write as if issuing a command
Best practice for reviewing QQ app
Tags: sociallogin, qq
Published: 2020-10-05 10:55:01

---
title: Best practice for reviewing QQ app
published: true
date: 2015-08-04 00:00:00 UTC
tags: SocialLogin,QQ
canonical_url: 
---

QQ is the most popular ID provider for Chinese people since the 90s, it is always the first choice for websites who want to provide social login functionality for their Chinese users. But similar to other ID providers from China, the app you created needs to be reviewed before…

   
[Read On](https://www.loginradius.com/engineering/blog/best-practice-reviewing-qq-app/)
Useful git aliases
Tags: git
Published: 2015-07-31 14:58:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Useful git aliases
slug: useful-git-aliases
date: 2015-07-31 14:58
published: true
tags:
 - git
---

I've been so busy recently that this blog has been neglected. I'm planning on fixing some design quirks and adding in some archiving, maybe even giving it a biy of a face lift so it's not so drab. Something I don't want to happen is to have empty months when it comes to my archive so today is the last day of July and I'll show you what aliases I have in my git config.

    [alias]
        a = "!git add -A . && git add -u"
        ab = branch -avv
        dt = difftool
        s = status
        b = branch -a
        k = !gitk --all --select-commit=HEAD &
        r = remote -v
        rh = reset --hard
        pr = "!git add . && git add -u && git stash && git pull && git stash pop"
        logp = log -n10 --decorate --graph --pretty=tformat:\"%C(yellow)%h%Creset%C(cyan)%d%C(reset) %s %C(green)(%an, %ar)%C(reset)\" --relative-date
        diffp = diff --ignore-space-at-eol -b -w
        llm = log -1
        unadd = reset --
        ua = reset --
        h = rev-list --max-count=1 HEAD
        list-merge-backups = !git status -su | grep -e'\\.orig$' | cut -f2 -d' '
        delete-merge-backups = !git list-merge-backups | xargs rm
        mergefrom = merge -s recursive -X theirs

Well, that was an easy blog post, but I can't use git without these, they save a lot of time!
Firewalld blocking snmp and fixing it (with Ansible)
Tags: centos, firewalld, snmp, ansible
Published: 2019-08-08 12:48:25

---
title: Firewalld blocking snmp and fixing it (with Ansible)
published: true
tags: centos,firewalld,snmp,ansible
canonical_url: https://www.zufallsheld.de/2015/07/27/firewalld-snmp-ansible/
---

Some time ago I had to use a new CentOS 7 virtual-machine for some things that aren’t relevant to this post. This machine had to run all the time but also had some problems with a sporadically failing application server. That’s why I decided to monitor the machine, starting with some basic snmp-monitoring.

When I added the host to my Icinga monitoring, Icinga failed to do the snmpwalk. After some searching on the host I found out that the default firewall _[firewalld](https://fedoraproject.org/wiki/FirewallD?rd=FirewallD/)_ was blocking access; something I did not have to deal with yet until this moment. But instead of simply turning the firewall off, I decided to permit snmp-access.

Reading the very good and comprehensive [RedHat documentation](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html) about _firewalld_ gave me enough information to allow access of the host. It also showed me that there’s no predefined service (at the time) for handling snmp-traffic so I had to add the exceptions to the firewall by myself.

This is the command:

```
[root@centos ~]# firewall-cmd --add-port=161-162/udp --zone=public
```

This means that the portrange 161-162 with the protocol UDP is added as an exception to the public zone (the default zone). To learn more about zones, take a look [here](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html#sec-Understanding_Network_Zones).

After testing that the new rule works, I had to make the changes permanent. This is done by simply adding a _—permanent_ to the first command:

```
[root@centos ~]# firewall-cmd --add-port=161-162/udp --zone=public --permanent
```

Knowing that I’d have to do this more often when deploying new boxes, I decided to write a simple [ansible](www.ansible.com)-playbook for it. Of course there’s a [module](https://docs.ansible.com/ansible/firewalld_module.html) to configure _firewalld_! Sadly the documentation only gave examples on how to add single ports or services, not port ranges. But I thought that adding a range should be possible too, so I just tried it and it worked! Here is the task:

```
- name: add snmp-exception to firewalld
  firewalld: 
    port: 161-162/udp
    permanent: true
    state: enabled
```

Since Ansible is an open-source project I decided to contribute to it and create a [pull-request](https://github.com/ansible/ansible-modules-extras/pull/114) to add the missing documentation and an example. This way I can help the community around Ansible without having to dive deep into the code itself!
7 Warning Signs that you’re a Bad Programmer
Published: 2022-08-02 10:42:48

---
title: 7 Warning Signs that you’re a Bad Programmer
published: true
date: 2015-07-23 20:00:45 UTC
tags: 
canonical_url: https://www.funkysi1701.com/posts/2015/7-warning-signs-that-youre-a-bad-programmer/
---

![](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2015/07/you_are_coding_it_wrong.png?w=359&ssl=1)

Am I a good programmer or a bad programmer?

Here are 7 signs that might mean you are more towards the bad end of the scale.

1. You fail to plan before you start coding

I am very guilty of this, I love to jump into the code before thinking. But I am slowly starting to see the advantages of sketching a few things out before I write any code.

Most of my coding recently has been SQL based and I am starting to like sketching out table designs.

1. You fail to use version control

I have blogged about using version control in the past but it really is a very useful technology. It not only keeps track of every file in your solution and stores its entire history, but you can separate different versions into branches and see who changed what and when (and if the commit message is detailed enough why).

1. You use bad variable names

Whats wrong with variable1 and variable2 as variable names? Variables should be named after what they do or what they contain, but it is very easy to start copy and pasting them and before you know it you have a variable1 and variable2 situation. Remember that Visual Studio has some powerful refactoring tools so relatively easy to get them back in order.

1. You repeat your code

I’ve been reading Pragmatic Programmer and one of their first tips was DRY – Don’t Repeat Yourself. They go to extremes with nothing being repeated anywhere in your code, but I don’t think you need to go too far, you can be reasonable. If you have the same code repeated four times, then creating a function for this code will dramatically improve your code.

1. You struggle to understand your own code

Why did I do it this way? I feel like I am always trying to remember the reasons I chose to code the way I did previously. Part of the reason for this is that I am constantly learning at the moment, but there is more that I can do to help myself understand in the future.

1. You are selfish and don’t share

I am not selfish, if I learn something really cool I have to tell someone. I like writing stuff on here to share with the world. I am thinking of news ways to train my staff.

1. You work on multiple projects

Yes Guilty as charged with this one. I have multiple projects that I am working on at work, I also have a fair few personal projects that I would like to work on. Not sure I completely agree that multiple projects equals bad programmer.
CSS3 Responsive Icons
Tags: css, responsive, ui
Published: 2020-10-05 10:55:08

---
title: CSS3 Responsive Icons
published: true
date: 2015-07-21 00:00:00 UTC
tags: CSS,Responsive,UI
canonical_url: 
---

What’s up, my neighbor? This is your boy, Darryl Tec. I am here to teach you how to create a responsive and awesomely scalable icon using CSS sprites. On top of that, we will also add a fallback for browsers that do not support SVG files. Quick FAQ. SVG - Stands for Scalable…

   
[Read On](https://www.loginradius.com/engineering/blog/css3-responsive-icons/)
Sudoku Challenge
Published: 2022-03-09 20:47:28

---
title: Sudoku Challenge
published: true
date: 2015-06-26 20:00:45 UTC
tags: 
canonical_url: https://www.funkysi1701.com/posts/2015/sudoku-challenge/
---

Last night I went to a Code Dojo at Leeds Sharp (the coding user group I have started going to). A Code Dojo is a programming challenge that people work on usually in pairs.

The challenge that we worked on was to code a solution to the puzzle game Sudoku. The code we worked with can be found on github.

![](https://storageaccountblog9f5d.blob.core.windows.net/blazor/wp-content/uploads/2015/06/2000px-Sudoku-by-L2G-20050714.svg_.png?resize=660%2C660&ssl=1)

I don’t know much about Sudoku but the game goes like this. You start with a 9×9 grid, and the idea is to fill in all the missing numbers.

Each Row can only use each digit 1 to 9 once, each column can only use each digit 1 to 9 once and each subgrid (3×3) can only use each digit once.

I worked with Richard one of the Leeds Sharp organisers, we started by trying to loop through each empty cell and insert values in a brute force attack, but this approach didn’t get us very far (literally as the application crashed!)

The approach that we needed to use was to loop through calculating possible values.

It was only when I sat down at this dojo did I realise how much I still have to learn, but while talking with Richard about different approaches and different coding structures I started to learn.
How to install XCode Command Line Tools
Tags: experience, php, xcode
Published: 2024-03-16 10:08:36

---
title: How to install XCode Command Line Tools
published: true
date: 2015-07-17 19:34:12 UTC
tags: Experience,PHP,XCode
canonical_url: https://io.serendipityhq.com/experience/how-to-install-xcode-command-line-tools/
---

XCode is the development environment provided by Apple and it contains a set of tools useful for development.

One of this tools is XCode Command Line Tool that

> […] gives terminal users many commonly used tools, utilities, and compilers, including make, GCC, clang, perl, svn, git, size, strip, strings, libtool, cpp, what, and many other useful commands that are usually found in default linux installations.
> 
> <footer>From <cite title="OSX Daily"><a href="http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/" target="_blank" rel="noopener">OSX Daily</a></cite></footer>

To install XCode Command Line Tools, you DON’T have to first install XCode.

To get XCode Command Line Tools up and running on your system and usable from command line, you only need to open the Terminal and type:

```
$ xcode-select --install
```

A popup will open asking you if you want to install the Tools: obviously, choose YES!

Once the installation of Command Line Tools is completed, you have to create symlinks between MAMP and XCode.

This is required, for example, to [install the Intl PHP module](http://aerendir.me/?p=452).

To create the symlinks:

```
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include /Applications/MAMP/bin/php/php5.6.6
```

Keep attention to versions both of xCode and of MAMP’s PHP!

All done: now you have XCode Command Line Tools available in your Terminal!

Remember to “Make. Ideas. Happen.”.

I wish you flocking users, see you soon!

L'articolo [How to install XCode Command Line Tools](https://io.serendipityhq.com/experience/how-to-install-xcode-command-line-tools/) proviene da [ÐΞV Experiences by Serendipity HQ](https://io.serendipityhq.com).
How to set the $PHP_AUTOCONF environment variable in MAMP (in 2 steps)
Tags: experience, php
Published: 2024-03-16 10:08:44

---
title: How to set the $PHP_AUTOCONF environment variable in MAMP (in 2 steps)
published: true
date: 2015-07-17 19:33:30 UTC
tags: Experience,PHP
canonical_url: https://io.serendipityhq.com/experience/how-to-set-the-php_autoconf-environment-variable-in-mamp-in-2-steps/
---

If you receive this error trying to install some new binaries using MAMP (for example, [installing Intl PHP module](http://aerendir.me/?p=452)), then there is a chance you’ll get this error in your Terminal:

> Cannot find autoconf. Please check your autoconf installation and the $PHP\_AUTOCONF environment variable. Then, rerun this script.

This happens because you haven’t the [Autoconf](http://www.gnu.org/software/autoconf/autoconf.html) binaries installed.

So, let’s install the Autoconf binaries in MAMP.

## STEP 0: Verify which version of PHP you are currently running

Before you install Autoconf binaries, [check that your Terminal is using the PHP binaries provided by MAMP](http://aerendir.me/?p=456).

Instead you have to install Autoconf both for the PHP used by Terminal – the one shipped with MacOSX – and for the PHP used by your browsers – the one shipped with MAMP. Yes, they are 2 separate binaries packages!

## STEP 1: Download autoconf binaries and uncompress them

```
$ cd ~/Desktop
$ curl -O http://mirror2.mirror.garr.it/mirrors/gnuftp/gnu/autoconf/autoconf-latest.tar.gz
$ tar xzvf autoconf-latest.tar.gz
```

## STEP 2: Compile the binaries and install them

Now that you have the Autoconf binaries, you have to install them. So, move into the `auoconf-*` folder and compile and install the binaries:

```
$ cd autoconf-*
$ ./configure
$ make && sudo make install
```

This process may require some minutes and during the process you will be asked to provide the Admin password.

To verify your work, type:

```
$ which autoconf
/usr/local/bin/autoconf
```

Remember to “Make. Ideas. Happen.”.

I wish you flocking users, see you soon!

L'articolo [How to set the $PHP\_AUTOCONF environment variable in MAMP (in 2 steps)](https://io.serendipityhq.com/experience/how-to-set-the-php_autoconf-environment-variable-in-mamp-in-2-steps/) proviene da [ÐΞV Experiences by Serendipity HQ](https://io.serendipityhq.com).