Skip to content

Instantly share code, notes, and snippets.

View Christopher2K's full-sized avatar
🎯
Focusing

Christopher N. KATOYI Christopher2K

🎯
Focusing
View GitHub Profile
@Christopher2K
Christopher2K / obs.js
Created December 18, 2017 23:27
Create an observable
function myDataStream(observer) {
observer.next('Hello');
observer.next('Reactive');
observer.next('World');
}
const obsOne = Rx.Observable.create(myDataStream);
const subscriptionOne = obsOne.subscribe((data) => {
console.log(`Output Obs 1 : ${data}`);
});
@Christopher2K
Christopher2K / xhr.js
Last active April 9, 2018 21:15
Exemple XHR
// Initialisation de la requête XHR
const request = new window.XMLHttpRequest();
// Options de la requête
const options = {
method: 'GET',
url: 'http://myurl.com',
async: true
};
const url = 'http://myurl.com';
const options = { method: 'GET' };
// Appel de l'API Fetch
fetch(url, options)
.then((response) => response.json()) // Récupération des données
.then((data) => { // Callback de succès
window.alert('SUCCESS');
console.log(data);
})
// with [email protected] & [email protected]
import { ajax } from 'rxjs/observable/dom/ajax';
import { tap } from 'rxjs/operators';
const request = ajax.getJSON('http://myurl.com/data')
.pipe(
tap((jsonData) => console.log(jsonData))
);
// Appel HTTP
// with [email protected] & [email protected]
import { combineLatest } from 'rxjs/observable/combineLatest';
import { ajax } from 'rxjs/observable/dom/ajax';
import { tap, map } from 'rxjs/operators';
const BASE_URL = 'http://myurl.com';
// Retour un observable AJAX formé par un argument
function loginUserAccordingToData({ someDataThis }) {
return ajax.post(`${BASE_URL}/data`, { someDataThis })

Keybase proof

I hereby claim:

  • I am christopher2k on github.
  • I am christopher2k (https://keybase.io/christopher2k) on keybase.
  • I have a public key ASBbLb-XbTgjxD_4tBXA5mbRgFfx4b7rGzk3BaomHEsllgo

To claim this, I am signing this object:

@Christopher2K
Christopher2K / widget.dart
Created January 25, 2020 18:35
[Clear the stack and push a new screen] How to reset the stack and push a new screen a flutter to avoid the back behaviour #flutter #dart
class MyWidget extends StatelessWidget {
void _clearStackAndPush (BuildContext context) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/screen-name',
() => false,
);
}
@override
Widget build(BuildContext context) {
@Christopher2K
Christopher2K / widget.dart
Last active January 26, 2020 16:43
[Transparent App Bar] How to get a transparent app bar #flutter #dart
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text('Hello !'),
),
extendBodyBehindAppBar: true,
@Christopher2K
Christopher2K / widget.dart
Last active May 8, 2022 17:38
[Programmatically open drawer from scaffold directly] How to open scaffold's drawer with code #flutter #dart
class Widget extends StatelessWidget {
final GlobalKey<ScaffoldState> _drawerKey = GlobalKey();
void _openDrawer () {
_drawerKey.currentState.openDrawer();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@Christopher2K
Christopher2K / list_view_with_extra_elements.dart
Created March 9, 2020 16:08
Allow ListView.builder() to have leading / trailling elements
import 'package:flutter/material.dart';
class ListViewWithExtraElements<T> extends StatelessWidget {
final List<T> elements;
final List<Widget> leadingElements;
final List<Widget> trailingElements;
final Widget Function(BuildContext context, T element) itemBuilder;
ListViewWithExtraElements({
this.leadingElements = const [],