Skip to content

Instantly share code, notes, and snippets.

# Store the full directory name of the executing script, no matter where it is
# being called from. This will work as long as the last component of the path
# used to find the script is not a symlink; directory links are OK.
# SEE: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo ${DIR}
#!/usr/bin/env bash
# Store the full directory name of the executing script, no matter where it is
# being called from. This will work as long as the last component of the path
# used to find the script is not a symlink; directory links are OK.
# SEE: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo $DIR
@raskasa
raskasa / notes-headfirst-python.md
Last active March 20, 2023 14:24
Head First Python notes.

TABLE OF CONTENTS

  1. Meet Python - Python Basics
  2. Sharing Your Code
  3. Files and Exceptions
  4. Persistence: Saving Data to Files
  5. Comprehending Data
  6. Custom Data Objects
  7. Web Development
  8. Mobile App Development
@raskasa
raskasa / ServletThreadSafety.java
Created December 18, 2012 20:27
An example of how to deal with concurrency and thread-safety when accessing context and session attributes. Context attributes can be accessed by an part of the web app including Servlets, JSPs, ContextListeners, and ServletContextAttributeListeners. Session attributes are only for one client, but opening up another new browser windows on the sa…
public class ServletThreadSafety extends HttpServlet {
/*
* Since we have the context lock, we're assuming that once we get inside the synzchonized block,
* the context attributes are safe from other threads until we exit the block... soft of. Safe
* means "safe from any other code that ALSO synchonizes on the ServletContext".
*
* But this is the best you've got for making the context attributes as thread-safe as you can.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@raskasa
raskasa / Singleton.java
Last active October 14, 2015 01:37
A basic implementation of the Singleton design pattern for reference.
/**
* A basic implementation of the Singleton design pattern for reference.
*/
public class Singleton {
/**
* Stores the only instance of this object. The 'volatile' keyword ensures
* that multiple threads handle the uniqueInstance variable correctly when it
* is being initialized to the Singleton instance.
*/
private volatile static Singleton uniqueInstance;
@raskasa
raskasa / tokenizer.c
Created December 14, 2012 04:37
An example of the parsing component of a compiler for reference.
#include <stdio.h>
#include <stdlib.h>
/* constants */
#define NUM 257
/* global */
int currentToken;
int currentAttribute;
@raskasa
raskasa / utility-functions.prolog
Created December 14, 2012 03:23
All useful Prolog functions learned over the course of the semester in CS 341 - Programming Languages.
% Contained within are all the useful Prolog functions learned in CS 341 this past semester (Fall 2012).
% NOTE: Any functions used that are not defined in this file are built-in functions.
% length(+As,-N)
% returns in N the length of the list As
length([],0).
length([A|As],N) :- length(As,M), N is M+1.
% append(+As,+Bs,-Cs)
% returns in Cs the append of lists As and Bs
@raskasa
raskasa / utility-functions.scm
Created December 14, 2012 00:49
All useful functions learned over the course of the semester in CS 341 - Programming Languages.
; Contained within are all the useful functions learned in CS 341 this past semester (Fall 2012).
; NOTE: Any functions used that are not defined in this file are built-in functions in either
; MIT-Scheme or Racket.
; length
; returns the length of the input list
(define length
(lambda (ls)
(if (null? ls)
0