Skip to content

Instantly share code, notes, and snippets.

View sankars's full-sized avatar

Sankar sankars

  • Dubai
View GitHub Profile
sudo apt-get update
sudo apt-get install openssh-server
sudo ufw allow 22
vector <- c(45, 5, 64, 80)
tail(vector, 1)
vector[length(vector)]
last <- function(x) { tail(x, n = 1) }
last(vector)
public enum Blah {
A("text1"),
B("text2"),
C("text3"),
D("text4");
private String text;
Blah(String text) {
this.text = text;
## only print filename instead of full path
find /dir1 -type f -printf "%f\n"
find /dir1 -type f -exec basename {} \;
# http://stackoverflow.com/questions/4984725/how-to-test-cron-job
run-parts -v /etc/cron.weekly
@sankars
sankars / vector_operations.r
Created April 11, 2014 16:23
Vector operations
# http://stackoverflow.com/questions/7706876/r-script-removing-na-values-from-a-vector
# Sort vectors that have 'NA'
d <- c(1, 100, NA, 10)
max(d, na.rm=TRUE)
# Remove 'NA' in a vector
d <- d[!is.na(d)]
# http://stackoverflow.com/questions/471183/linux-command-line-global-search-and-replace
# not recursive. input the file name
sed -i 's/foo/bar/g' *
# recursive
find -name '*.html' -print -exec sed -i.bak 's/foo/bar/g' {} \;
// http://stackoverflow.com/questions/22713652/can-an-interface-method-have-a-body
// define static method
interface Whoa {
public static void doStuff() {
System.out.println("This is not default implementation");
}
}
public class Joda implements Directions
{
public static void main(String [] args)
{
// From http://stackoverflow.com/questions/1555262/calculating-the-difference-between-two-java-date-instances
Interval interval = new Interval(oldTime, new Instant());
# From http://stackoverflow.com/questions/7004710/laply-is-part-of-what-package-in-r
install.packages("pkg")
library("pkg")