Skip to content

Instantly share code, notes, and snippets.

View viraltux's full-sized avatar

Fran Urbano viraltux

View GitHub Profile
@viraltux
viraltux / .emacs
Last active August 24, 2017 18:44
(setq user-emacs-directory (expand-file-name "~/Dropbox/.emacs.d/"))
(require 'org)
(org-babel-load-file (expand-file-name (concat user-emacs-directory "init.org")))
(load (locate-user-emacs-file "init.el"))
@viraltux
viraltux / init.org
Last active September 8, 2017 15:03

Emacs

More interesting settings in http://mescal.imag.fr/membres/arnaud.legrand/misc/init.php and https://github.com/dz/dotfiles/tree/master/emacsd/configs Common problems with Emacs can be solve by removing the .elc (compiled files) and recompiling them with byte-recompile-directory. For just one file we can use byte-compile-file.

Check for more seetings in: http://www.i3s.unice.fr/~malapert/org/tips/emacs_orgmode.html

.emacs main content

a soft linked copy of the .emacs file should be place in the home directory ~ with cp -as ~/Dropbox/.emacs ~

The .emacs file will trigger the load and conversion of the init.org file and should contain the following lines in the begginning.

;; https://stable.melpa.org/#/getting-started
(require 'package) ;; You might already have this line
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
(add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
@viraltux
viraltux / createt.R
Last active August 16, 2017 11:35
code to generate a CREATE table statement for POSTGRESQL useful to generate the CREATE TABLE scripts for existing CSV files and data.frames
createt <- function(table){
## code to generate a CREATE table statement for POSTGRESQL
## useful to generate the CREATE TABLE script for CSV files
## and data.frames
create.sql <- "SELECT
'CREATE TABLE ' || relname || E'\n(\n' ||
array_to_string(
array_agg(
' ' || column_name || ' ' || type || ' '|| not_null
)
#Combining P-Values via Naive Bayes
bpv <- function(pv){
#Bayesian Probability
bp <- function(p){
if (any(p>1/exp(1))) stop('All p-values musts be lower that 1/e')
1 / (1 + 1/(-exp(1)*p*log(p)))
}
#Naive Bayes
nb <- function(p){
@viraltux
viraltux / SubSV
Last active September 10, 2015 07:41
R function to that replaces 'key' tagged words (eg. $word) within a string with the value contained in the system by the local variable 'word'
SubSV <- function(string, env, key = '$'){
# Replaces 'key' tagged words (eg. $word) within a string with the value
# contained in the system by the local variable 'word'
#
# Args:
# string: string with 'key' tagged words.
# Returns:
# string with every 'key' tagged word replaced.
# Example:
# this <- 'by that'; SubSV('replace $this', environment())
@viraltux
viraltux / IChing
Last active August 31, 2016 23:32
R function returning six Yin Yang elements coded from 6 to 9 following the traditional method to obtain I Ching hexagrams as explained by Richard Whilhem book. http://aleadeum.com/2013/07/12/the-i-ching-random-numbers-and-why-you-are-doing-it-wrong
IChing = function(N=6){
set = NULL
for(i in 1:N){
sign = 0
hand = 0
for(j in 1:3){
left = sample(1:(48-hand),1)
right = 49-hand-left
pinky = 1 ; right = right - 1
anular = ifelse(left%%4==0,4,left%%4);