Skip to content

Instantly share code, notes, and snippets.

View krasnobaev's full-sized avatar
👨‍🔬

Aleksey Krasnobaev krasnobaev

👨‍🔬
View GitHub Profile
@krasnobaev
krasnobaev / check for program existing
Last active August 29, 2015 13:56
bash use cases
command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
# http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
@krasnobaev
krasnobaev / Makefile
Last active August 29, 2015 14:07
Docker makefile
IMAGE = IMAGENAME
CONTAINER = CONTAINERNAME
build:
docker build -t $(IMAGE) .
rebuild:
docker build -t --no-cache=true $(IMAGE) .
run:
@krasnobaev
krasnobaev / basics
Created October 17, 2014 22:32
R handies
data[47]
table(is.na(data))
mean(data, na.rm=TRUE)
mean(data.R[which(data > 31 & data > 90)])
mean(data[data == 6])
max(data[data == 5], na.rm=TRUE)
by(iris$Sepal.Length, iris$Species == "virginica", mean)[2]
apply(iris[, 1:4], 2, mean)
with(mtcars, tapply(mpg, cyl, mean))
#!/bin/bash
USERNAME=stub
apt-get -y update
apt-get -y upgrade
apt-get -y dist-upgrade
DEBIAN_FRONTEND=noninteractive apt-get -y install git docker.io mailutils pwgen
apt-get -y autoremove
apt-get -y autoclean
@krasnobaev
krasnobaev / create simple table
Created June 23, 2015 14:09
JavaScript snippets
oTable = document.createElement('table');
oTable.className = 'htCore';
oTbody = document.createElement('tbody');
oTr = document.createElement('oTr');
oTd = document.createElement('oTd');
oTd.appendChild(document.createTextNode('Text'));
oTr.appendChild(oTd);
oTbody.appendChild(oTr);
oTable.appendChild(oTbody);
// convert tabs to 4 spaces
find . -type f -exec sed -i 's/[ \t]*$//' {} \;
// remove trailing spaces
find . -type f -exec sed -i 's/[ \t]*$//' {} \;
// add new line at the end of file
find . -type f -exec sed -i -e '$a\' {} \;
// convert CRLF to LF
@krasnobaev
krasnobaev / Handsontable
Created June 30, 2015 11:32
JavaScript
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<link href="handsontable.full.css" rel="stylesheet">
<script src="handsontable.full.js"></script>
@krasnobaev
krasnobaev / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# prepare to hold your colour
cd /usr/local/src/linux
cp /boot/config-$(uname -r) .config && make oldconfig
# enable CAIAQ module (CONFIG_SND_USB_CAIAQ=m)
# other recommended options:
# CONFIG_SND_DEBUG=y
# CONFIG_SND_DEBUG_VERBOSE=y
# CONFIG_SND_VERBOSE_PRINTK=y
make xconfig
$ shopt -s extglob
$ echo images/*
images/004.bmp images/033.jpg images/1276338351183.jpg images/2252.png
$ echo images/!(*.jpg)
images/004.bmp images/2252.png