Skip to content

Instantly share code, notes, and snippets.

View adnaan's full-sized avatar
🎯
Focusing

Adnaan Badr adnaan

🎯
Focusing
View GitHub Profile
@adnaan
adnaan / services.js
Last active November 2, 2016 04:58
src/services.js
/*@flow*/
export async function getProducts() {
return fetch(`/api/products`).then(res => res.json())
}
export async function updateVote(id: { id: number }) {
return fetch('/api/products/vote/' + String(id)).then(res => res.json())
}
effects: { * query(_, { call, put }: { call: Function, put: Function }) {
const { success, data } = yield call(getProducts);
if (success) {
yield put({
type: 'querySuccess',
products: data,
});
}
},
* vote({ id }: { id: number }, { call, put }: { call: Function, put: Function }) {
reducers: {
query(state) {
return { ...state, loading: true, };
},
querySuccess(state, { payload }) {
return { ...state, loading: false, list: payload };
},
vote(state) {
return { ...state, loading: true };
},
reducers:{
query(state,{ payload }) {
return { ...state };
},
querySuccess(state, { payload }) {
return { ...state };
},
vote(state, { payload }) {
return { ...state };
},
@adnaan
adnaan / App.0.js
Created November 1, 2016 16:25
Default App.js
import React from 'react';
import logo from './logo.svg';
import './App.css';
const App = function() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
@adnaan
adnaan / index.js
Created November 1, 2016 16:21
popular-products/src/index.js
/*@flow*/
import React from 'react';
import { Router, Route } from 'dva/router';
import dva from 'dva';
import App from './App';
import model from './model';
import './index.css';
const app = dva();
app.model(model);
@adnaan
adnaan / api.go
Created November 1, 2016 15:56
Products API Server
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net"
"net/http"
"os"
app.model({
namespace: 'products',
state: {
list: [],
loading: false,
},
subscriptions: {
setup({ dispatch }) {
dispatch({ type: 'query' });
},
@adnaan
adnaan / script.sh
Last active September 25, 2019 13:02
Parse and execute a simple bash script.
ls -la
echo "hello"
tree
adb devices
adb wait-for-device #example of a long running task
@adnaan
adnaan / repo-apply.sh
Last active August 29, 2015 14:17 — forked from gipi/repo-apply.sh
#!/bin/sh
## Script to patch up diff reated by `repo diff`
# from https://groups.google.com/d/msg/repo-discuss/43juvD1qGIQ/7maptZVcEjsJ
if [ -z "$1" ] || [ ! -e "$1" ]; then
echo "Usages: $0 <repo_diff_file>";
exit 0;
fi
rm -fr _tmp_splits*