Skip to content

Instantly share code, notes, and snippets.

Unix Scripting Lab

Part 1: Getting Parameters

  1. Take a directory name and a file name. Create the directory and then create the file inside.
  2. Take a user name and print all processes from that user
  3. Write a shell script that reads a file name from the user, prints its contents and the number of lines in the file.

Part 2: Conditionals

#!/usr/bin/env csh -f
# Also supported: <, >, <=, >=
if ( $# > 2 ) echo "So many arguments"
# Also supported: +, -, *, /
if ( $# % 2 == 0 ) echo "Can also use math"
@ynonp
ynonp / main.clj
Created June 20, 2015 08:08
clojure demo
(ns clojure-noob.core
(:gen-class))
(require 'digest)
(defn exp [x n]
(reduce * (repeat n x)))
(defn char_at [ab i d]
(ab (rem
@ynonp
ynonp / main.cpp
Created June 20, 2015 15:42
Range iterator
#include <QCoreApplication>
#include "range.h"
#include <QDebug>
#include <QtCore>
#include <QtConcurrent>
static const char ab[] = "0123456789abcdefghijklmnopqrstuvwxyz";
@ynonp
ynonp / sub.pl
Created July 5, 2015 06:53
subroutine demo
use strict;
use warnings;
use v5.08;
sub say {
print @_, "\n";
}
say("Hello");
@ynonp
ynonp / dabblet.css
Created December 17, 2011 17:13
Arcs example
/**
* Arcs example
*/
html {
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
}
svg {
@ynonp
ynonp / dabblet.css
Created December 17, 2011 17:39
Text in path example
/**
* Text in path example
*/
html {
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
}
svg {
#include <QtCore/QtCore>
#include <QtCore/QCoreApplication>
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
#include <QtCore/QLatin1Char>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
static const char mydata[] = {
@ynonp
ynonp / get_numbers.php
Created January 23, 2012 18:25
PHP JSON Example
<?php
header('Content-Type: application/json' );
$a = array(10, 20, 30);
print json_encode($a);
@ynonp
ynonp / riddle.js
Created January 25, 2012 06:05
js intro
function Counter(max) {
var val = 0;
return function() { return (val < max) ? val++ : false; }
;
}
var c = Counter(10);
while (c()) {
console.log(c());
}