Skip to content

Instantly share code, notes, and snippets.

View hankliu5's full-sized avatar
🐶

Yu-Chia "Hank" Liu hankliu5

🐶
View GitHub Profile
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 },
@hankliu5
hankliu5 / gist:f38f33f9e9b1502f8772
Created December 2, 2015 22:29
First time I wrote a code to deal with complicated computation for my homework. Just for a souvenir.
# 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
@hankliu5
hankliu5 / sieve_of_Eratosthenes.rb
Last active December 5, 2015 03:02
Which can help us pick up prime numbers in the range of a number you choose.
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
@hankliu5
hankliu5 / HW5.java
Last active February 19, 2016 05:53
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};
// 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) {
#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) {
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
package main
import (
"fmt"
"strings"
"os"
"bufio"
"io"
"strconv"
"encoding/binary"
package main
import (
"fmt"
"strings"
"os"
"bufio"
"io"
"strconv"
"gonum.org/v1/gonum/mat"
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()