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::io; | |
| use rand::Rng; | |
| fn main() { | |
| println!("Welcome to Magic 8-Ball"); | |
| loop { | |
| println!("What is your question?"); | |
| let mut question = String::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
| use rand::Rng; | |
| use std::cmp::Ordering; | |
| use std::io; | |
| fn main() { | |
| loop { | |
| let secret_number = rand::thread_rng().gen_range(1..101); | |
| println!("Guess the number"); |
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
| export default function Home() { | |
| return( | |
| <div | |
| style={{ | |
| position: 'absolute', | |
| display: 'flex', | |
| alignItems: 'center', | |
| height: '100%', | |
| width: '100%', | |
| top: 0, |
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
| export default function Home() { | |
| return( | |
| <div | |
| style={{ | |
| position: 'absolute', | |
| height: '100%', | |
| width: '100%', | |
| top: 0, | |
| bottom: 0, | |
| margin: 0, |
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 json = '{"foo": { "bar": { "baz": {"a": 1, "b": 2, "c": 3}}}}'; | |
| const parsedJSON = JSON.parse(json); | |
| /* | |
| * DANGER! This line will run, but is not fail-safe, could crash if foo, bar, | |
| * baz or a is missing or undefined | |
| */ | |
| console.log(parsedJSON.foo.bar.baz.a); |
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
| from flask import Flask, Response, render_template, request | |
| app = Flask(__name__) | |
| @app.route('/', methods=['GET', 'POST']) | |
| def index(): | |
| user_agent = request.headers.get('User-Agent') | |
| user_agent = user_agent.lower() |
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
| enum Foo { | |
| A = "ActivityCode.Foo.A", | |
| B = "ActivityCode.Foo.B", | |
| C = "ActivityCode.Foo.C", | |
| } | |
| enum Bar { | |
| A = "ActivityCode.Bar.A", | |
| B = "ActivityCode.Bar.B", | |
| C = "ActivityCode.Bar.C", |
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
| package blog.topherpedersen.uselesscameraapp; | |
| import androidx.appcompat.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.Toast; | |
| public class MainActivity extends AppCompatActivity { |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <Button |
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
| // Duplicates: Bob, Aaron, Frank | |
| const arrayWithDuplicates = ["Aaron", "Bob", "Chris", "Dave", "Edward", "Bob", "Aaron", "Frank", "George", "Frank", "Henry", "Bob", "Bob", "Aaron", "Aaron", "Frank"]; | |
| function stripDuplicates(arrayWithDuplicates) { | |
| let uniques = []; | |
| arrayWithDuplicates.forEach( (value, index) => { | |
| const indexWhereValueFirstAppears = arrayWithDuplicates.findIndex( (value_) => { | |
| return value_ === value; | |
| }); | |
| if (index === indexWhereValueFirstAppears) { |