Skip to content

Instantly share code, notes, and snippets.

View mfansler's full-sized avatar

Mervin Fansler mfansler

View GitHub Profile
@ghoseb
ghoseb / factorial.py
Created November 14, 2008 18:58
The evolution of a Python Programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@Gozala
Gozala / example.js
Created January 29, 2012 03:46
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active November 9, 2024 08:57
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@davfre
davfre / bamfilter_oneliners.md
Last active August 4, 2024 03:10
SAM and BAM filtering oneliners
## This will allow you to use dplyr functions with Bioconductor's
## S4Vectors::DataFrame class. They simply call "as.data.frame" on
## DataFrame objects and then pass them to the methods for
## "data.frame". Note that this entails conversion of S4 vector
## columns to primitive vectors. No attempt is made to convert the
## results back to DataFrame, since such a conversion would not
## restore S4 vector columns that were converted to primitive vectors.
library(S4Vectors)
library(dplyr)
@mcg1969
mcg1969 / spaces.md
Last active November 12, 2021 14:28
Conda hackery: namespaces

Conda Proposal: namespaces

Motivation

We would like to position Conda as a language-agnostic package manager, but at present it maintains a distinct bias towards Python. Given its origins this was expected and, frankly, reasonable. Nevertheless, as we begin to use it to subsume other packaging ecosystems, such as CRAN, NPM, Ruby Gems, etc., we are going to want to overcome this history; and one key challenge is to address naming conflicts across platforms.

@luiscape
luiscape / install_packages.sh
Created January 16, 2017 14:36
Install Python dependency packages from requirements.txt using conda.
#
# Original solution via StackOverflow:
# http://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t
#
#
# Install via `conda` directly.
# This will fail to install all
# dependencies. If one fails,
# all dependencies will fail to install.
@nick3499
nick3499 / filter_map_collect.rs
Last active May 26, 2020 13:10
Rust: Filter Range, Map, Collect
fn main() {
let rng = 0..30;
let rng_even_cubed = rng.filter(|n| is_even(*n))
.map(|n| n * n * n)
.collect::<Vec<i32>>();
println!("{:?}", rng_even_cubed);
}
fn is_even(n: i32) -> bool {
n % 2 == 0
@hfossli
hfossli / standard.sh
Last active September 19, 2024 05:27
Standard bash script format
#!/bin/bash
CLEAR='\033[0m'
RED='\033[0;31m'
function usage() {
if [ -n "$1" ]; then
echo -e "${RED}👉 $1${CLEAR}\n";
fi
echo "Usage: $0 [-n number-of-people] [-s section-id] [-c cache-file]"
@hyginn
hyginn / makeMD5.md
Last active January 29, 2023 17:39
The making of MD5 files
# Author: Boris Steipe (ORCID: 0000-0002-1134-6758)
# License: (c) Author (2019) + MIT
# Date: 2019-01-17

What are MD5 files good for anyway?

I recently contributed to Siegfried Köstlmeier's qrandom package and overlooked to update the package MD5 file. That got me thinking - these files are actually not mentioned in Writing R Extensions, and they are not mentioned in Hadley Wickham's R Packages either. We find them in the wild - but I did not find an explicit source regarding their format. In fact, there is a puzzled post from 2016 by Matthew Lueder on Stack Overflow "What is the MD5 file in R packages used for? How is it generated?" ... and the sole answer on the page misunderstood the question.