Skip to content

Instantly share code, notes, and snippets.

View swarajd's full-sized avatar

Swaraj Dhumne swarajd

View GitHub Profile
swarajd@swarajd-travel:~/prog/systems/3ep/29_locked_data_structures$ ./concurrent_counter
it took: 0.261783 seconds to run 1 threads
it took: 1.349552 seconds to run 2 threads
it took: 2.434678 seconds to run 3 threads
it took: 4.624687 seconds to run 4 threads
it took: 6.601393 seconds to run 5 threads
swarajd@swarajd-travel:~/prog/systems/3ep/29_locked_data_structures$ ./better_concurrent_counter
it took: 0.300315 seconds to run 1 threads
it took: 1.788734 seconds to run 2 threads
it took: 3.112465 seconds to run 3 threads
#include <stdio.h>
#include "mythreads.h"
pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
void* worker(void* arg) {
if ((long long) arg == 0) {
Pthread_mutex_lock(&m1);
#define _GNU_SOURCE
#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
@swarajd
swarajd / p8.c
Last active October 15, 2019 04:14
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define READ_END 0
#define WRITE_END 1
class Solution {
public int reverse(int x) {
int reversed = 0;
while (x != 0) {
int rem = x % 10;
reversed += rem;
int prevReverse = reversed;
boolean xIsBig = x >= 10 || x <= -10;
if (xIsBig) {
reversed *= 10;
class Solution {
public int lengthOfLongestSubstring(String s) {
HashSet<Character> seenSoFar = new HashSet<Character>();
int curLength = 0;
int longestSoFar = 0;
int start = 0;
int end = 0;
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char** argv) {
// print the args
for (int i = 0; i < argc; ++i) {
printf("%s\n", argv[i]);
const gcd = (a, b) => {
if (!b) {
return a;
}
return gcd(b, a % b);
}
const hill = (text, matrix) => {
if (text.length % matrix.length != 0) {
throw "please provide a plaintext that can be cleanly divided into " + matrix.length + " parts"
}
const chunks = [];
for (let i = 0; i < text.length; i += matrix.length) {
chunks.push(text.substring(i, i + matrix.length));
}
const getRandomInt = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const dValues = (() => {
const result = new Array(27);
result[0] = 1;
result[1] = 0;
for (let i = 2; i < letters.length; i++) {
result[i] = (i - 1) * (result[i - 1] + result[i - 2]);