Skip to content

Instantly share code, notes, and snippets.

Satish Babariya satishbabariya

Block or report user

Report or block satishbabariya

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:25b09a366443daec63d594ad3e39f812
/**
* Check user is admin or not
* @param {*} req Express req Object
* @param {*} res Express res Object
* @param {*} next Express next Function
*/
const isAdmin = async (req, res, next) => {
if (!req.currentUser) {
return next(new Exception('Error in checking current user', 500));
@satishbabariya
satishbabariya / state.js
Last active Nov 28, 2019
Using the State Hook
View state.js
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 Oct 17, 2019
Ref Links to check
View links.txt
@satishbabariya
satishbabariya / commit.sh
Created Oct 13, 2019
Git, rewrite previous commit usernames and emails
View commit.sh
#!/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
View Swift Property Wrappers.md

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…

View SampleRequest.swift
MyService.zen.request(type: [Todo].self) { result in
switch result {
case let .success(todos):
// Array of [Todo]
case let .failure(error):
// error
}
}
View MyServiceExtension.swift
// MARK: - Resty Protocol Implementation
extension MyService: Resty {
var host: String {
return "https://jsonplaceholder.typicode.com/"
}
var path: String {
return ""
}
View MyService.swift
enum MyService {
case zen
case showUser(id: Int)
case createUser(firstName: String, lastName: String)
case updateUser(id: Int, firstName: String, lastName: String)
case showAccounts
}
View FakeAPI.swift
import Resty
struct Todo: Codable {
let id: Int
let title: String
let completed: Bool
}
enum FakeAPI: Resty {
case todos
View One Liner to Download the Latest Release from Github Repo.md
  • 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 \" \
You can’t perform that action at this time.