Skip to content

Instantly share code, notes, and snippets.

View devansh42's full-sized avatar

Devansh Gupta devansh42

View GitHub Profile
@devansh42
devansh42 / cool_dynamic_string.c
Created October 21, 2023 06:13
Cool Dynamic String Implementation in C inspired by Redis SDS
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
// HEADER_SIZE would help us to move pointer to and fro
// usually, sizeof(unsigned int) is 4 bytes
// so this will be 8 bytes
#define HEADER_SIZE 2 * sizeof(unsigned int)
@devansh42
devansh42 / boring_dynamic_string.c
Created October 21, 2023 06:11
Boring Dynamic String Implementation in C
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
// HEADER_SIZE would help us to move pointer to and fro
// usually, sizeof(unsigned int) is 4 bytes
// so this will be 8 bytes
#define HEADER_SIZE 2 * sizeof(unsigned int)
bubbleSort::(Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort ([a]) = [a] -- One element array
bubbleSort ([a,b]) = if a<b then [a,b] else [b,a]
bubbleSort (a:b:bs) = let res = if a < b then [a] ++ bubbleSort([b]++bs) else [b] ++ bubbleSort([a]++bs) in bubbleSort (init res) ++ [last res]
def bubble_sort(ar):
if len(ar)<=1:
return ar
if len(ar)==2:
return ar if ar[0]<ar[1] else [ar[1],ar[0]]
a,b,bs=ar[0],ar[1],ar[2:]
res = []
if a<b:
@devansh42
devansh42 / imperative_bubble_sort.py
Last active December 29, 2020 15:04
Imperative algorithm of bubble sort in python
def imperative_bubble_sort(ar):
for i in range(len(ar)):
for j in range(len(ar)-1-i):
if ar[j]>ar[j+1]:
ar[j],ar[j+1] = ar[j+1],ar[j]
return ar
ssh -l username -n -N -i identity_file -R 6379:0.0.0.0:6379 mydroplet.domain.com
ssh -l username -n -N -i identity_file -R 6379:127.0.0.1:6379 mydroplet.domain.com
#ifndef 1_H
#define 1_H
void foo(){
//Some code
}
#endif
# 1 "3.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "3.c"
# 1 "2.h" 1
# 1 "1.h" 1
#include"2.h"
#include"1.h"
void main(){
foo();
soo();
}