This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -s http://www.whatismypublicip.com | grep -Eo '[0-9]*[\.][0-9]*[\.][0-9]*[\.][0-9]*' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |