Skip to content

Instantly share code, notes, and snippets.

View ruan65's full-sized avatar
🎯
Focusing

Andrew ruan65

🎯
Focusing
View GitHub Profile
syntax="proto3";
message Student {
int32 id = 1;
string name = 2;
}
message Question {
int32 id = 1;
string text = 2;
@ruan65
ruan65 / ui_helpers.dart
Last active May 1, 2020 16:54
Flutter UI Helpers
import 'package:flutter/material.dart';
abstract class ScreenSize {
static Size size(BuildContext context) {
return MediaQuery.of(context).size;
}
static double height(BuildContext context,
{double dividedBy = 1, double reducedBy = 0.0}) {
return (ScreenSize.size(context).height - reducedBy) / dividedBy;
@Cheesetouched
Cheesetouched / .gitignore
Created March 3, 2019 04:18
Standardised gitignore for your Flutter apps & Dart projects
### Flutter Generated
# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
@ruan65
ruan65 / wiki.sh
Created February 15, 2019 10:05
linux ubuntu useful commands
# add path example
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.bashrc
source .bashrc
# install dart https://www.dartlang.org/tools/sdk#install
@ruan65
ruan65 / bloc_example.dart
Created February 12, 2019 16:37
Bloc Flutter Example
class CounterState {
final int counter;
CounterState._(this.counter);
factory CounterState.nextState(int times) => CounterState._(times);
}
class CounterBloc extends Bloc<CounterEvent, CounterState> {
@override
CounterState get initialState => CounterState.nextState(0);
@ruan65
ruan65 / user.xml
Last active March 1, 2019 14:10
Android Studio Live Templates code snippets /home/a/.AndroidStudio3.3/config/templates/user.xml on Ubuntu /Users/a/Library/Preferences/AndroidStudio3.3/templates/user.xml on Mac
<templateSet group="user">
<template name="imf" value="import 'package:flutter/material.dart';" description="Import flutter material" toReformat="false" toShortenFQNames="true">
<context>
<option name="DART" value="true" />
</context>
</template>
<template name="fblo" value="import 'dart:async';&#10;import 'package:bloc/bloc.dart';&#10;&#10;class $name$Bloc extends Bloc&lt;$event$, $state$&gt; {&#10;&#10;&#10; @override&#10; $name$State get initialState =&gt; null;&#10;&#10; @override&#10; Stream&lt;$name$State&gt; mapEventToState($state$ currentState, $event$ event) {&#10; $cursor$&#10; return null;&#10; }&#10;&#10;}" description="flutter bloc class template" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="event" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="state" expression="" defaultValue="" alwaysStopAt="true" />
@ruan65
ruan65 / stringSubscript.swift
Created March 7, 2017 22:35
swift better work with strings
extension String {
subscript (i: Int) -> String? {
if characters.count > i && i >= 0 {
return String(Array(self.characters)[i])
}
return nil
}
subscript (r: Range<Int>) -> String? {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
// Needed in AndroidManifest:
<!-- Permission for using NFC hardware -->
<uses-permission android:name="android.permission.NFC"/>
<!-- Forcing device to have NFC hardware -->
<uses-feature android:name="android.hardware.nfc" android:required="true"/>
<!-- Registering app for receiving NFC's TAG_DISCOVERED intent -->
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>