Skip to content

Instantly share code, notes, and snippets.

View onattech's full-sized avatar
🌍
Working

Onat onattech

🌍
Working
View GitHub Profile
@onattech
onattech / Go Channels Example
Created March 30, 2022 09:15
Go Channels Example
func TestWithTimeOut(t *testing.T) {
timeout := time.After(3 * time.Second)
done := make(chan bool)
go func() {
// do your testing
time.Sleep(5 * time.Second)
done <- true
}()
select {
@onattech
onattech / Python
Created March 29, 2022 11:17
Python
import time
print("Pipeline id: caef17be-2f5d-40ff-8a02-84b921ec8f7d")
print("Node id: 40a51e57-0ba6-4160-9fa3-8080645753d6")
for x in range(100):
print(x)
time.sleep(1)
print("After sleep :" + str(x))
@onattech
onattech / Proxy example
Created March 23, 2022 09:52
Proxy example
const salary = new Proxy({hoursWorked: 0, payout: 0}, {
set:(o, _, value) => {
o.hoursWorked = value
o.payout = value * 10
}
})
salary.hoursWorked = 8 // { hoursWorked: 8, payout: 80 } 
console.log(salary.payout) // 80
// ----- Utility function
/**
* Takes two permission objects, returns the difference
* @example
* incoming = { view: false, edit: false, run: false, assign_permissions: false }
* outgoing = { view: true, edit: false, run: false, assign_permissions: false }
* returns ==> { view: true }
*/
function getDiff(incoming, outgoing) {
const change = {};
  1. Install airbnb-base npx install-peerdeps --dev eslint-config-airbnb-base

  2. Install required dependencies npm i -D typescript eslint prettier prettier-eslint-cli eslint-config-prettier eslint-plugin-prettier eslint-config-node eslint-plugin-node @typescript-eslint/eslint-plugin @typescript-eslint/parser

  3. Add .eslintrc.json with the following code:

{
  "root": true,
@onattech
onattech / postman-deb.sh
Created January 30, 2022 06:04 — forked from SanderTheDragon/postman-deb.sh
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file.
#!/bin/sh
curlExists=$(command -v curl)
echo "Testing Postman version"
targetName=""
if [ -z $curlExists ]; then
targetName=$(wget -S --spider "https://dl.pstmn.io/download/latest/linux64" 2>&1 | grep "Content-Disposition" | awk -F '=' '{ print $2 }')
else
@onattech
onattech / 8 Must know array methods.js
Created January 21, 2022 13:46
JS: 8 Must know array methods
const items = [
{ name: 'Bike', price: 100 },
{ name: 'TV', price: 200 },
{ name: 'Album', price: 10 },
{ name: 'Book', price: 5 },
{ name: 'Phone', price: 500 },
{ name: 'Computer', price: 1000 },
{ name: 'Keyboard', price: 25 }
]
@onattech
onattech / React: unpacked version with className and inline Styles and ...props spread
Created January 10, 2022 17:26
React: unpacked version with className and inline Styles and ...props spread
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@16.12.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.12.0/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.8.3/babel.js"></script>
<style>
.box {
border: 1px solid #333;
display: flex;
flex-direction: column;

Mutation with single variable, no return

In the backend

extend type Mutation {
    updateChangeMyPassword(password: String!): String
}

In the frontend

mutation updateChangeMyPassword($password: String!) {
@onattech
onattech / GO: Models & JSON.go
Created December 4, 2021 11:20
GO: Models & JSON
package main
import (
"encoding/json"
"log"
)
type User struct {
FirstName string `json:"first_name"` // key will be "first_name"
BirthYear int `json:"birth_year"` // key will be "birth_year"