Skip to content

Instantly share code, notes, and snippets.

View electron0zero's full-sized avatar
🎯
Focusing

Suraj Nath electron0zero

🎯
Focusing
View GitHub Profile
@electron0zero
electron0zero / optparse_example.rb
Created May 30, 2019 10:55
Ruby optparse multiple args example
require 'optparse'
require 'optparse/time'
require 'ostruct'
require 'pp'
class OptparseExample
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
#
@electron0zero
electron0zero / kubectl_aliases.sh
Last active October 19, 2023 18:58
Context and namesapce aware kubectl aliaes
#@IgnoreInspection BashAddShebang
# Setup:
# 1. source this script in your ~/.bashrc
# source "~/kubectl_aliases.sh"
# Usage:
# - use kctx to set context
# - use kns to set namespace
# - kjmp to jump to a set list of cluster and namespace pair from a local text file
# - now use kctl instead of kubectl and all the commands will have correct namespace and context passed
# - try other shorthand aliases for frequently used commands
@electron0zero
electron0zero / menu.sh
Created April 9, 2019 21:39
Interactive menu in Bash - Allow user to select form list of options
#!/bin/bash
echo "Select any of the files or directory"
echo "Enter the number of the file or directory:"
select item in *; do
# wait for input and break when we get it
break
done
echo "You selected item: $item with option: $REPLY"
@electron0zero
electron0zero / hello.html
Created April 4, 2019 20:22
Hello from Suraj 👋
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://bungee-project.djr.com/resources/web/bungee.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://bungee-project.djr.com/resources/web/bungee.js"></script>
</head>
<body>
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Suraj subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="Comics" title="Comics">
<outline type="rss" text="CommitStrip" title="CommitStrip" xmlUrl="http://www.commitstrip.com/en/feed/" htmlUrl="http://www.commitstrip.com"/>
<outline type="rss" text="turnoff.us - geek comic site" title="turnoff.us - geek comic site" xmlUrl="http://turnoff.us/feed.xml" htmlUrl="http://turnoff.us/"/>
@electron0zero
electron0zero / .odbc.ini
Created March 5, 2019 12:40
Setup MapR ODBC for Apache Drill in CentOS 7
[ODBC]
Trace=no
[ODBC Data Sources]
MapR Drill 32-bit=MapR Drill ODBC Driver 32-bit
MapR Drill 64-bit=MapR Drill ODBC Driver 64-bit
[MapR Drill 32-bit]
# This key is not necessary and is only to give a description of the data source.
Description=MapR Drill ODBC Driver (32-bit) DSN
@electron0zero
electron0zero / storage.go
Created March 4, 2019 10:04
Golang upload file to GCS
package server
import (
"context"
"fmt"
"io"
"os"
"cloud.google.com/go/storage"
@electron0zero
electron0zero / sidekiq_stats.rb
Last active January 22, 2019 17:49
Monitor sidekiq stats
# overall and per-queue sidekiq stats
def compute_sidekiq_stats
workers = Sidekiq::ProcessSet.new
# compute per queue workers
total_capacity = 0
total_busy = 0
queue_workers = {}
workers.each do |worker|
total_capacity += worker['concurrency'].to_i
total_busy += worker['busy'].to_i
@electron0zero
electron0zero / slack_delete.rb
Created January 8, 2019 17:47 — forked from jamescmartinez/slack_delete.rb
This Ruby script will bulk remove all Slack files older than 30 days. Just add your API token from https://api.slack.com/web#authentication into the token quotes at the top of the file.
require 'net/http'
require 'json'
require 'uri'
@token = ''
def list_files
ts_to = (Time.now - 30 * 24 * 60 * 60).to_i # 30 days ago
params = {
token: @token,
@electron0zero
electron0zero / ssl_test.rb
Created January 3, 2019 11:16
Check for valid SSL cert in Ruby
require 'influxdb'
require 'net/https'
# badssl.com has lots of subdomains to test ssl
def ssl_valid?(domain)
uri = URI.parse(domain)
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER