Skip to content

Instantly share code, notes, and snippets.

public class rotateArray{
public static int[] main(int[] a, int n){
int[] result = new int[a.length];
for(int i=0; i<a.length; i++){
result[i] = a[(i+n) % a.length];
}
a = result;
return a;
}
}
public class firstArray {
public static int[] setupArray() {
int[][] x = new int[6][4];
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < x[0].length; j++) {
a[i][j] = (int) (Math.random() * 90 + 10);
}
}
return x;
@dtemkin
dtemkin / beerbottles.java
Created September 20, 2017 00:49
Popular Song in Java (for MS Data Sci Program)
// Problem:
// Write a program that prints the “99 bottles of beer on the wall” song:
// http://www.99-bottles-of-beer.net/lyrics.html
public class beerbottles{
public static void main(String[] args){
int n = 99;
while(n-1 > -1) {
if(n==1){
String song = String.format("%d bottle of beer on the wall.\n%d bottle of beer.\nTake one down, pass it around.", n, n);
@dtemkin
dtemkin / taylorpi.java
Created September 20, 2017 00:47
Taylor Series Pi Estimate (for MS Data Sci Degree)
// Problem:
// The value of pi can be determined by the series equation:
// pi = 4(1-1/3+1/5-1/7+1/9-1/11+...)
// Write a program to approximate the value of pi using the formula given including terms up through 1/99.
public class taylorpi{
static double estimate=0.0;
static double max_int=99.0;
@dtemkin
dtemkin / recursive_removal_function.py
Last active April 8, 2018 15:02
Recursively remove list element by value.
a = [1, 1, 1, 5, 6, 7]
# remove value recursively
def _rm_recurs(lst, val):
lst.remove(val)
if val in lst:
_rm_recurs(lst, val)
return lst
@dtemkin
dtemkin / svm.py
Created February 9, 2017 05:26
Udacity SVM Mini-Project
#!/usr/bin/python2
import sys
from time import time
sys.path.append("../tools/")
from email_preprocess import preprocess
from sklearn.metrics import accuracy_score
from sklearn.svm import SVC
### features_train and features_test are the features for the training
### and testing datasets, respectively
@dtemkin
dtemkin / cramersV.py
Last active July 8, 2023 08:07
A simple Cramers V function in Python
import math
import numpy as np
# Functions for calculating the degree of association between nominal variables
def cramersV(nrows, ncols, chisquared, correct_bias=True):
nobs = nrows*ncols
if correct_bias is True:
phi = 0
else:
phi = chisquared/nobs
@dtemkin
dtemkin / get_public_ip
Created January 24, 2017 21:53
Get Public IP from http://www.whatismypublicip.com using curl and grep
curl -s http://www.whatismypublicip.com | grep -Eo '[0-9]*[\.][0-9]*[\.][0-9]*[\.][0-9]*'
We couldn’t find that file to show.
@dtemkin
dtemkin / bash_install_txt.sh
Last active December 9, 2016 05:54
Install packages listed in file using cat in BASH
# A cute one-liner in bash to install all the packages listed in a file using pacman
for i in $(cat '/path/to/installed-pkgs.list'); do sudo pacman -S --noconfirm $i; done;
# You can also filter the list using grep like this
for i in $(cat '/path/to/installed-pkgs.list' | grep "xorg-"); do sudo pacman -S --noconfirm $i; done;
# If you use another base package manager like aptitude edit as follows