
wikimedia
I guess I'm probably the last person in the world to learn about this guy:
one
two
three
four
five
my favorite:
six
Incredible feeling...
one more
and the last
but one.
(Can't help myself)
sudo
, which stands for superuser, do once. If not, you can see wikipedia. Normally you will use this to write (install) or even delete files in /usr/bin
and the like. > mv /usr/bin/znew ~/Desktop/znew |
man
page on this one. There is always something interesting in the manual.man
can be broken up into chunks or streamed using the down arrow, but maybe you want to study it or keep it as a reference. man
in a special way before directing it to a file, for example:man ls | col -bx > results.txt |
col
leads to selective stuttering:LS(1) BSD General Commands Manual LS(1) |
head
and tail
are useful for looking at the first few lines or last few lines of a file. less
is like what you get when you just do man some_command
---it gives chunks or streams.man cat
to see what else that can do.split
but I couldn't figure out how to make it take my favorite separator ('\n\n').diff
does what you might expect. The use case might be that you have some good edits but also some bad edits to a file, so you want to revert to the old one, and then try the edits one by one. > diff old.txt new.txt > results.txt |
results.txt
onto TextMate for a little color (graphic).ps -u username |
> ps -p 48068 -O %mem |
man
page on ps
is extensive.find
is tricky. I need a lot more practice to understand it. Here's a simple one, and then a fun one though:> find . -name "old.txt" -print |
wc
(word count), discovering that there are 118,791 lines in the output---that's the number of files! This link seems to have good info on find
.> python -c 'print 3.0/17' |
> hexdump -C post.txt |
alias |
ssh
. But that really does deserve a post of its own.
.bash_profile
, containing this line:> cat ~/.bash_profile |
mv ~/.bash_profile ~/Desktop/x.txt |
c-98-236-78-154:Desktop telliott$ |
#PS1="> "; export PS1 |
.bash_profile
as an option.pico
(a command line editor):> pico ~/.bash_profile |
pico
..bash_profile
is modification to the $PATH variable. Let's look at that from the command line:> echo $PATH |
ls
, for example, these directories are searched in turn until the program is discovered finally. It is in:> whereis ls |
> PATH=~/Desktop:$PATH; export PATH |
history
:> history |
> !505 |
> !504; !512 |
history
to the Unix tool called tail
through a `|`, a Unix "pipe." tail
takes an option for how many lines at the end of the "file" to display.grep
searches lines of text for those matching a pattern. It's particularly useful in combination with `|`.> history | grep pico |
history
is fed through the pipe to grep
, searching for lines containing the pattern. Now I can just do:> !40 |
ln
with the option -s
which makes a "soft link" to a file. I can never remember, but you want to put the existing file first (that's the opposite of the way I would design it):> cat temp/y.txt |
-> temp/y.txt
, where it links to.
echo
and the `>` redirection operator. Take a look at what's there with cat
:> cd |
mv
:> mkdir temp |
> echo "echo xyz" > temp/x.txt |
temp/x.txt
and the file system did not warn us first. There is no way to recover from this if it was a mistake!sh
command executes the text in the file you give it; in this case the output is familiar. Normally, we'd probably use the file extension .sh
for such a script, but it's not required. (Even with Python scripts, the .py
extension is only required if you want to import a module).#! sh |
./executable
where the `.` means this directory (the restriction has never made a lot of sense to me either, but it's apparently a security hole):> cat y.txt |
ls
command:> ls -l y.txt |
> chmod 644 y.txt |
> ls -l ~/Desktop |
ls
on the Desktop directory (above), we get a listing for both the temp
sub-directory and the file. Note that the first character in the "file mode" is d
for the directory. staff
is my group name, and after that comes the number of bytes in each "file", including directories.man ls
The Long Format
If the -l option is given, the following informa-
tion is displayed for each file: file mode, num-
ber of links, owner name, group name, number of
bytes in the file, abbreviated month, day-of-
month file was last modified, hour file last mod-
ified, minute file last modified, and the path-
name. In addition, for each directory whose con-
tents are displayed, the total number of 512-byte
blocks used by the files in the directory is dis-
played on a line by itself, immediately before
the information for the files in the directory.
If the file or directory has extended attributes,
the permissions field printed by the -l option is
followed by a '@' character. Otherwise, if the
file or directory has extended security informa-
tion (such as an access control list), the per-
missions field printed by the -l option is fol-
lowed by a '+' character.
-lR
:> ls -lR |
temp
directory:> cp y.txt temp |
mv
actually "moves" the file:> mv y.txt temp |
y.txt
on the Desktop (and in temp
) are gone forever.> rm temp/y.txt |
temp
has lots of files, so we try:> rmdir temp |
rm
and -r
and *
. Don't fall for it.man
page for rm
and maybe using the -i
option.
> cd |
cd
, says to change directory; with no other argument given, we go to our home directory. To see where we are in the file system we can do pwd
: print working directory. Also, the ~ symbol is a shorthand for the user's home directory.cd De
and then press tab. The shell fills out "Desktop."ls
: list the contents of the current directory (since there is no argument). And to see the contents of a file you might do cat
with the results shown.> ls -a |
ls -a
. There are many (many) other options with results cataloged under man some_command
./
is absolute, otherwise it's relative. Hence /usr/bin
is a directory starting from the root of the file system, while Desktop
is only understood as a valid destination if I'm in my home directory (or some other directory with Desktop as a sub-directory).*
is a wild card and matches anything; ls /usr/bin/pyth*
lists all the entries matching pyth- + something in the given directory. > pushd /usr/bin |
pushd
and popd
are useful here, with results as shown.cat
takes the option -n
, which numbers the output lines. cal
is probably faster than finding the Calendar.app, since I don't usually have it in the Dock.cd ..
, meaning "go up."
NSSocketPortNameServer *name_server; |
initWithReceivePort:sendPort:
. If you set it up with nil for the sendPort, it uses the same port for both sending and receiving, which is what you want.)// gcc talk3.m -o test -framework Foundation |
listen.py
is on my laptop:from Foundation import * |
> python listen.py |
task.py
uses the #! thing and is set to be executable (by the user only). The code looks for an int in argv and a second arg that tells whether to examine the environment variable dictionary.#! /usr/bin/python |
from Foundation import * |
2011-01-29 03:18:00.109 Python[19298:60f] -[OC_PythonNumber fileSystemRepresentation]: unrecognized selector sent to instance 0x101a6d950 |
> python parent.py |
D = NSProcessInfo.processInfo().environment() |
> python parent.py |
NSFileHandle.fileHandleForWritingAtPath_
apparently requires the file to already exist.p3 = NSHomeDirectory() + '/Desktop/results.txt' |
> python parent.py |
readDataToEndOfFile
. Not sure what's up with that yet.> python script.py |
@objc.signature('v@0:@8')
). I should probably explore all of that in another post.Decorators allow you to inject or modify code in functions or classes
The only constraint upon the object returned by the decorator is that it can be used as a function -- which basically means it must be callable. Thus, any classes we use as decorators must implement __call__.
What should the decorator do? Well, it can do anything but usually you expect the original function code to be used at some point. This is not required, however.
class entryExit(object): |
objc_msgSend
and you can do that yourself if you want:// gcc test.m -o test -framework Foundation |
objc_msgSend
.> ./test |
> python listen.py |
[OC_PythonString initWithBytes:length:encoding:]: unrecognized selector sent to instance 0x3635130 |
// gcc talk.m -o test -framework Foundation |
> ./test |
registerName:
will fail.from Foundation import * |
proxy_obj
was nil/None.
from Foundation import * |
<NSButton: 0x61c7b0> button |
// gcc tell.m -o test -framework Foundation |
a = ( 3, 4) = [ 3 ] |
P = (2,-4) |
(0 - y) / ( 0 - x) = 4/3 (from a) |
y = 4/3 x |
(-12 - 3y) = -(2 - x) |
M = [ 3 -3 ] |
3u - 3v = 2 |
v = -4u - 4 |
3u - 3(-4u - 4) = 2 |
a = ( 3, 4) |
u a + v b |
M = [ 3 -3 ] |
u a + v b - c = 0 |
[ 3 -3 2 ] [ u ] = [ 0 ] |
-2/3 [ 3 ] -4/3 [ -3 ] - [ 2 ] = [ 0 ] |
x = [ u ] = [ -2/3 ] |
A = [ 3 -3 2 ] |
NSCountedSet
. I'd never heard of this class, but it's described in the Apple docs about Collections (here). Besides the usual charactersNSArray |
NSPointerArray |
from Foundation import * |
x 1 |
count
of an object that's not in the set (as in Python), but as the docs say:removeObject:
does nothing if anObject is not present in the set
2010 - b == b % 100 |
L = data.strip().split('\n\n') |
title, seq = item.strip().split('\n',1) |
strip
, just to be safe.
y = sin x |
sin-1 y + cos-1 y = π/2 |
cos x = √ (1-y2) |
sin-1 y
:y = sin x |
sin-1 y + cos-1 y = π/2
, if:x = cos-1 y |
(u/v)' = (v u' - u v')/v2 |
1/(1 + y2) dy
, we get tan-1 y
. We're going to use that.1 + x + x2 + x3 + .. = 1/(1 - x) |
1 + x + x2 + .. = S |
(1 - x) (1 + x + x2 + x3 + ..) = 1 |
1 - x2 + x4 - x6 .. = 1/(1 + x2) |
tan-1 x
. And the lhs is:x - x3/3 + x5/5 - x7/7 |
x = 1
, then:1 - 1/3 + 1/5 - 1/7 + .. = tan-1 1 = π/4 |
otool
. For example> otool -L /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python |
> otool -L /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python |
export DYLD_PRINT_LIBRARIES=1
trick is pretty cool. nm
(like here).MachOView.app
at Source Forge (here) and tried it. It gave me quite a bit of insight into the structure of our simple examples from the other day (here). The screenshot above is from a run on its own executable. There is very detailed info on the object code (or images in geek-speak).svn co https://machoview.svn.sourceforge.net/svnroot/machoview machoview |
clang
as a gcc
replacement. (I'd love to have Xcode 4 but it's not worth the $99). Here we build Python 2.7 in record time:mkdir ~/temp |
Wed Jan 12 15:35:26 EST 2011 |
cd Python-2.7.1/ |
Wed Jan 12 15:38:02 EST 2011 |
~/temp/Python/bin/python |
> file ~/temp/Python/bin/python |
cd .. |
~/temp/Python/bin/python |
matplotlib
in it, as well as modify a Cocoa-Python application to link against that Framework. The only thing that looks a little shaky is the PyObjC install, but it still seems like it's working. Not every detail is given, but I hope it's enough.python-2.7.1-macosx10.6.dmg
(Mac Installer disk image (2.7.1) for OS X 10.6 and later).Shell profile updater
under Custom.. Not sure why, except I didn't want to spend time figuring out what it does./Library/Frameworks/Pythonframework |
.bash_profile
> export PATH=/$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin |
easy_install
would be difficult, but I got (something like) it from distribute
:> curl -O http://python-distribute.org/distribute_setup.py |
easy_install
documentation which I found impossible to figure out so far. But, poking around, I found easy_install
and easy_install-2.7
in bin
:> which easy_install-2.7 |
$PATH
is set up, easy_install
runs the wrong Python. That's OK, we just do:> easy_install-2.7 -U numpy |
> /usr/local/bin/python |
matplotlib
using instructions from Gavin Huttley (here, here). Since matplotlib-1.0.0
is available, I went for it. In the make.osx
file:PYVERSION=2.7 |
libpng-1.2.39
and libfreetype-2.3.11
(although these are not the latest versions.. In fact, I had a bit of trouble with libpng
since I got back a file that was really html, though titled as .gz or .bz2 or .xz. I finally found it here). For the other one:> FREETYPEVERSION=2.3.11 |
libpng
file INSTALL
, I notice that it says: "Before installing libpng, you must first install zlib, if it is not already on your system." So I'll do it in that order next time.]matplotlib
by running the script from here.> cd PyCogent-1.5 |
> cd tests |
Ran 3602 tests in 184.766s |
change SDK to 10.6
delete Python.framework
drag in new Python.framework
under Targets > X > Link Binary ..
drag in new Python.framework
> /usr/local/bin/python |
import sys |
2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) |
> sudo port install python27 |
> python |
>>> dir(__builtins__)
MyFramework.framework/ |
MyFramework.framework/Versions/A/MyFramework
Info.plist
file. Just as we set the key: NSPrincipalClass
, to have the value: SimpleMessage
in our bundle (here), there is a key in the Python.framework:cat Resources/Info.plist |
/System/Library/Frameworks/Python.framework/Versions/2.5/Python
import objc
fails with ImportError
, and the App terminates.easy_install
when it's not there yet, or alternatively build PyObjC from scratch. main.py
before the import of objc
, as shown:import sys |
2.5.4 (r254:67916, Jun 24 2010, 21:47:25) |
main.m
:Py_SetProgramName("/usr/bin/python"); |
Base SDK Mac OS X 10.5
The name or path of the base SDK being used during the build. The product will be built against the headers and libraries located inside the indicated SDK. This path will be prepended to all search paths, and will be passed through the environment to the compiler and linker. Normally, this path is set at the project level via the "Cross-Develop Using Target SDK" popup in the General tab of the project inspector. Additional SDKs can be specified in the ADDITIONAL_SDKS setting. [SDKROOT]
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Python.framework
/System/Library/Frameworks/Python.framework
Name: Python.framework
Path: /System/Library/Frameworks/Python.framework
/System/Library/Frameworks/Python.framework/Versions/2.6
main.py
:import os |
PATH /Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin |
PATH
variable is not the one from my shell. But there isn't any Python in /Developer/usr/bin
and both Python and python in /usr/bin
give 2.6. So that's not where it comes from. $PYTHONPATH just points to the App.> export DYLD_PRINT_LIBRARIES=1 |
/usr/bin/Python
which is 2.6!:> cd /System/Library/Frameworks/Python.framework/Versions/2.5 |
The stupid, it burns.link