Skip to content

Instantly share code, notes, and snippets.

View legalcodes's full-sized avatar

Jon Tippens legalcodes

  • San Francisco, California
View GitHub Profile
@legalcodes
legalcodes / README.md
Created February 4, 2016 00:08 — forked from mbostock/.block
TopoJSON Examples

Some of these files are from the us-atlas:

  • us.json - make topo/us-10m.json
  • us-congress-113.json - make topo/us-congress-10m.json

Others are from the world-atlas:

  • world-50m.json - make topo/world-50m.json
  • world-110m.json - make topo/world-110m.json

Applescript for disconnecting and re-connecting wired ethernet connection

tell application "System Preferences"
	activate
	set the current pane to pane id "com.apple.preference.network"
	get the name of every anchor of pane id "com.apple.preference.network"
	reveal anchor "Ethernet" of pane id "com.apple.preference.network"
	
@legalcodes
legalcodes / gist:c12ed6dcd5c37a610424eae7e4a5e8ee
Created January 11, 2019 23:06
Override .git credential helper setting
git -c credential.helper=
// https://stackoverflow.com/questions/13198143/how-do-i-disable-gits-credential-helper-for-a-single-repository/13203623#13203623
@legalcodes
legalcodes / hint.txt
Last active November 25, 2019 23:45
Practice Using async and await
Did you remember to add the async keyword to the reportUserRole function?
Did you remember to use the await keyword before invoking fetchRole?
Remember: reportUserRole needs to return a future!
@legalcodes
legalcodes / main.dart
Last active November 25, 2019 23:42
Putting It All Together (More practice with async and await)
// Part 1
addHello(){}
// Part 2
//You can call the provided async function fetchUsername to return the username
greetUser(){}
// Part 3
//You can call the provided async function logoutUser to logout the user
sayGoodbye(){}
@legalcodes
legalcodes / main.dart
Last active April 26, 2019 20:09
async example 1
// Synchronous code
String createOrderMessage () {
var order = getUserOrder();
return 'Your order is: $order';
}
// Asynchronous code
Future getUserOrder() {
return Future.delayed(Duration(seconds: 4), () => 'Large Latte');
}
@legalcodes
legalcodes / mock_result.dart
Created April 23, 2019 20:17
Mock _result function
void _result(bool success, [List<String> messages]) {
final joinedMessages = messages?.map((m) => m.toString())?.join(',') ?? '';
print('success: $success, "messages": $joinedMessages');
}
@legalcodes
legalcodes / main.dart
Last active November 27, 2019 17:21
Why Async Matters
// This example shows how *not* to write asynchronous Dart code.
String createOrderMessage () {
var order = fetchUserOrder();
return 'Your order is: $order';
}
Future<String> fetchUserOrder() {
// Imagine that this function is more complex and slow
return Future.delayed(Duration(seconds: 4), () => 'Large Latte');
@legalcodes
legalcodes / main.dart
Last active November 25, 2019 23:23
What is a future? (completed)
Future<void> fetchUserOrder() {
// Imagine that this function is fetching user info from another service or database
return Future.delayed(Duration(seconds: 3), () => print('Large Latte'));
}
void main() {
fetchUserOrder();
print('Fetching user order...');
}
@legalcodes
legalcodes / main.dart
Last active June 19, 2019 16:26
getUserOrder asynchronous
// Asynchronous
Future<String> createOrderMessage () async {
var order = await getUserOrder();
return 'Your order is: $order';
}
// Asynchronous
Future<String> getUserOrder() {
return Future.delayed(Duration(seconds: 4), () => 'Large Latte');
}