POSIX-Portable Operating System Interface based on uniX Cheatsheet Commands

Categories blog, code

This is a quick reference guide, mostly made of standard Unix commands.Basically because I got fed up of googling them all the time. (POSIX utilities, every Unix / Linux distribution has these POSIXstands for Portable Operating System Interface based on uniX).

For more information about each command, refer to a Unix manual or the man (stands for manual) command. Type man command at a TelNet/SSH Client Software prompt etc… to get info about using the “man” command.

at

: execute commands at a specified time/date.

awk

: a scripting language, especially useful for manipulating text and automation.

bash

: invokes the Bourne Again Shell (standard on most boxes).

batch

: execute commands when load permits.

bc

: interactive C-like calculator (integers only).

cal

: displays a calender, also lets you choose month/year using parameters.

calender

: invoke a reminder service.

cancel

: cancel request to calender.

cat

: concatenate files (displays a file without scrolling ability. Simply dumps it to the standard output. Can be useful when chaining multiple applications to do complicated jobs, so one application can use another’s output as input).

cd

: change the current working directory.

chgrp

: change group ownership of a file.

chmod

: change access patterns (permissions) to files.

chown

: change user ownership of files.

clear

: clear the screen.

cmp

: compare two files.

cp

: copy files.

cpio

: archive and extract files.

cron

: clock deamon (executes “batch” and “at” commands).

crontab

: schedules commands at regular intervals.

crypt

: encrypt , decrypt files using altered DES, standard to Unix passwords (restricted distribution).

csh

: invoke the C shell.

csplit

: split file into several other files.

cu

: call up another unix terminal.

cut

: cut selected fields from each line of file.

date

: displays the time and date (can also change it if you’re root).

dd

: convert and copy a file.

df

: reports space (free, total etc’) on all mounted file systems.

diff

: compare two files.

diff3

: compare 3 or more files.

dircmp

: compare two directories.

du

: report disk usage.

echo

: echo argument to standart output.

ed

: line oriented editor.

egrep

: extended version of grep (searches for extended regular expressions).

fgrep

: same as grep, only it interprets patterns as a list of fixed strings.

expr

: evaluate boolean and arithmetic expression.

false

: return nonzero (false) exit status.

file

: report type of file.

find

: find matching files and run specified programs on them (optional).

finger

: report user information (operates remotely only if a finger server is running on the remote host).

ftp

: (file transfer protocol) a client for FTP servers.

grep

: search files for regular expression matches.

haltsys

: gracefully shutdown sytem (can only be run by root. halt in Linux).

head

: display first 10 lines of a file.

join

: display the combination (lines with command field) of two fields.

kill

: send a signal to terminate a process.

ksh

: invoke the korn shell.

line

: read a specific line out of a file (shell script usage).

ln

: create a link to a file/directory.

logname

: gets your login name.

whoami

: which user you are logged in as at the moment. If you, for example, switch to a different user, logname will show the original username you logged in as, and whoami will show the current user.

lpr

: sends a request to printer.

lprint

: prints on local printer.

lpstat

: reports printer status.

lpq

: same as above.

ls

: lists the contents of directory.

mail

: send and recieve mail.

man

: displays manual pages.

mesg

: grant or deny permissions to recieve messages from other users using the write command.

mkdir

: create a new directory .

mknod

: build a special file.

more

: display file one page at a time.

mount

: mount a storage device.

mv

: move or rename a file.

news

: display news item from NNTP servers.

nice

: change priorities of processes.

nohup

: run a command after logout (ignores hangup signals).

nroff

: format files for printing.

nslookup

: retrieve information from DNS servers.

od

: displays a file in 8-based octals.

passwd

: create or change login password.

paste

: merge lines of files.

pr

: format and print file.

ps

: reports status of active processes.

pstat

: report system status.

pwcheck

: check /etc/passwd (default) file.

pwd

: display current working directory.

rm

: remove (erase) files or directories (unrecoverable).

rmdir

: remove an empty directory.

rsh

: invoke Restricted Bourne Shell.

sed

: the stream editor.

set

: assign value to variable.

setenv

: assign value to enviroment variable.

sh

: invoke Bourne shell.

sleep

: suspend execution of a command for a given period.

sort

: sort and merge files.

spell

: find spelling errors.

split

: split file to smaller files.

stty

: set options for a terminal.

su

: spawns a subshell with a different username, requires other user’s password, unless you’re root.

sum

: compute checksums and number of blocks for files.

tabs

: set tabs on a terminal.

tail

: display last 10 lines of file.

tar

: a simple compression tool that merges multiple files into a single one, originally made to make backing up materials on backup tapes easier.

tee

: create a tee in a pipe.

telnet

: access remote systems using the telnet protocol.

test

: test various expressions and files.

time

: display elapsed time (execution, process, and system times) for a command.

touch

: change time/date stamps of files.

tr

: substitutes sets of characters.

translate

: translates files to different format.

troff

: format files to phototypester.

true

: return zero (true) exit status.

tset

: set terminal mode.

tty

: report a name of a terminal.

umask

: set file-creation mode (permissions) mask.

umount

: unmount a device.

uname

: display the name of the current system.

uniq

: report any duplicate line in a file.

units

: convert numbers from one unit to another.

unzip

: extract files from zip archive.

uptime

: report system activity.

uucp

: copy files between two unix systems (oldie but still beautiful).

uulog

: report uucp status.

uuname

: list uucp sites known to this site.

uudecode

: decode to binary after “uuencode” transmission.

uuencode

: encode binary file for email transmission.

uustat

: report status of uucp or cancel a job.

uupick

: receive public files sent by uuto.

uuto

: send files to another public Unix system.

uux

: execute command to remote Unix system.

vi

: a screen oriented (visual) editor (cool ,but Vim is better).

wall

: sends message to all users (root only).

wait

: await completion of background process.

wc

: count lines, words, bytes etc’ in one or more files.

who

: report active users.

whois

: search for user information.

write

: send a message for another user (see mesg).

zip

: archive file or files in zip format.

 

Examining Virality

Categories blog, code

Virality: The act of content on the web being spread by users sharing it, bringing new users to the original content and therefore adding additional utility.

Virality is the noun for the adverb viral and it has been thrown about these days when it comes to the online world. Virality refers to a sort of new metric system used to determine the “pace” in which information is transmitted over the internets.Borrowed from biology and perhaps misused from the silicon tech and digital marketing community. Ironically the words “infection” or “infected” have been left out of the social media jargon perhaps due to the negative connotation it might have. Coming to think of it users who abstain  from social media platforms are immune  to virality.  So abstainace helps your “immune” system and keeps you in the dark ages. But humour aside an attempt should be made to formulate this phenomenon from a digital point of view.

The success of a viral application relies on number of posible receptors in an online ecosystem and the percentage of users that where indeed infected or converted. The formula below depicts the virality coefficient.

k=icdot conv%

The virality coefficient kappa  , where i equals the number of posible receptors(or invites) and conv% the conversion percentage. The assumption here is that each user sends his invites once is a single batch.

The following formula measures users over time.

U(t)=U(0)cdotfrac{K^{(frac{1}{p}+1)}-1}{K-1}

The time need for a new user to send invites is given by p. The number of epochs the invite process has gone through is represented by frac{t}{p}. The significance of introducing p in the formula is that it shows that it’s easier to increace U(t) by reducing p rather than increasing K.

Verbalizing the aforementioned, lowering the amount fo time necessary for a user to invite other users to a site may be more effective than increasing the numer of invitations users send or the rate at which invited non-users convert. Lowering p increases the power while increasing K only increases the base.

In most cases p is ignored. It is more likely than K to be amenable to change. So perhaps it would be a good idea to invest in minimizing p.

An example of how the formula works is shown on the table below indicating how invitations increase the size of a user base over time. Say K=2 and U(0)=5 and N the number of completed Epochs.

Epochs 0 1 2 3 4 5
New Users added this Epoch 10 20 40 80 160
Total Users 5 15 35 75 155 315

 

It is apparant that the New Users  row doubles every round. The number of New Users for round i  , is given by

U(0)K^i

and the Total Users  is the running sum of New Users; hence the total number of users is given by the summation

U(t)=sumlimits_{i=0}^N U(0)K^i = U(0)cdot sumlimits_{i=0}^N K^i

There is a known identity for sums of powers.

sumlimits_{i=0}^{M-1}r^i=frac{1-r^M}{1-r}

We use it here with N=M-1

U(0)cdotsumlimits_{i=0}^{N}K^i=U(0)cdotfrac{1-K^{(N+1)}}{1-K}

 

Multiply the term on the right by -1/-1

U(0)cdotfrac{1-K^{(N-1)}}{K-1}

Replace N  with frac{t}{p}

U(t)=U(0)cdotfrac{K^{(frac{1}{p}+1)}-1}{K-1}

Bringing us back to the original formula; hence in oder to increace  U(t) maximize  K and minimize  p .

In one sentence: Make the users send out more invites and most importantly faster, you knew it, now you got the proof  :-)

Now that you know the math you understand why online poker became so popular the past 10 years.

LaTeX for wordpress gotta love it.

Special thanx

Categories blog, code

Special thanks to the great programmers of these libraries :

* FatFree PHP Framework: http://fatfree.sourceforge.net/

* Elastic CSS Framework: http://elasticss.com/

* HTML5 Boilerplate.com: http://html5boilerplate.com/

* SimplePie: http://simplepie.org/

* jQuery: http://jquery.com/

* WideImage: http://wideimage.sourceforge.net/

* iScroll: http://cubiq.org/iscroll

* htmLawed: http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/

* PHP Universal Feed Generator: http://www.ajaxray.com/blog/2008/03/08/php-universal-feed-generator-supports-rss-10-rss-20-and-atom/

* twitteroauth: https://github.com/abraham/twitteroauth

* floIcon: http://www.phpclasses.org/package/3906-PHP-Read-and-write-images-from-ICO-files.html

* modernizr: http://www.modernizr.com/

* keyboard shortcuts: http://www.openjs.com/scripts/events/keyboard_shortcuts/

* jsmin: https://github.com/rgrove/jsmin-php/blob/master/jsmin.php

* cssmin: http://code.google.com/p/cssmin/

*zazar: http://www.zazar.net

 

 

 

 

A furry planet with anti-collision drones or the Sfera app for Mac/Win/Lin and Android.

Categories blog, code

A giant furry planet somewhere in universe and a flock of thousands of drones that don’t collide with each other.

The app uses openGL for the graphics, it is java based and uses the processing libs. This is quite fascinating you take  a break and 20′ later you have a fun doodle running on all platforms that support java.

This “art app” as I like to call these things is a combination of the implementation that  Daniel Shiffman did based on Craig Reynold’s Boids program to simulate the flocking behavior of birds and the “esfera” by David Pena. Each Drone steers itself based on rules of avoidance, alignment, and coherence.

What I would like to do is to remove the mouse functionality and instead use the webcam to identify hand gestures and specifically the finger tips. Imagine this on a large HD projector with millions of Drones around the furry planet using your hands, fun right?

The app runs on Mac, Win, Lin and Android. I haven’t tested it yet on Windows but it should run fine. But seriously don’t use windows.

 

Click your mouse to produce more Drones.
Move your mouse up and down to rotate the sphere.

Windoes 32-bit edition - Download here
Windoes 64-bit edition - Download here
Linux 32-bit edition - Download here
Linux 64-bit edition - Download here
MAC OS X   - Download here
ANDROID   - Download here
[cc lang="java"]/**author =Thrasos *URL= http://www.thrasos.net
* Made for the android originally.
*This "art app" as I like to call these things is 
*a combination of the implementation that  Daniel Shiffman
* did based on Craig Reynold's Boids program
* to simulate the flocking behavior of birds 
*and the esfera by David Pena. Each Drone steers itself 
*based on rules of avoidance, alignment, and coherence.
*
*/
package processing.android.test.sfera;

import processing.core.*; 
import processing.xml.*; 

import android.view.MotionEvent; 
import android.view.KeyEvent; 
import android.graphics.Bitmap; 
import java.io.*; 
import java.util.*; 

public class sfera extends PApplet {

int cuantos = 8000;
pelo[] lista ;
float[] z = new float[cuantos]; 
float[] phi = new float[cuantos]; 
float[] largos = new float[cuantos]; 
float radio = 200;
float rx = 0;
float ry =0;

Flock flock;

public void setup() {

  radio = height/3.5f;

  lista = new pelo[cuantos];
  for (int i=0; i<cuantos; i++){
    lista[i] = new pelo();
  }
  noiseDetail(3);
  flock = new Flock();
  // Add an initial set of boids into the system
  for (int i = 0; i < 150; i++) {
    flock.addBoid(new Boid(new PVector(width/2,height/2), 3.0f, 0.05f));
  }
  smooth();

}

public void draw() {
  background(0);
    flock.run();

  translate(width/2,height/2);

  float rxp = ((mouseX-(width/2))*0.005f);
  float ryp = ((mouseY-(height/2))*0.005f);
  rx = (rx*0.9f)+(rxp*0.1f);
  ry = (ry*0.9f)+(ryp*0.1f);
  rotateY(rx);
  rotateX(ry);
  fill(0);
  noStroke();
  sphere(radio);

  for (int i=0;i<cuantos;i++){
    lista[i].dibujar();

  }
}

// Add a new boid into the System
public void mousePressed() {
  flock.addBoid(new Boid(new PVector(mouseX,mouseY),2.0f,0.05f));
}
class pelo
{
  float z = random(-radio,radio);
  float phi = random(TWO_PI);
  float largo = random(1.15f,1.2f);
  float theta = asin(z/radio);

    public void dibujar(){

    float off = (noise(millis() * 0.0005f,sin(phi))-0.5f) * 0.3f;
    float offb = (noise(millis() * 0.0007f,sin(z) * 0.01f)-0.5f) * 0.3f;

    float thetaff = theta+off;
    float phff = phi+offb;
    float x = radio * cos(theta) * cos(phi);
    float y = radio * cos(theta) * sin(phi);
    float z = radio * sin(theta);
    float msx= screenX(x,y,z);
    float msy= screenY(x,y,z);

    float xo = radio * cos(thetaff) * cos(phff);
    float yo = radio * cos(thetaff) * sin(phff);
    float zo = radio * sin(thetaff);

    float xb = xo * largo;
    float yb = yo * largo;
    float zb = zo * largo;

    beginShape(LINES);
    stroke(0);
    vertex(x,y,z);
    stroke(200,150);
    vertex(xb,yb,zb);
    endShape();
  }
}
// The Boid class

class Boid {

  PVector loc;
  PVector vel;
  PVector acc;
  float r;
  float maxforce;    // Maximum steering force
  float maxspeed;    // Maximum speed

    Boid(PVector l, float ms, float mf) {
    acc = new PVector(0,0);
    vel = new PVector(random(-1,1),random(-1,1));
    loc = l.get();
    r = 2.0f;
    maxspeed = ms;
    maxforce = mf;
  }

  public void run(ArrayList boids) {
    flock(boids);
    update();
    borders();
    render();
  }

  // We accumulate a new acceleration each time based on three rules
  public void flock(ArrayList boids) {
    PVector sep = separate(boids);   // Separation
    PVector ali = align(boids);      // Alignment
    PVector coh = cohesion(boids);   // Cohesion
    // Arbitrarily weight these forces
    sep.mult(1.5f);
    ali.mult(1.0f);
    coh.mult(1.0f);
    // Add the force vectors to acceleration
    acc.add(sep);
    acc.add(ali);
    acc.add(coh);
  }

  // Method to update location
  public void update() {
    // Update velocity
    vel.add(acc);
    // Limit speed
    vel.limit(maxspeed);
    loc.add(vel);
    // Reset accelertion to 0 each cycle
    acc.mult(0);
  }

  public void seek(PVector target) {
    acc.add(steer(target,false));
  }

  public void arrive(PVector target) {
    acc.add(steer(target,true));
  }

  // A method that calculates a steering vector towards a target
  // Takes a second argument, if true, it slows down as it approaches the target
  public PVector steer(PVector target, boolean slowdown) {
    PVector steer;  // The steering vector
    PVector desired = target.sub(target,loc);  // A vector pointing from the location to the target
    float d = desired.mag(); // Distance from the target is the magnitude of the vector
    // If the distance is greater than 0, calc steering (otherwise return zero vector)
    if (d > 0) {
      // Normalize desired
      desired.normalize();
      // Two options for desired vector magnitude (1 -- based on distance, 2 -- maxspeed)
      if ((slowdown) && (d < 100.0f)) desired.mult(maxspeed*(d/100.0f)); // This damping is somewhat arbitrary
      else desired.mult(maxspeed);
      // Steering = Desired minus Velocity
      steer = target.sub(desired,vel);
      steer.limit(maxforce);  // Limit to maximum steering force
    } 
    else {
      steer = new PVector(0,0);
    }
    return steer;
  }

  public void render() {
    // Draw a triangle rotated in the direction of velocity
    float theta = vel.heading2D() + PI/2;
    fill(200,100);
    stroke(255);
    pushMatrix();
    translate(loc.x,loc.y);
    rotate(theta);
    beginShape(TRIANGLES);
    vertex(0, -r*2);
    vertex(-r, r*2);
    vertex(r, r*2);
    endShape();
    popMatrix();
  }

  // Wraparound
  public void borders() {
    if (loc.x < -r) loc.x = width+r;
    if (loc.y < -r) loc.y = height+r;
    if (loc.x > width+r) loc.x = -r;
    if (loc.y > height+r) loc.y = -r;
  }

  // Separation
  // Method checks for nearby boids and steers away
  public PVector separate (ArrayList boids) {
    float desiredseparation = 20.0f;
    PVector steer = new PVector(0,0,0);
    int count = 0;
    // For every boid in the system, check if it's too close
    for (int i = 0 ; i < boids.size(); i++) {
      Boid other = (Boid) boids.get(i);
      float d = PVector.dist(loc,other.loc);
      // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
      if ((d > 0) && (d < desiredseparation)) {
        // Calculate vector pointing away from neighbor
        PVector diff = PVector.sub(loc,other.loc);
        diff.normalize();
        diff.div(d);        // Weight by distance
        steer.add(diff);
        count++;            // Keep track of how many
      }
    }
    // Average -- divide by how many
    if (count > 0) {
      steer.div((float)count);
    }

    // As long as the vector is greater than 0
    if (steer.mag() > 0) {
      // Implement Reynolds: Steering = Desired - Velocity
      steer.normalize();
      steer.mult(maxspeed);
      steer.sub(vel);
      steer.limit(maxforce);
    }
    return steer;
  }

  // Alignment
  // For every nearby boid in the system, calculate the average velocity
  public PVector align (ArrayList boids) {
    float neighbordist = 25.0f;
    PVector steer = new PVector(0,0,0);
    int count = 0;
    for (int i = 0 ; i < boids.size(); i++) {
      Boid other = (Boid) boids.get(i);
      float d = PVector.dist(loc,other.loc);
      if ((d > 0) && (d < neighbordist)) {
        steer.add(other.vel);
        count++;
      }
    }
    if (count > 0) {
      steer.div((float)count);
    }

    // As long as the vector is greater than 0
    if (steer.mag() > 0) {
      // Implement Reynolds: Steering = Desired - Velocity
      steer.normalize();
      steer.mult(maxspeed);
      steer.sub(vel);
      steer.limit(maxforce);
    }
    return steer;
  }

  // Cohesion
  // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
  public PVector cohesion (ArrayList boids) {
    float neighbordist = 25.0f;
    PVector sum = new PVector(0,0);   // Start with empty vector to accumulate all locations
    int count = 0;
    for (int i = 0 ; i < boids.size(); i++) {
      Boid other = (Boid) boids.get(i);
      float d = loc.dist(other.loc);
      if ((d > 0) && (d < neighbordist)) {
        sum.add(other.loc); // Add location
        count++;
      }
    }
    if (count > 0) {
      sum.div((float)count);
      return steer(sum,false);  // Steer towards the location
    }
    return sum;
  }
}

// The Flock (a list of Boid objects)

class Flock {
  ArrayList boids; // An arraylist for all the boids

  Flock() {
    boids = new ArrayList(); // Initialize the arraylist
  }

  public void run() {
    for (int i = 0; i < boids.size(); i++) {
      Boid b = (Boid) boids.get(i);  
      b.run(boids);  // Passing the entire list of boids to each boid individually
    }
  }

  public void addBoid(Boid b) {
    boids.add(b);
  }

}

  public int sketchWidth() { return 1024; }
  public int sketchHeight() { return 768; }
  public String sketchRenderer() { return OPENGL; }
}[/cc]

 

Mac show hidden files

Categories blog, code

So you have a mac and you want to view hidden files on Finder.

Simple.

open the terminal and type this command

defaults write com.apple.Finder AppleShowAllFiles YES

If you decide that this is tiresome just change the value to NO

 

WordPress: Adding stuff to your RSS feed

Categories blog, code

So you want to add stuff to your RSS feed? And by stuff I mean ads, links, text, dead cats etc.

Well it’s another add_filter() function based solution. Quick and easy by editing functions.php.

There is another more dirty way to do this but I wont get in to it now.

[cc lang=”php”]


Have you taken your picture?


‘;

return $content; }

add_filter(‘the_excerpt_rss’, ‘addStuff’);

add_filter(‘the_content_rss’, ‘addStuff’);

?>

[/cc]

Posting stuff that helped me and so I don’t forget :-)

glfx.js

Categories blog, code

glfx.js provides realtime image effects using WebGL

pure awesomeness check out their website, demo and source code

The moment our browsers acquire camera functionality, I can see flash going bye bye and app’s like photobooth for the mac having strong competition.

 

 

Augmented Reality

Categories blog, code

This is an old but fun application of augmented reality. Instead of a printed marker it identifies the human face as a marker and applies a 2D object. It was all written in flex so be patient, if you happen to want the source code let me know and I’ll mail it to you. I am just too lazy to post it online and start doing software support via the comments (for something I did for fun!)

funface