Skip to content

Instantly share code, notes, and snippets.

View santosh's full-sized avatar
:octocat:

Santosh Kumar santosh

:octocat:
View GitHub Profile
#!/bin/bash
unknown_os ()
{
echo "Unfortunately, your operating system distribution and version are not supported by this script."
echo
echo "You can override the OS detection by setting os= and dist= prior to running this script."
echo "You can find a list of supported OSes and distributions on our website: https://packagecloud.io/docs#os_distro_version"
echo
echo "For example, to force Ubuntu Trusty: os=ubuntu dist=trusty ./script.sh"
@santosh
santosh / timezones.go
Created August 24, 2023 05:30
Convert from one timezone to another in Go.
package main
import (
"fmt"
"time"
)
// tsConvert convert timestamp in "YYYY-MM-DDTHH:MM" format from one timezone to another
func tsConvert(ts string, fromTZ string, toTZ string) (string, error) {
la, _ := time.LoadLocation(fromTZ)
@santosh
santosh / files.go
Last active November 28, 2022 07:03
Mocking a filesystem call
package findgo
import (
"io/fs"
"path/filepath"
)
func Files(folder fs.FS) int {
var count int
fs.WalkDir(folder, ".", func(p string, d fs.DirEntry, err error) error {
@santosh
santosh / main.go
Created November 1, 2022 08:13
Interface as value.
package main
import (
"fmt"
)
type Animal interface {
Speak() string
}
@santosh
santosh / iptables_examples.go
Created August 25, 2022 07:39
go-iptables examples
package main
func main() {
// if ipt, err := iptables.NewWithProtocol(iptables.ProtocolIPv4); err == nil {
// rule := []string{"-m", "ttl", "--ttl-eq", "1", "-p", "tcp", "-d", raddr.IP.String(), "--dport", fmt.Sprint(raddr.Port), "-j", "DROP"}
// if exists, err := ipt.Exists("filter", "OUTPUT", rule...); err == nil {
// if !exists {
// if err = ipt.Append("filter", "OUTPUT", rule...); err == nil {
// conn.iprule = rule
// conn.iptables = ipt
@santosh
santosh / RockPaperScissors.java
Created April 10, 2022 01:08
Rock Paper Scissors game in Java.
package practice;
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors {
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
Random r = new Random();
@santosh
santosh / gussing_game.rs
Created March 28, 2022 15:00
Guess the number game in Rust.
use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1..101);
loop {
@santosh
santosh / jenkins.yml
Created November 6, 2021 14:12
Playbook for installation of Jenkins server on RHEL derived distros.
---
- name: install and start jenkins
hosts: web
become: yes
tasks:
- name: add redhat-stable jenkins repo
ansible.builtin.get_url:
url: https://pkg.jenkins.io/redhat-stable/jenkins.repo
dest: /etc/yum.repos.d/jenkins.repo
@santosh
santosh / nginx.conf
Created October 28, 2021 16:20
nginx.conf for Jenkins reverse proxy
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
@santosh
santosh / AsteroidGrid.js
Created August 2, 2021 08:16
Event passing to parent and back.
// requires Vue.js and Bootstrap
Vue.component('asteroid-grid', {
props: ['asteroids', 'header'],
data: function () {
return {
showSummary: true
}
},
computed: {
numAsteroids: function () {