Skip to content

Instantly share code, notes, and snippets.

View xros's full-sized avatar
🎯
Focusing

Songhua Liu xros

🎯
Focusing
View GitHub Profile
@xros
xros / main.dart
Created December 27, 2021 06:36
Stream async* and Future async in Dart
Future<int> sumStream(Stream<int> stream) async {
int sum = 0;
await for (var i in stream) {
sum += i;
}
return sum;
}
Future<int> sumStream2(Stream<int> stream) =>
stream.reduce((previous, element) => previous + element);
@xros
xros / main.dart
Created December 26, 2021 17:28
Generics class -- class Stack<T>{} example
// generics class (very re-usable)
class Stack<T>{
final List<T> _items = [];
void push(T item) {
_items.add(item);
}
T pop() => _items.removeLast();
@xros
xros / main.dart
Last active December 26, 2021 14:52
simple copyWith method in Dart
// simple copyWith method
class Credentials {
const Credentials({this.email = '', this.password = ''});
final String email;
final String password;
Credentials copyWith({String? email, String? password}) {
return Credentials(
email: email ?? this.email,
password: password ?? this.password,
@xros
xros / main.dart
Last active December 26, 2021 14:51
.fromJson & .toJson example in Dart
// .fromJson , .toJson example in Dart
// .fromJson convert a Map Object to an Instance
// .toJson convert an Instance to a Map Object
class Person {
Person({required this.name, required this.age});
String name;
int age;
factory Person.fromJson(Map<String, Object> json) {
final name = json['name'];
import 'dart:io';
/*
* An implementation of shopping cart and checkout in Dart
*
*/
class Product {
const Product({required this.id, required this.name, required this.price});
final int id;
final String name;
class Person {
const Person(this.name, this.age);
final String name;
final int age;
factory Person.fromJson(Map<String, Object> json) {
final name = json['name'];
final age = json['age'];
if (name == null) {
import 'dart:math';
/*
We can use abstract classes to define an interface that can be implemented by subclasses
Very powerful: decouples code that uses an interface from its implementation
printArea() doesn't need to know that Sqaure and Circle even exist.
only needs a Shape argument with an area property
*/
# retrieve webelement
input = driver.find_element_by_xpath("//*[@name='fieldname']")
# set attribute from js script referencing webelement found in python code
driver.execute_script("arguments[0].setAttribute('value', 'new value!')", input);
# or
driver.execute_script("arguments[0].setAttribute('value', arguments[1])", input, 'new value!');
# Code for File Upload
file_input = driver.find_element_by_id("uploadBtn")
file_input.send_keys("/absolute/path/to/file")
@xros
xros / steam_console_params.txt
Created January 24, 2018 00:50 — forked from davispuh/steam_console_params.txt
Steam client parameters, consoles commands and variables
-480p - Run tenfoot in 480p rather than 1080p
-720p - Run tenfoot in 720p rather than 1080p
-accountrecovery - Perform account recovery
-all_languages - show longest loc string from any language
-bigpicture - Start in Steam Big Picture mode
-cafeapplaunch - Launch apps in a cyber cafe context
-candidates - Show libjingle candidates for local connection as they are processed
-ccsyntax - Spew details about the localized strings we load
-community - Set the community URL
-complete_install_via_http - Run installation completion over HTTP by default
server {
listen 80;
server_name www.example.com;
rewrite ^ http://example.com$request_uri? permanent; #301 redirect
}
server {
listen 80;
server_name example.com;