Skip to content

Instantly share code, notes, and snippets.

View armaandhir's full-sized avatar
😎
Thinking

Armaan Dhir armaandhir

😎
Thinking
View GitHub Profile
public void testDates() throws ParseException {
// Desired Format in all scenarios
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//Sample string we recieve
String runTime = "2020-10-26T00:07:35.965030-04:00[America/Toronto]";
//converting to LocalDateTime for usage
LocalDateTime localDateTimeOut = ZonedDateTime.parse(runTime).toLocalDateTime();
System.out.println("LocalDateTime to String without format: " + localDateTimeOut.toString());
@armaandhir
armaandhir / slack-message-java.java
Created November 21, 2017 02:10
Send a slack message to a channel. This provides a demo code to use the slack api and use json to design slack message.
package com.armaandhir.slack_integration.util;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Send slack messages using java.
@armaandhir
armaandhir / NumberWords.java
Created May 23, 2017 18:06
Prints the textual representation of integer in English.
/**
* The program takes 2 parameters for the main method:
* - first parameter is the number to be converted
* - second parameter is either 1 or 2. 1 represents question 1 and 2 represents question 2
*
* @author armaan
*
*/
public class NumberWords {
@armaandhir
armaandhir / c_bitwise.c
Last active May 5, 2016 15:31
Simple implementation of & bitwise operator
/*
* Simple implementation of & bitwise operator
*/
#include <stdio.h>
#define TUNA_A 1
#define TUNA_B 2
#define TUNA_C 4
#define TUNA_D 8
@armaandhir
armaandhir / crc_encode.py
Created March 2, 2016 19:26
simple crc check using python
def crc_encode(self, message, length):
new_message = message
crc = 0
hex_crc = 0x91
#lopp through each letter in string and store the xor value
for x in range(length):
crc ^= ord(message[x])
#loop through each bit in char and check if it
@armaandhir
armaandhir / readExcel.py
Last active August 6, 2024 04:23
Reading data from excel using openpyxl
#
# I hate the documentation of openpyxl and it took me a while to undertand their stuff. So I decided to write down this code.
# Has some wrapper functions that reads all rows from the excel sheet and also a function to read a particular row.
# Add some code to the functions if you wish to do something on fly like adding values to list and sorting them later.
#
# Date: 28/09/2015
from openpyxl import load_workbook
# Reads all rows
@armaandhir
armaandhir / replaceFunction.c
Last active February 18, 2016 19:29
C function to replace a sub string with something in a string.
/*
* C function to replace a sub string with something in a string. Would suggest to use glib to avoid memory overwritting or use mallocs.
* You can use malloc() to assign memory to return string and get rid of the last argument but make sure to free it later.
* This function replaces multiple instances of the found substring. To replace single instance, see the comment in the function.
* If you want to dig more into it, check this out: http://creativeandcritical.net/str-replace-c
*
* Date: 23/09/2015
*/
#include <stdio.h>