Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Last active January 3, 2016 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzi/8467136 to your computer and use it in GitHub Desktop.
Save abruzzi/8467136 to your computer and use it in GitHub Desktop.
Some Useful notes on Linux

underscore.js

Given I have a data structure like this

{
	"JSESSIONID": "6C729E682C05AA56017E3D1675CE8E5F",
	"_USER": "GEO-NASTAR"
}

and I want it to be coverted to

"JSESSIONID=6C729E682C05AA56017E3D1675CE8E5F;_USER=GEO-NASTAR"

This is how to do ti with underscore.js

var cookies = {
	"JSESSIONID": "6C729E682C05AA56017E3D1675CE8E5F",
	"_USER": "GEO-NASTAR"
}


_.reduce(_.pairs(cookies), function(memo, item) {
	return memo.concat(item.join("="));
}, []).join(";");

Some notes about command line in Linux enviornment

How to find out which process is listening upon a port

lsof -i :80

How to set proxy in linux?

export http_proxy="http://username:password@hosename:port"
export no_proxy="127.0.0.1, localhost, *.cnn.com, 192.168.1.10, domain.com:8080"

And note that when you have special characters in password field, you need to escape it by url-encoding, $ -> %24

How to set svn executable property to script file

So you have a executable(maybe e2e_test.sh in linux), but team are working on stupid Windows. And when you commit the executable to svn, the executable premission will be missed.

svn propset svn:executable "*" someScript

This line will fix the problem.

How can I know whether a file is executable or not in bash

if [ -x $FILENAME ]; then
  # the file is executable
fi
if [ -f $FILENAME ]; then
  # the file is existing
fi

Which distribution of Linux am I using?

$ lsb_release -a

you may get if you're running in SUSE:

$ lsb_release -a
LSB Version:    core-2.0-noarch:core-3.0-noarch:core-2.0-x86_64:core-3.0-x86_64:desktop-3.1-amd64:desktop-3.1-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.1-amd64:graphics-3.1-noarch
Distributor ID: SUSE LINUX
Description:    SUSE Linux Enterprise Server 10 (x86_64)
Release:        10
Codename:       n/a

or this if youare using ubuntu instead:

$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.3 LTS
Release:        12.04
Codename:       precise

How to know 64 bits or 32 bits of given linux

$ uname -m
x86_64

or

$ file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, BuildID[sha1]=0xe04b36145abc21d863652b93e6a0d069f7dfd3f4, stripped

How can I find something and exclude a special folder

So you want to count all javascript file, but don't want count those in libs/, here is the command:

find . -path ./libs -prune -o -name "*.js" | wc -l

-path ./libs -prune -o is doing the magic.

Continue download with wget

I was trying to download the virtual box image of CDH4 from cloudera, and in the meantime, the VirtualBox itself was downloaded. I'm so happy after 30 mins waiting and start the installation.

2 mins later, I was asked is that ok if the network cut off temporyly? I said ok, and later found the putty was cut as well.

Ok, the wget was reporting that it finished almost 11%, I reconnect to the putty, but wget was a orphan. What should I do? the image is 3.2 GB big.

$ wget -c https://downloads.cloudera.com/demo_vm/virtualbox/cloudera-quickstart-vm-4.6.0-0-virtualbox.7z --no-check-certificate
--2014-05-08 12:32:25--  https://downloads.cloudera.com/demo_vm/virtualbox/cloudera-quickstart-vm-4.6.0-0-virtualbox.7z
Connecting to 172.19.6.47:8080... connected.
WARNING: cannot verify downloads.cloudera.com's certificate, issued by `/O=Huawei Technologies Co., Ltd./OU=IT/L=Huawei Internal Network/C=CN/CN=Huawei Secure Internet Proxy CA':
  Unable to locally verify the issuer's authority.
Proxy request sent, awaiting response... 206 Partial Content
Length: 3393638045 (3.2G), 2951427152 (2.7G) remaining [text/plain]
Saving to: `cloudera-quickstart-vm-4.6.0-0-virtualbox.7z'

13% [++++++++++                                                                      ] 450,866,893 57.8K/s  eta 3h 57m

woohoo....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment