Skip to content

Instantly share code, notes, and snippets.

View mkamrani's full-sized avatar
💭
Building Utopiops & Do10X

Sam(Mohsen) Kamrani mkamrani

💭
Building Utopiops & Do10X
View GitHub Profile
@ryanfitz
ryanfitz / golang-nuts.go
Created December 2, 2012 22:45
two ways to call a function every 2 seconds
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl
@timhudson
timhudson / pre-save-update.js
Last active July 3, 2020 08:58
Update the `lastUpdated` field every time a mongoose model is saved
var schema = mongoose.Schema({
lastUpdated: {type: Date, 'default': Date.now}
})
schema.pre('save', function(next) {
this.lastUpdated = Date.now()
next()
})
@thebigredgeek
thebigredgeek / express_with_jwt.js
Last active November 5, 2023 18:35
Express API with JWT
var express = require('express')
, jwtMiddleware = require('express-jwt')
, bodyParser = require('body-parser')
, cookieParser = require('cookie-parser')
, cors = require('cors');
// We pass a secret token into the NodeJS process via an environment variable.
// We will use this token to sign cookies and JWTs
var SECRET_TOKEN = process.env.SECRET_TOKEN;
@paladini
paladini / aws-ec2-redis-cli.md
Last active June 21, 2024 18:16 — forked from todgru/aws-ec2-redis-cli.md
AWS redis-cli without redis server on AWS EC2

Setup redis-cli without the whole Redis Server on AWS EC2

This fast tutorial will teach you how to install redis-clion AWS EC2 without having to install the whole Redis Server. Firstly, SSH into your EC2 instance and run the following command:

$ sudo yum install gcc

This may return an "already installed" message, but that's OK. After that, just run:

$ wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make && sudo cp src/redis-cli /usr/local/bin/ && sudo chmod 755 /usr/local/bin/redis-cli

@tkrajina
tkrajina / unmarshal_interface.go
Last active June 22, 2024 14:24
Unmarshal JSON to specific interface implementation
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Something interface{}
@lummie
lummie / enum.go
Last active June 16, 2024 16:19
Golang Enum pattern that can be serialized to json
package enum_example
import (
"bytes"
"encoding/json"
)
// TaskState represents the state of task, moving through Created, Running then Finished or Errorred
type TaskState int
@vmandic
vmandic / dotnet core .gitignore
Last active July 18, 2024 09:03
A default .NET Core project .gitignore file - or just type `dotnet new gitignore`
# From .NET Core 3.0 you can use the command: `dotnet new gitignore` to generate a customizable .gitignore file
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
# Visual Studio Code
.vscode
@kshailen
kshailen / Connecting_postgress_RDS_from_local_via_bastion.md
Last active July 8, 2024 19:04
Ways to connect to postgress RDS instance from bastion host and from local host

When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management.

How can you easily access and manage your secured data?

basic_RDS_bastion_architecture

There are two basic ways to acees it.

  1. Access postgres RDS from bastion host. There are following requirements for this.
@mkamrani
mkamrani / add-gtag.sh
Created May 30, 2023 01:12
Add Google Analytics to all HTML files in a directory
#!/bin/bash
# From: dotenx.com
# description:
# Add Google Analytics to all HTML files in a directory. Google Analytics code should be in a file called google-analytics in the same directory as this script.
# usage:
# ./add-gtag.sh directory