Skip to content

Instantly share code, notes, and snippets.

View khayyamsaleem's full-sized avatar
🏠
Working from home

khayyam khayyamsaleem

🏠
Working from home
View GitHub Profile
#include "my.h"
/**
* Prints a number using the length of the string as the base and the contents
* as the alphabet. For example, if you called my_num_base(9, "RTFM"), then
* R = 0, T = 1, F = 2, M = 3. 9 in base 4 is 21 and so the result is printed
* out as "FT".
*
* If char* is NULL or empty, print an error message and return.
* If given unary, repeat alphabet letter the specified number of times.
import java.util.Scanner;
public class Coordinates {
public static void main(String[] args){
Scanner console = new Scanner(System.in);
System.out.println("x coordinate? ");
double x = console.nextDouble();
int neg;
if (x < 0.0) {
System.out.print("y coordinate? ");
double y = console.nextDouble();
class Game {
constructor(numberOfRows, numberOfColumns, numberOfBombs) {
this._board = new Board(numberOfRows, numberOfColumns, numberOfBombs);
}
playMove(rowIndex, columnIndex) {
this._board.flipTile(rowIndex, columnIndex);
if (this._board.playerBoard[rowIndex][columnIndex] === 'B') {
console.log('Game Over! Final Board:');
this._board.print();
import java.util.Arrays;
import java.util.Iterator;
/**
*
* @author khayyamsaleem 2017S CS284 -- Data Structures.
* A SortedList class that
* demonstrates the usage of a linked list
* @param <E>
* a comparable element of our list
const generatePlayerBoard = (numberOfRows, numberOfColumns) => {
let board = [];
for (let i = 0; i < numberOfRows; i++){
let row = [];
for (let j = 0; j < numberOfColumns; j++){
row.push(' ');
} board.push(row);
} return board };
// console.log(generatePlayerBoard(3,2));
/**
* A Queue implemented with two stacks implemented with linked lists implemented with nodes.
* @author khayyamsaleem 2017S CS284.
*
*/
public class Queue<E> {
private Stack<E> left;
private Stack<E> right;
private int size;
//monitors
//EB6, Q4
//E = W < S
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Condition;
public class TWS implements Runnable{
private int state = 1;
private Condition first = new ReentrantLock().newCondition();
private Condition second = new ReentrantLock().newCondition();
private Condition third = new ReentrantLock().newCondition();
public class LL<E>{
private static class Node<E>{
E data;
Node<E> next;
public Node(E data, Node<E> next){
this.data = data;
this.next = next;
}
public Node(E data){
this.data = data;
#include "my.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char *argv[]){
if(argc <= 1){
my_str("Usage: ./pipes <message>\n");
return 1;
}
CFLAGS = -I../../include -Wall -Werror --pedantic -std=c99
SRC = my_alpha.c my_char.c my_str.c my_strlen.c my_revstr.c my_int.c my_num_base.c my_strindex.c my_strrindex.c my_strfind.c my_strrfind.c my_strcmp.c my_strncmp.c my_strcpy.c my_strncpy.c my_strcat.c my_strdup.c my_strconcat.c my_strnconcat.c my_atoi.c
OBJS = $(SRC:.c=.o)
LIB = libmy.a
CC = gcc
all: $(OBJS)
ar -rc $(LIB) $(OBJS)
ranlib $(LIB)
mv $(LIB) ../../lib