This file contains 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
TodoList.destroy_all | |
User.destroy_all | |
Profile.destroy_all | |
# Here we use exclamation because it will warn you if something goes wrong. | |
# The regular create won't tell you anything if fail. | |
Profile.create! [ | |
{ first_name: "Carly", last_name: "Fiorina", birth_year: 1954 }, | |
{ first_name: "Donald", last_name: "Trump", birth_year: 1946 }, | |
{ first_name: "Ben", last_name: "Carson", birth_year: 1951 }, |
This file contains 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
# The first time I write a code to deal with my homework. | |
forces_of_experiment = [1.33, 3.33, 4.80, 7.13, 8.00, 6.60, 5.07, 4.53] | |
frequencies_of_experiment = [0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21] | |
density_of_experiment = 800 | |
length_of_experiment = 250 | |
viscosity_of_experiment = 0.000018 | |
y = Array.new | |
x = Array.new |
This file contains 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
puts "Enter an number greater than 1." | |
number = gets.chomp.to_i | |
puts "I'm gonna pick up prime numbers less than #{number}." | |
range = Array.new | |
initial_value = 2 | |
(number - 1).times { range << initial_value; initial_value += 1 } | |
range.each do |i| | |
i_square = i ** 2 |
This file contains 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 java.util.Scanner; | |
import java.io.FileInputStream; | |
import java.io.BufferedInputStream; | |
import java.io.FileOutputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.IOException; | |
public class Recover { | |
public static void main(String[] args) throws IOException{ | |
int[] test1 = {0xff, 0xd8, 0xff, 0xe0}; |
This file contains 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
// puts wordsMap's key and value into ArrayList. | |
List<Map.Entry<String, Integer>> listData = | |
new ArrayList<Map.Entry<String, Integer>>(wordsMap.entrySet()); | |
/** | |
* sorts the data based on the order of values by using Comparator class. | |
*/ | |
Collections.sort(listData, new Comparator<Map.Entry<String, Integer>>() { | |
public int compare(Map.Entry<String, Integer> entry1, | |
Map.Entry<String, Integer> entry2) { |
This file contains 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
#include <iostream> | |
void swap(int *x, int *y) { | |
int temp = *x; | |
printf("the value of temp: %d\n", temp); | |
*x = *y; | |
*y = temp; | |
} | |
void wrong_swap(int x, int y) { |
This file contains 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
def path_from_s_to_t(G: directed graph, s: starting point, t: ending point) | |
return dfs(G, s, t, "white") | |
def dfs(G, u, t, color): | |
if u is t: | |
return True | |
found_path_to_t = False | |
for all neighbors v in u: | |
if color == edge(u, v) and v.prev is None: | |
v.prev = u |
This file contains 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
package main | |
import ( | |
"fmt" | |
"strings" | |
"os" | |
"bufio" | |
"io" | |
"strconv" | |
"encoding/binary" |
This file contains 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
package main | |
import ( | |
"fmt" | |
"strings" | |
"os" | |
"bufio" | |
"io" | |
"strconv" | |
"gonum.org/v1/gonum/mat" |
This file contains 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 numpy as np | |
import sys | |
np.random.seed(0) | |
size = int(sys.argv[1]) if len(sys.argv) > 1 else 4096 | |
outfile = open('ascii_floats_{}.txt'.format(size), 'w') | |
A = np.random.random((size, size)) | |
np.savetxt(outfile, A) | |
np.save('validation_floats_{}'.format(size), A) | |
outfile.close() |
OlderNewer