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
<?php | |
$search_query = "cattle rearing"; // example | |
$search_words = explode(" ", $search_query); | |
$sql = "SELECT * FROM _index WHERE "; | |
for ($i = 0; $i < count($search_words); $i++) { | |
$sql .= "CONTAINS(keywords, '{$search_words[$i]}')"; | |
if ($i < count($search_words) - 1) $sql .= " AND "; | |
} | |
echo "SQL Query: " . $sql; |
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 random | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def generateWorkload(): | |
n = 20 # size of workload | |
inter_arrival_time_range = (1, 15) # nanoseconds | |
burst_time_range = (70, 130) # nanoseconds | |
processes = [] | |
for i in range(n): |
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
/* calculate the difference in minutes between 2 date times | |
given that only the minutes within a specified time range | |
every day should be counted | |
e.g: say the time range is 6AM to 6PM | |
if datetime1 = 4AM and datetime2 = 5AM, difference = 0 minutes | |
this is because 4AM to 5AM doesn't fall within the range of | |
6AM to 6PM so the 60 minutes isn't counted | |
e.g 2: say we have same time range and, | |
datetime1 = 5AM today and datetime2 = 7PM tomorrow, | |
difference = 1440 minutes |
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
process.on('unhandledRejection', r => console.log(r)); |
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
# assuming we want to run the tests in User.test.js | |
# remember to add test/bootstrap.test.js to mocha.opts | |
NODE_ENV=test node_modules/.bin/mocha test/integration/model/User.test.js |
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 matplotlib.pyplot as plt | |
data = np.array([ | |
[4, 3], [0, 0], [2, 4], [3, 4], [5, 4], [-2, 1], [-3, 0], [-3, -3], [8, 12], [11, 11], [9, 10] | |
]) | |
K = 3 | |
tol = 0.001 | |
max_iter = 25 |
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 | |
# data | |
heights = np.array([6.3, 5.9, 5.1, 5.6, 5.1]) | |
weights = np.array([50.2, 79.7, 61.4, 47.1, 59.8]) | |
classes = np.array(["Male", "Female", "Female" , "Male", "Female"]) | |
# P(Class) | |
males_count = 0 |
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
main { | |
max-width: 1200px; | |
margin: 0 auto; | |
} | |
section { | |
display: flex; | |
flex-wrap: wrap; | |
} | |
article, aside { flex-basis: 100%; } | |
@media (min-width: 576px) { |
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 tribonacci_triangle(n): | |
# n <- number of rows to generate | |
# a <- tribonacci triangle | |
a = [[1], [1, 1]] | |
if n == 1: | |
return [[1]] | |
elif n == 2: | |
return a | |
else: | |
# generate rows 3 to n |
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
<?php | |
$fields = []; | |
$fields['name'] = $_POST['name'] ?? NULL; | |
$fields['sex'] = $_POST['sex'] ?? NULL; | |
$fields['q1'] = $_POST['q1'] ?? NULL; | |
$fields['q2'] = $_POST['q2'] ?? NULL; | |
$fields['q3'] = $_POST['q3'] ?? NULL; | |
// validation | |
$errors = []; |