Skip to content

Instantly share code, notes, and snippets.

View utarn's full-sized avatar

Utharn Buranasaksee utarn

View GitHub Profile
@utarn
utarn / stop.sh
Created December 19, 2018 05:01
CLOUD COMPUTING CLASS: script to bulk stop
for i in $(seq -w $1 $2)
do
num=$(printf %02d $i)
VMID=`vim-cmd vmsvc/getallvms |grep CentOS7-$num | cut -f1 -d' '`
vim-cmd vmsvc/power.shutdown $VMID
done
@utarn
utarn / autologin.sh
Created December 23, 2018 14:15
CLOUD COMPUTING CLASS: Auto login script
#!/bin/bash
#
# Username is 1111111111
# Password is 2222222222
# Change them to yours.
#
#
curl -k -e "https://login.rmutsb.ac.th/login.php" "https://login.rmutsb.ac.th/login.php" -d "_u=1111111111&_p=2222222222&a=a&web_host=login.rmutsb.ac.th&web_host4=auth4.rmutsb.ac.th&_ip4=&web_host6=auth6.rmutsb.ac.th&_ip6="
@utarn
utarn / ApplicationDbContext.cs
Created January 1, 2019 14:04
ASP.NET Core with Postgresql convert Capitalized alphabet to Snake
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var mapper = new Npgsql.NpgsqlSnakeCaseNameTranslator();
var types = modelBuilder.Model.GetEntityTypes().ToList();
// Refer to tables in snake_case internally
types.ForEach(e => e.Relational().TableName = mapper.TranslateMemberName(e.Relational().TableName));
// Refer to columns in snake_case internally
types.SelectMany(e => e.GetProperties())
@utarn
utarn / docker-stack.yml
Last active January 9, 2019 07:27
Docker stack 3.0
version: '3.7'
services:
mariadb:
image: 'bitnami/mariadb:latest'
environment:
- MARIADB_USER=bn_wordpress
- MARIADB_DATABASE=bitnami_wordpress
- MARIADB_PASSWORD=bn_password
- ALLOW_EMPTY_PASSWORD=yes
volumes:
@utarn
utarn / step to follow
Last active January 9, 2019 08:10
CLOUD COMPUTING CLASS: Docker Swarm
1. Update Kernel to 4.20
2. Install docker, docker-compose
3. Enable ip forwarding
Add net.ipv4.ip_forward=1 to /etc/sysctl.conf
- Restart network service
- Check: sysctl net.ipv4.ip_forward
4. Install iptables-services via yum
@utarn
utarn / LineNotify.cs
Created July 25, 2019 00:57
Web Service Technology - Line Notify function C#
public async Task<bool> SendNotify(string accesstoken, string Msg)
{
try
{
var client = new HttpClient();
client.BaseAddress = new Uri("https://notify-api.line.me/api/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken);
var nvc = new List<KeyValuePair<string, string>>();
nvc.Add(new KeyValuePair<string, string>("message", Msg));
@utarn
utarn / TokenController.cs
Last active June 2, 2021 11:39
ASP.NET Core JWT Function part 1/2
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
public TokenController(IConfiguration config, ApplicationDbContext dbContext)
{
_config = config;
@utarn
utarn / Startup.cs
Last active September 16, 2019 23:27
ASP.NET Core JWT Function part 2/2
// appSettings.json
"Jwt": {
"Key": "secret-key",
"Issuer": "https://localhost:5000/"
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
@utarn
utarn / dhcpd.conf
Created July 30, 2019 07:49
Sample & Simple dhcpd.conf
default-lease-time 86400; # 24 hours
max-lease-time 172800; # 48 hours
subnet 192.168.13.0 netmask 255.255.255.0 {
option domain-name "myrmutsb.com";
option domain-name-servers 8.8.8.8, 8.8.4.4;
option routers 192.168.13.1;
option subnet-mask 255.255.255.0;
range 192.168.13.101 192.168.13.200;
}
@utarn
utarn / FileDownloader.cs
Created August 23, 2019 02:38 — forked from yasirkula/FileDownloader.cs
C# Download Public File From Google Drive™ (works for large files as well)
using System;
using System.IO;
using System.Net;
public static class FileDownloader
{
private const string GOOGLE_DRIVE_DOMAIN = "drive.google.com";
private const string GOOGLE_DRIVE_DOMAIN2 = "https://drive.google.com";
// Normal example: FileDownloader.DownloadFileFromURLToPath( "http://example.com/file/download/link", @"C:\file.txt" );