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 chrono::{Duration, NaiveDate, NaiveDateTime, NaiveTime, Weekday, Datelike}; | |
| /// Gets the next day of the week at the given time. If the current date is already the given | |
| /// weekday **and** after the given time, it will return the next one. | |
| fn get_next_day_of_week_at_time( | |
| weekday: Weekday, | |
| at_time: NaiveTime, | |
| ) -> Option<NaiveDateTime> { | |
| let mut date = chrono::offset::Local::now(); | |
| let one_day = Duration::days(1); |
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 futures_retry::{ErrorHandler, RetryPolicy, FutureRetry}; | |
| use rand::Rng; | |
| use std::time::Duration; | |
| #[macro_export] | |
| macro_rules! retry { | |
| ( $x:expr, $d:expr, $n:expr ) => { | |
| { | |
| FutureRetry::new(move || $x, RetryHandler::new($d, $n)) | |
| .await |
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 expensive() -> bool { | |
| println!("expensive"); | |
| true | |
| } | |
| fn main() { | |
| // expensive is not executed when previous statement is false | |
| if false && expensive() { | |
| println!("Hello, world!"); | |
| } |
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
| sed -n -e '/CREATE TABLE.*`table_name`/,/Table structure for table/p' db.sql > table.sql |
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
| CREATE TABLE colors ( | |
| id serial NOT NULL PRIMARY KEY, | |
| name VARCHAR(255) NOT NULL, | |
| hex VARCHAR(6) NOT NULL | |
| ); | |
| INSERT INTO colors | |
| (name, hex) | |
| VALUES | |
| ('Hot Pink', 'FF0066'), | |
| ('Orange', 'FF9900'), |
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
| SELECT paints.rgb1 | |
| FROM paints | |
| INNER JOIN bptf_prices | |
| ON bptf_prices.defindex = paints.defindex | |
| WHERE | |
| bptf_prices.craftable = true | |
| ORDER BY | |
| bptf_prices.currency ASC, | |
| bptf_prices.value DESC; |
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
| SELECT | |
| TABLE_NAME AS `Table`, | |
| ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` | |
| FROM | |
| information_schema.TABLES | |
| WHERE | |
| TABLE_SCHEMA = "name_of_database" | |
| ORDER BY | |
| (DATA_LENGTH + INDEX_LENGTH) | |
| DESC; |
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 fs = require('fs'); | |
| const filepath = process.argv[2]; | |
| const filename = filepath.match(/([a-z_0-9]+)\.rs$/)[1]; | |
| const data = fs.readFileSync(filepath, 'utf8'); | |
| const structs = data | |
| .split('\n') | |
| .filter(line => /^pub struct /.test(line)) | |
| .map(line => line.replace(/(pub struct | \{)/g, '')); | |
| const tab = ' '; |
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::time::{SystemTime, UNIX_EPOCH}; | |
| use sha1::Sha1; | |
| use hmac::{Hmac, Mac, NewMac}; | |
| use std::io::Cursor; | |
| use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; | |
| use base64; | |
| const CHARS: &'static [char] = &['2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', | |
| 'N', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y']; |
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 tokio::sync::{mpsc, oneshot}; | |
| use async_std::task::sleep; | |
| use std::time::Duration; | |
| #[tokio::main] | |
| async fn main() { | |
| let (main_tx, mut main_rx) = mpsc::channel(16); | |
| tokio::spawn(async move { | |
| println!("Hello?"); |