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
fn main() { | |
let abc: (f32, f32, f32) = (0.1, 0.2, 0.3); | |
let xyz: (f64, f64, f64) = (0.1, 0.2, 0.3); | |
assert!((abc.0 + abc.1 - abc.2).abs() <= f32::EPSILON); // pass | |
assert!((xyz.0 + xyz.1 - xyz.2).abs() <= f64::EPSILON); // pass | |
assert!(abc.0 + abc.1 == abc.2); // pass | |
assert!(xyz.0 + xyz.1 == xyz.2); // fail | |
} |
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
use std::rc::Rc; | |
use std::cell::RefCell; | |
#[derive(Debug)] | |
struct GroundStation { | |
radio_freq: f64 // Mhz | |
} | |
fn main() { | |
let base: Rc<RefCell<GroundStation>> = Rc::new(RefCell::new( |
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
// Cargo.toml | |
// validator = { version = "0.16.1", features = ["derive"] } | |
use validator::Validate; | |
#[derive(Deserialize, Validate)] | |
struct CatEndpointPath { | |
#[validate(range(min = 1, max = 150))] | |
id: i32, | |
} |
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
// Cargo.toml | |
// diesel = { version = "2.1.1", features = ["postgres", "r2d2"] } | |
async fn some_handler(pool: web::Data<DbPool>) -> Result<HttpResponse, UserError> { | |
todo!("Logic implemention here") | |
} | |
fn setup_database() -> DbPool { | |
let database_url = env::var("DATABASE_URL").expect("Database url is not set"); | |
let manager = ConnectionManager::<PgConnection>::new(database_url); |
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
use actix_files::{Files, NamedFile}; | |
async fn index() -> Result<NamedFile> { | |
Ok(NamedFile::open("./static/index.html")?) | |
} |
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
function midString(prev, next) { | |
var p, n, pos, str; | |
for (pos = 0; p == n; pos++) { | |
// find leftmost non-matching character | |
p = pos < prev.length ? prev.charCodeAt(pos) : 96; | |
n = pos < next.length ? next.charCodeAt(pos) : 123; | |
} | |
str = prev.slice(0, pos - 1); // copy identical part of string | |
if (p == 96) { | |
// prev string equals beginning of next |
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
function removePrefix(originalString, prefix) { | |
if (typeof originalString !== 'string') return originalString; | |
return originalString.replace(new RegExp(`^${prefix}`), ''); | |
} | |
/** | |
* This would throw exception if one of parameters is not string | |
*/ | |
const removePrefix2 = (originalString, prefixToRemove) => { | |
if (typeof originalString !== 'string') return originalString; |
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
const express = require('express'); | |
const axios = require('axios'); | |
const Bluebird = require('bluebird'); | |
const { readFile: someOtherFnc } = require('fs'); | |
const app = express(); | |
// This is just a simulation | |
// real-life functions might not obviously simple for us to realize | |
async function simulateBlocker() { |
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
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.ap-southeast-1.amazonaws.com |
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
const { execSync } = require('child_process'); | |
const sourceBranch = process.argv[2]; | |
const targetBranch = process.argv[3]; | |
const getCommitsInfo = (branch) => { | |
const command = `git log --format="%h:::%s" ${branch}`; | |
const commitInfo = execSync(command, { encoding: 'utf8' }); | |
return commitInfo.trim().split('\n'); | |
}; |