Skip to content

Instantly share code, notes, and snippets.

@jylock
jylock / c arrow operator
Last active September 27, 2015 17:09
Arrow Operator Syntax, usage, clarification, etc
struct foo
{
int x;
float y;
};
struct foo var;
struct foo* pvar;
var.x = 5;
@jylock
jylock / Shell customization
Last active January 16, 2016 05:21
Terminal prompt customization, Alias, etc
Login shell: .bash_profile
Interactive shell: .bashrc
To color code your prompt on a Mac, use the following template:
\[\033[COLOR_CODE_HERE\]PROMPT_ESCAPE_OR_TEXT_HERE\[\033[0m\]
----------------------------------------------------------------------------
Most Linux distributions use a little different format:
\e[COLOR_CODE PROMPT_ESCAPE\e[0m
----------------------------------------------------------------------------
redirect.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/**
* Executes the command "grep Villanova < scores > out".
@jylock
jylock / Hadoop Commands
Last active October 13, 2015 18:35
Compile, ToolRunner, Configuration, etc
#TF-IDF
TF-IDF = tf * idf = tf * log(N/n)
tf: number of times a term appears in a document
N: total number of documents
n: number of documents that contain a term
TF-IDF stands for "Term Frequency, Inverse Document Frequency".
It is a way to score the importance of words (or "terms") in a
document based on how frequently they appear across multiple documents.
All POSIX semaphore functions and types are prototyped or defined in semaphore.h. To define a semaphore object, use
sem_t sem_name;
To initialize a semaphore, use sem_init():
int sem_init(sem_t *sem, int pshared, unsigned int value);
sem points to a semaphore object to initialize
pshared is a flag indicating whether or not the semaphore should be shared with fork()ed processes. LinuxThreads does not currently support shared semaphores
value is an initial value to set the semaphore to
Example of use:
sem_init(&sem_name, 0, 10);
monitor DP {
status state[5];
condition self[5];
// Pickup chopsticks
Pickup(int i){
state[i] = hungary; // indicate that I'm hungary
test(i); //set state to eating in test() only if my
//left and right neighbors are not eating
if(state[i] != eating)
//The name of our remote is origin and the default local branch name is master.
//The -u tells Git to remember the parameters, so that next time we can simply
//run git push and Git will know what to do. Go ahead and push it!
git push -u origin master
//diff of most recent commit, which we can refer to using the HEAD pointer
git diff HEAD
git diff --staged
//unstage files by using the git reset command
#include <stdio.h>
#include <stdlib.h>
char* ReadFile(char *filename)
{
char *buffer = NULL;
int string_size,read_size;
FILE *handler = fopen(filename,"r");
if (handler)
# Arithmatic Expansion
# Arithmetic expansion with backticks (often used in conjunction with expr)
# Arithmetic expansion with double parentheses, and using let
z=$(($z+3))
z=$((z+3)) # Also correct.
# Within double parentheses,
#+ parameter dereferencing
#+ is optional.
//comment and uncomment multiple lines
//commenting lines from 66 to 70 (inclusive).
:66,70s/^/#
:66,70s/^#/