Skip to content

Instantly share code, notes, and snippets.

View mrsoftware's full-sized avatar
🏠
Working from home

Mohammad Rajabloo mrsoftware

🏠
Working from home
View GitHub Profile
@mrsoftware
mrsoftware / Hex to Rgba
Last active December 2, 2018 09:29
Functions for convert HEX to RGBA
// function for calculating 6 letters hex value
export const hexToRgbaFull = (hex, opacity = 1) => {
hex = ( hex.charAt(0) === "#" ? hex.substr(1) : hex );
var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16);
return `rgba( ${r}, ${g}, ${b}, ${opacity} )`;
}
@mrsoftware
mrsoftware / start-webcam
Created February 22, 2019 12:24
start webcam in linux ubuntu
mplayer -tv driver=v4l2:width=270:height=190: -vo xv -vf mirror tv:// -geometry "99%:99%" -noborder -ontop
@mrsoftware
mrsoftware / isPlainObject.js
Last active May 21, 2019 14:29
check if is object in JavaScript
/**
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
@mrsoftware
mrsoftware / cloudSettings
Created June 4, 2019 15:17
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-06-04T15:16:59.712Z","extensionVersion":"v3.2.9"}
import types from "./App/components/Post/types";
const schema = [
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "video,image,text", model: 'rec', item: {} },
{ type: "video,image,text", model: 'rec', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "text,image,video", model: 'squ', item: {} },
{ type: "video,image,text", model: 'big', item: {} },
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" Add plugins here
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'gkapfham/vim-vitamin-onec'
Plugin 'itchyny/lightline.vim'
@mrsoftware
mrsoftware / pars config file with viper
Created September 27, 2019 10:33
With this method you can open any config file that supported by viper
// go run main.go --config ./config/config.yaml
// go run main.go --config ./config/config.json
// go run main.go --config ./config/config.toml
// file name also can be any name : config, app and etc.
var configFile = flag.String("config", "./config/config.yaml", "Address of config file")
func parseConfig() {
dir, file := path.Split(*configFile)
ext := path.Ext(file)
func init() {
viper.SetConfigFile(`config.json`)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
if viper.GetBool(`debug`) {
fmt.Println("Service RUN on DEBUG mode")
}
dbHost := viper.GetString(`database.host`)
dbPort := viper.GetString(`database.port`)
dbUser := viper.GetString(`database.user`)
dbPass := viper.GetString(`database.pass`)
dbName := viper.GetString(`database.name`)
connection := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", dbUser, dbPass, dbHost, dbPort, dbName)
val := url.Values{}
val.Add("parseTime", "1")
val.Add("loc", "Asia/Jakarta")
dsn := fmt.Sprintf("%s?%s", connection, val.Encode())
`SELECT
*
FROM
Posts
WHERE
CreateAt `+direction+` (SELECT CreateAt FROM Posts WHERE Id = :PostId)
AND ChannelId = :ChannelId
AND DeleteAt = 0
ORDER BY CreateAt `+sort+`
LIMIT :Limit