Skip to content

Instantly share code, notes, and snippets.

View aL3xa's full-sized avatar

Aleksandar Blagotić aL3xa

View GitHub Profile
@aL3xa
aL3xa / serbian_locale.R
Created March 4, 2011 16:16
Сербиан локале
> set.seed(1)
> шушумига <- rnorm(10)
> шушумига
[1] 0.7996718 -0.9688060 -0.1634763 -1.1242522 -1.5689024 -0.6055469
[7] -0.3446827 -0.8229724 -0.6148953 2.5545790
> set.seed(1)
> ( blah <- factor(sample(c("један", "два", "три"), 100, replace = TRUE)) )
[1] један два два три један три три два два један један један
[13] три два три два три три два три три један два један
@aL3xa
aL3xa / corstar.R
Created March 25, 2011 17:41
Correlation table with significance indicators
corstar <- function(x, y = NULL, use = "pairwise", method = "pearson", round = 3, row.labels, col.labels, ...) {
require(psych)
ct <- corr.test(x, y, use, method) # calculate correlation
r <- ct$r # get correlation coefs
p <- ct$p # get p-values
stars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " "))) # generate significance stars
@aL3xa
aL3xa / conkerorrc
Created April 11, 2011 02:27
Conkeror RC
// homepage = "http://www.google.com";
// set default webjump
read_url_handler_list = [read_url_make_default_webjump_handler("google")];
// possibly valid URL
function possibly_valid_url (str) {
return (/[\.\/:]/.test(str)) &&
!(/\S\s+\S/.test(str)) &&
!(/^\s*$/.test(str));
}
@aL3xa
aL3xa / grade_questionnaire.R
Created July 7, 2011 19:31
Questionnaire grading function
grade_questionnaire <- function(dtf, n.items, item.ind = NULL, scale.names, scale.labels = NULL, start = 1:length(scale.names), end = n.items, jump, rev.ind = NULL, rev.fn = NULL, total = FALSE, total.name = NULL, allowed.values = NULL, pre.process.fn = NULL, na.rm = FALSE, ...){
d <- subset(dtf, ...) # create subset if any
nc <- ncol(d) # number of columns
## number of columns sanity check
if (nc != n.items)
stop(sprintf("Incorrect number of items! %d items required, while %d were provided!", n.items, nc))
## check scale labels
@aL3xa
aL3xa / .emacs
Last active September 27, 2015 04:47
My .emacs
;; start the timer
(defvar *emacs-load-start* (current-time))
;; Package repos
(require 'package)
;; MELPA
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(global-set-key (kbd "C-c p") 'list-packages)
@aL3xa
aL3xa / sweave.sh
Created September 13, 2011 10:27
Custom Sweave bash script
#!/bin/bash
FILEBASE=${1%.*}
FILEXT=${1##*.}
FILEPATH=${1%/*}
TEXFILE=$FILEBASE.tex
PDFFILE=$FILEBASE.pdf
# errorexit
@aL3xa
aL3xa / virtualbox.sh
Created September 13, 2011 10:28
Virtualbox custom startup script
#!/bin/bash
if [ -z $(lsmod | grep vboxdrv) ]; then
# load virtualbox module
gksudo modprobe vboxdrv
fi
# virtualbox module loaded
vm=`VBoxManage list vms | zenity --list --title="Virtualbox machines" --column="Machine"`
if [ ! -z "$vm" ]; then
VBoxManage startvm $vm
@aL3xa
aL3xa / buildpkg.R
Created January 23, 2012 14:35
Build, Check, Install and (Re)Load R Package
b <- function(path = "package/", ...){
require(devtools)
require(roxygen2)
pkg <- as.package(path) # package pointer
## update documentation
message("Updating documentation...")
roxygenise(path, ...)
@aL3xa
aL3xa / send_http.php
Created March 6, 2012 17:45
Send HTTP request from PHP
// send HTTP POST request
function send_http($url, $params = null, $type = 'GET')
{
$type = strtoupper($type); // request type
if (!preg_match('/^(GET|POST)$/', $type)) {
die("Unsupported method type: '$type'");
}
/* generate POST string */
$query_string = '';
@aL3xa
aL3xa / watermark.js
Created April 10, 2012 23:32
Quick and dirty jQuery watermark function
// Quick & dirty watermark function
// inspired by https://github.com/marioestrada/jQuery-Watermark
(function ($){
$.fn.watermark = function(){
var $elems = $(this).filter('textarea, input[type="text"]');
$elems.each(function(i, e){