pandas - format custom date in data frame
say you have a data frame like this
[
{foo: 1, created_date:"2016-06-04 03:00:01.727"},
...
]
the timestamp doesn’t recognize immediately. To make this field as timestamp and as index we could do
|
|
say you have a data frame like this
[
{foo: 1, created_date:"2016-06-04 03:00:01.727"},
...
]
the timestamp doesn’t recognize immediately. To make this field as timestamp and as index we could do
|
|
from http://stackoverflow.com/a/17419690/546750
to list all file that modified more than more than X days, we can use
$ find . -mtime +[number of days]
if you use -
sign than it became file is modified since X days
Combine it with akw, we can get total file size
$ find . -mtime +180 -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}'
from http://stackoverflow.com/a/185903/546750
Underneath the file system files are represented by inodes (or is it multiple inodes not sure)
A file in the file system is basically a link to an inode. A hard link then just creates another file with a link to the same underlying inode.
When you delete a file it removes one link to the underlying inode. The inode is only deleted (or deletable/over-writable) when all links to the inode have been deleted.
A symbolic link is a link to another name in the file system.
Once a hard link has been made the link is to the inode. deleting renaming or moving the original file will not affect the hard link as it links to the underlying inode. Any changes to the data on the inode is reflected in all files that refer to that inode.
Note: Hard links are only valid within the same File System. Symbolic links can span file systems as they are simply the name of another file.
jq is a fantastic command line tools to parse and filter json in command line. It works for linux, osx and maybe windows.
example, to format json
$ json='[{"genre":"deep house"}, {"genre": "progressive house"}, {"genre": "dubstep"}]'
$ echo $json
[{"genre":"deep house"}, {"genre": "progressive house"}, {"genre": "dubstep"}]
$ echo $json | jq .
[
{
"genre": "deep house"
},
{
"genre": "progressive house"
},
{
"genre": "dubstep"
}
]
To output a particular field
$ echo $json | jq '.[].genre'
"deep house"
"progressive house"
"dubstep"
To filter based on a key
$ echo "$json" | jq -c '.[] | select(.genre | contains("house"))'
{"genre":"deep house"}
{"genre":"progressive house"}
more example could be found on here
Sometimes you create a script that generate something but you wanted to only keep N last item. There is couple way to achive this. This version works both on OSX and Linux.
$ (ls -t|head -n 5;ls)|sort|uniq -u|xargs rm
Basically it the (..)
will capture together the output
ls -t | head -n 5
will list files sort by time and get first 5 itemsls
will list all file. Now it contains duplicate items for items we want to keepsort|uniq -u
will sort it, and remove those duplicate file in step 1. At this point it will contains only files that we want to delete (everything except files from step 1)xargs rm
will change the resulst into space separated value which is argument for rm
I need to start jumpcut during startup because I have to start it manually now.
We can add one or more program to start when we are logged in. Use system preference > Users & Groups. Select your username and there should be Login items tabs where you can add more or disable programs.
from http://northernmost.org/blog/find-out-what-is-using-your-swap/
|
|
From http://stackoverflow.com/questions/1885525/how-do-i-prompt-a-user-for-confirmation-in-bash-script
|
|
with head -n <negative number>
we can get the output except n lines
example
cat a.txt | head -n -1
will gives as the content of a.txt except the last one
Let say we have file 1 2 3 4 5, and with grep we want to only get 1 2 3.
we can achive this with ls and grep
$ ls | grep 4 -B 100000000 | head -n -1
the -B show 100000000 lines before matched line, and the head -n -1 removes the matched
When compiling binary that open port, (depending on your settings) it will ask to allow if the process can make the connection.
We can sign our binary with certificate to avoid this.
While RedYeti’s link is useful, just to save a few clicks for others let me recap how to generate a code-signing cert and to use it for code (re-)signing:
1. Create your own code signing cert:
In Keychain Access, Keychain Access > Certificate Assistant > Create a certificate. This launches the Certificate Assistant:
Name: Enter some arbitrary string here that you can remember. Avoid spaces otherwise you'll need to escape the cert's name when using codesign from the command line.
Identity type: Self Signed Root
Certificate Type: Code Signing
Check the box "Let me override defaults", this is quite important
Serial number: 1 (OK as long as the cert name/serial no. combination is unique)
Validity Period: 3650 (gives you 10 years)
Email, Name, etc. fill out as you wish.
Key pair info: set to RSA, 2048 bits. Does not really matter IMHO.
From "Key usage extension" up to "Subject Alternate Name Extension": accept the defaults.
Location: login keychain.
Once it is created, set to "Always trust" in the Login keychain.
2. Re-signing an app: codesign -f -s <certname> /path/to/app --deep
3. Verify that it worked: codesign -dvvvv /path/to/app
Enjoy!