Skip to content

Instantly share code, notes, and snippets.

View ak9999's full-sized avatar
🎯
Focusing

Abdullah "AJ" Khan ak9999

🎯
Focusing
  • New York
View GitHub Profile
@ak9999
ak9999 / rust_guessing_game_print.rs
Created April 6, 2017 20:56
Guessing Game Tutorial from Rust docs using the `print!` macro.
extern crate rand; // rand crate for generating random numbers
use std::io; // io library from standard library
use std::io::Write; // Needed for flushing stdout after print.
use std::cmp::Ordering; // For comparing values
use rand::Rng; // from rand crate
fn main() {
println!("Guess the number, from 0 to 100."); // Greet user
let secret_number = rand::thread_rng().gen_range(0, 101);
@ak9999
ak9999 / k-th_smallest_element.cpp
Last active March 14, 2017 02:39
Find the second smallest element
// Abdullah Khan
// Compile with: g++ -std=c++14 k-th_smallest_element.cpp
// Second smallest value in unsorted array/vector/list
#include <iostream>
#include <vector>
#include <utility>
#include <random>
using Generator = std::mt19937;
@ak9999
ak9999 / reverse.cpp
Created March 13, 2017 16:18
reverse a string
// Compile with g++ -std=c++14 reverse.cpp
#include <iostream> // std::cout
#include <string> // std::string
#include <utility> // std::swap
using namespace std;
string reverse(string & s) {
// Ternary conditional
// If string is of even length, n = string length
// File: progress_bar_example.cpp
// Modified from https://stackoverflow.com/questions/14539867/how-to-display-a-progress-indicator-in-pure-c-c-cout-printf
// Compile with:
// g++ -std=c++14 -o prog progress_bar_example.cpp -Werror -pedantic
#include <iostream>
#include <chrono> // for literals
#include <thread> // for cross-platform sleep
int main()
{
/*
Author: Abdullah Khan
Purpose: Show off C++14 automatic return type deduction.
Build: g++ -std=c++14 automatic_return_type_deduction.cpp -o create_pair
Run: Invoke create_pair with two parameters: words or numbers work best.
*/
#include <iostream>
#include <utility>