Skip to content

Instantly share code, notes, and snippets.

import my.androidapp
import my.androidapp.models
suspend fun getSpaceX(limit:Int) {
val vLimit = "\$limit"
val query = """
query($vLimit:Int)
{
launchesPast(limit: $vLimit) {
mission_name
@khle
khle / RequesterGQL.kt
Created November 11, 2021 13:59
RequesterGQL.kt
package my.androidapp
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import okio.IOException
import org.json.JSONObject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
@khle
khle / spaceX.kt
Created November 11, 2021 04:54
spaceX.kt
// To parse the JSON, install Klaxon and do:
//
// val spaceX = SpaceX.fromJson(jsonString)
package my.androidapp.models
import com.beust.klaxon.*
private val klaxon = Klaxon()
@khle
khle / spacex.gql
Created November 11, 2021 04:06
spacex gql
query($limit:Int)
{
launchesPast(limit: $limit) {
mission_name
launch_date_local
launch_site {
site_name_long
}
links {
article_link
@khle
khle / useImperativeHandle.tsx
Created October 22, 2021 15:49 — forked from lilywang711/useImperativeHandle.tsx
useImperativeHandle in typescript
// 定义
export interface MyInputHandles {
focus(): void;
}
const MyInput: RefForwardingComponent<MyInputHandles, MyInputProps> = (
props,
ref
) => {
const inputRef = useRef<HTMLInputElement>(null);
@khle
khle / Startup.cs
Created August 26, 2021 05:11
Startup.cs
//Other using import statements
//We only import 2 packages
using Azure.Security.KeyVault.Secrets;
using Azure.Identity;
//Other codes remain unchanged
//Only changes to be made are in this method ConfigureServices()
public void ConfigureServices(IServiceCollection services)
{
@khle
khle / app.js
Last active August 25, 2021 23:03
app.js
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
const { DefaultAzureCredential } = require('@azure/identity')
const credentials = new DefaultAzureCredential()
@khle
khle / User.ts
Created April 17, 2021 12:19
User.ts
// To parse this data:
//
// import { Convert, User } from "./file";
//
// const user = Convert.toUser(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface User {
@khle
khle / MainPageViewModel.xaml
Created November 3, 2020 12:33
MainPageViewModel
using Xamarin.Forms;
using System.ComponentModel;
using System.Threading.Tasks;
namespace AsyncButtonApp.ViewModels
{
public class MainPageViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:components="clr-namespace:AsyncButtonApp.Components"
xmlns:vm="clr-namespace:AsyncButtonApp.ViewModels"
x:Class="AsyncButtonApp.Views.MainPage"
Title="Main Page">
<ContentPage.BindingContext>
<vm:MainPageViewModel />
</ContentPage.BindingContext>