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
use node_bindgen::derive::node_bindgen; | |
#[node_bindgen] | |
pub fn simple_moving_average(array_prices: Vec<f64>, window: f64) -> Vec<f64> { | |
let interval = window as usize; | |
let mut index = interval - 1; | |
let length = array_prices.len() + 1; | |
let mut results = Vec::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
use wasm_bindgen::prelude::*; | |
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | |
// allocator. | |
#[cfg(feature = "wee_alloc")] | |
#[global_allocator] | |
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | |
#[wasm_bindgen] | |
extern "C" { |
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 simple moving average from stock prices. | |
* @param {Array} prices - The list of prices. | |
* @param {number} interval - The number of periods to calculate. | |
* @return {Array} The list of SMA value. | |
*/ | |
exports.simpleMovingAverage = (prices, interval) => { | |
let index = interval - 1; | |
const length = prices.length + 1; | |
let results = []; |
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
// This gist is a solution from a challenge that I found in Twitter. | |
// The challenge is writing code to do 1000 HTTP GET concurently with any favourite programming languages. | |
// Here's the URL: https://twitter.com/codingfess/status/1426142985532575747 | |
use std::thread; | |
use std::io::prelude::*; | |
use std::net::{TcpStream}; | |
fn http_call(hostname: &str) { | |
let mut stream = TcpStream::connect((hostname, 80)).unwrap(); | |
let header = format!("GET /get HTTP/1.1\r\nHost: {}\r\nAccept: */*\r\nConnection: close\r\n\r\n", hostname); |
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
const express = require('express'); | |
const app = express(); | |
let personData = [ | |
{ | |
name: 'Budi', | |
age: '42', | |
origin: 'Jawa Barat' | |
}, | |
{ |
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
const int ledPin = 13; // pin yang digunakan untuk LED | |
// variabel yang akan selalu berganti | |
int ledState = LOW; // ledState digunakan untuk mengubah kondisi LED | |
long previousMillis = 0; // akan menyimpan milidetik terakhir dari loop | |
// inilah variabel pengganti delay(1000) | |
long interval = 1000; // interval blink dalam ms | |
void setup() { |
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
(function() { | |
let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); | |
// Create the oscillator | |
let osc1 = audioCtx.createOscillator(); | |
// Create the gain node | |
let gainOsc1 = audioCtx.createGain(); | |
// Create the panner |
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
(function() { | |
let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); | |
// Create the oscillator | |
let osc1 = audioCtx.createOscillator(); | |
let osc2 = audioCtx.createOscillator(); | |
// Create the gain node | |
let gainOsc1 = audioCtx.createGain(); | |
let gainOsc2 = audioCtx.createGain(); |
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
#define LEDPIN 2 | |
void setup() | |
{ | |
pinMode(LEDPIN, OUTPUT); | |
} | |
void loop() | |
{ | |
digitalWrite(LEDPIN, HIGH); // led menyala |
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
/** | |
* Fungsi ini digunakan untuk menghitung harga barang setelah diskon. | |
* @param {Number} discountRate - nilai diskon yang diberikan | |
* @param {Number} originalPrice - harga barang sebelum diskon dalam Rupiah | |
* @returns {Number} | |
*/ | |
function calculateDiscount(originalPrice, discountRate) { | |
let discount = originalPrice * discountRate / 100; | |
return originalPrice - discount; | |
} |
NewerOlder