Skip to content

Instantly share code, notes, and snippets.

Node* Reverse(Node *head)
{
Node* trail=0;
while (head){
Node* next= head->next;
head->next = trail;
trail=head;
head=next;
}
return trail;
@ademidun
ademidun / inorder.cpp
Last active February 18, 2016 23:17
Week2
void Inorder(node *root) {
if (root) {
Inorder(root->left);
cout << to_string(root->data) + " ";
Inorder(root->right);
}
}
@ademidun
ademidun / flipbits.cpp
Created February 19, 2016 20:33
Week3
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int cases, x;
//first, we find how many numbers we have, we use scanf on the input from STDIN, to return the number
//of cases we have to cases variable
scanf("%u", &cases);
@ademidun
ademidun / lonsest-substring.java
Last active September 20, 2016 03:53
Week1-2016
public int lengthOfLongestSubstring(String s) {
if(s==null || s.length()==0){
return 0;
}
HashSet<Character> set = new HashSet<Character>();
int max=0;
int i=0;
@ademidun
ademidun / MyStack.java
Last active September 26, 2016 04:04
Week2-2016
public class MyStack<T extends Comparable<T>>{
private static class StackNode<T extends Comparable<T>> {
private Comparable<T> data;
private StackNode<T> next;
public StackNode(Comparable<T> item){
this.data =item;
}
@ademidun
ademidun / course-sched.java
Last active October 5, 2016 02:48
Week3-2016
public boolean canFinish(int numCourses, int[][] prerequisites) {
if(prerequisites == null){
throw new IllegalArgumentException("Invalid Prerequisites");
}
int p_len = prerequisites.length;
if(p_len == 0||numCourses == 0){
return true;
}
@ademidun
ademidun / lavar-ball-scholarship-cache-sort.py
Last active March 1, 2018 01:04
Help Lavar pay for school!
# Lavar Ball is looking for scholarships to help pay for school.
# He has 2 lists, A and B.
# A is a cache of Lavar's scholarships as an array of primary keys.
# B is an array of scholarship objects matching Lavar's profile.
# Lavar needs to sort the objects in B based on the PKs of A, to get a new B (B_2).
# Lavar needs it done in less than O(n^2) time so he doesn't get bored and starts browsing Reddit.
# e.g.
A = [3,139,47] # arbitrary order
B = [{pk:139,name:'Scholarship X'},{pk:47,name:'Scholarship Y'},{pk:3,name:'Scholarship Z'}]
@ademidun
ademidun / python-dynamo-utils.py
Last active November 7, 2019 16:33
Some helpful python code snippets when working with dynamodb.
from botocore.exceptions import ClientError
def dict_to_dynamo(data):
# if you try to save an empty string to dynamo you will get the following error:
# 'An error occurred (ValidationException) when calling the BatchWriteItem operation: One or more parameter values were invalid: An AttributeValue may not contain an empty string'
# This function recursively converts all empty string to valid None/Null type values that dynamo accepts
# https://gist.github.com/JamieCressey/a3a75a397db092d7a70bbe876a6fb817
@ademidun
ademidun / pwa-tutorial-0-0-main.ts
Last active September 28, 2018 23:33
Service worker configuration for Part 1 if Angular pwa tutorial.
// src/main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
@ademidun
ademidun / bash-git-commands.sh
Last active August 10, 2019 18:39
Useful Bash and Git Commands
# Rename File Extensions
# https://www.maketecheasier.com/rename-files-in-linux/
brew install rename;
rename 's/.m4a/.mp3/' * # rename all .m4a files to .mp3 (don't forget to include the asteriks '*')
# delete all files with a certain extension
# https://askubuntu.com/questions/377438/how-can-i-recursively-delete-all-files-of-a-specific-extension-in-the-current-di
find . -name "*.bak" -type f #first check the files that will be deleted
find . -name "*.bak" -type f -delete # then you can delete them