Skip to content

Instantly share code, notes, and snippets.

View satishbabariya's full-sized avatar

Satish Babariya satishbabariya

View GitHub Profile
@satishbabariya
satishbabariya / state.js
Last active November 28, 2019 17:44
Using the State Hook
import {useAsync} from 'react-use';
const Demo = ({url}) => {
const state = useAsync(async () => {
const response = await fetch(url);
const result = await response.text();
return result
}, [url]);
return (
@satishbabariya
satishbabariya / links.txt
Created October 17, 2019 03:06
Ref Links to check
@satishbabariya
satishbabariya / commit.sh
Created October 13, 2019 04:09
Git, rewrite previous commit usernames and emails
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="oldEmail@xxx-MacBook-Pro.local"
CORRECT_NAME="Satish Babariya"
CORRECT_EMAIL="satish.babariya@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@satishbabariya
satishbabariya / Swift Property Wrappers.md
Last active September 30, 2019 15:24
Swift Property Wrappers

Swift Property Wrappers Written by Mattt June 24th, 2019 Years ago, we remarked that the “at sign” (@) — along with square brackets and ridiculously-long method names — was as characteristic of Objective-C as parentheses are to Lisp or punctuation is to Perl.

Then came Swift, and with it an end to these curious little 🥨-shaped glyphs. Or so we thought.

At first, the function of @ was limited to Objective-C interoperability: @IBAction, @NSCopying, @UIApplicationMain, and so on. But in time, Swift has continued to incorporate an ever-increasing number of @-prefixed attributes.

We got our first glimpse of Swift 5.1 at WWDC 2019 by way of the SwiftUI announcement. And with each “mind-blowing” slide came a hitherto unknown attribute: @State, @Binding, @EnvironmentObject…

MyService.zen.request(type: [Todo].self) { result in
switch result {
case let .success(todos):
// Array of [Todo]
case let .failure(error):
// error
}
}
// MARK: - Resty Protocol Implementation
extension MyService: Resty {
var host: String {
return "https://jsonplaceholder.typicode.com/"
}
var path: String {
return ""
}
enum MyService {
case zen
case showUser(id: Int)
case createUser(firstName: String, lastName: String)
case updateUser(id: Int, firstName: String, lastName: String)
case showAccounts
}
import Resty
struct Todo: Codable {
let id: Int
let title: String
let completed: Bool
}
enum FakeAPI: Resty {
case todos
  • Use curl to get the JSON response for the latest release
  • Use grep to find the line containing file URL
  • Use cut and tr to extract the URL
  • Use wget to download it
curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \" \
import * as React from "react";
import * as monaco from 'monaco-editor-core/esm/vs/editor/editor.main';
// (self as any).MonacoEnvironment = {
// getWorkerUrl: () => './editor.worker.bundle.js',
// };
class Editor extends React.Component {