Skip to content

Instantly share code, notes, and snippets.

View ashwanthkumar's full-sized avatar

Ashwanth Kumar ashwanthkumar

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ashwanthkumar on github.
  • I am ashwanthkumar (https://keybase.io/ashwanthkumar) on keybase.
  • I have a public key whose fingerprint is 2668 B364 EF04 21C5 5CB0 633A 3C86 C0FB 01EF BF7B

To claim this, I am signing this object:

@ashwanthkumar
ashwanthkumar / GroupBy.go
Created February 28, 2022 02:13
GroupBy implementation in Golang for string slices
func GroupBy(slice []string, groupFn func(string) string) map[string][]string {
groups := make(map[string][]string)
for _, elem := range slice {
elementKey := groupFn(elem)
existing, present := groups[elementKey]
if !present {
existing = []string{}
}
existing = append(existing, elem)
groups[elementKey] = existing
@ashwanthkumar
ashwanthkumar / GithubContributors.scala
Last active January 14, 2019 07:27
Get the list of all contributors for all the repos within an organization.
import java.io.{File, PrintWriter}
import org.kohsuke.github.{GHRepository, GitHub}
import scala.collection.JavaConversions._
// Needs the following in build.sbt
// resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
// libraryDependencies += "org.kohsuke" % "github-api" % "1.95"
#!/bin/bash
## This script get's the current working directory of an gocd-agent and
## deletes all the directories under pipelines/ except the ${GO_PIPELINE_NAME}.
## Since a stage is running on an agent, we've exclusive access over that agent
## it's safe to perform that delete.
CWD="$( cd "$( dirname "$0" )" && pwd )"
AGENT_PIPELINES_DIR=${CWD}/../
@ashwanthkumar
ashwanthkumar / gen-thrift.sh
Created October 24, 2018 04:07
Generate Java Thrift classes for thrift 0.8
#!/bin/bash
docker run -v "$PWD:/data" ashwanthkumar/docker-thrift:0.8 thrift --gen java:private-members --out /data/src/test/java/ /data/src/test/thrift/*.thrift
@ashwanthkumar
ashwanthkumar / sumOfN.c
Created June 10, 2018 14:07
Sum of N numbers without mutating any variables.
#include<stdio.h>
int sum(int n) {
if (n == 1) return 1;
else return n + sum(n - 1);
}
int main() {
int input;
scanf("%d", &input);

Python Lists

The following questions were adapted from Prolog Lists, and mostly re-written to remove any prolog references or examples.

  1. Find the last element of a list
  2. Find the last but one element of a list.
  3. Find the K'th element of a list.
  4. Find the number of elements of a list.
  5. Reverse a list.
  6. Find out whether a list is a palindrome.
    A palindrome can be read forward or backward; e.g. [x,a,m,a,x].
  7. Flatten a nested list structure.Transform a list, possibly holding lists as elements into a 'flat' list by replacing each list with its elements (recursively).
/**
* Type declaration for npm package https://www.npmjs.com/package/sse-nodejs
*/
declare module "sse-nodejs" {
import { OutgoingMessage } from "http";
function SSE(response: OutgoingMessage, options?: Object): SSE.ServerSendEvent;
namespace SSE {
/**
* ServerSendEvent wraps a response object from http and exposes
Subject: *.cloudfront.net
Issuer: Symantec Class 3 Secure Server CA - G4
Expires on: 18 Dec 2017
Current date: 17 Mar 2017
PEM encoded chain: -----BEGIN CERTIFICATE-----
MIIF8jCCBNqgAwIBAgIQNprHPWcGOqJ1gw38ZoQcHjANBgkqhkiG9w0BAQsFADB+
MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd
BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxLzAtBgNVBAMTJlN5bWFudGVj
IENsYXNzIDMgU2VjdXJlIFNlcnZlciBDQSAtIEc0MB4XDTE2MTAyNjAwMDAwMFoX
DTE3MTIxNzIzNTk1OVowajELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0
package chaser.hadoop;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.UUID;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;