I was just hesitated to see annoying useful BibTeX ids like: "???_tonejito_???" so I found this page [1] that shows how to mess with the Zotero Firefox plugin, and I came out with the idea of using the md5 of the title as identifier (for me that is better than the other id).
The file in question was <FirefoxProfile>/zotero/translators/BibTeX.js the whole code is javascript so it's easy to modify and play with.
Looking around the web I also found this github:gist [2] to calculate an md5 sum from a given string, I pasted all the code at the end of the file and used the md5_hex function as follows to replace the element key.
$ diff -u /tmp/BibTeX.js BibTeX.js
--- /tmp/BibTeX.js 2012-10-31 02:51:49.000000000 -0600
+++ BibTeX.js 2012-10-31 02:51:43.000000000 -0600
@@ -2083,7 +2083,8 @@
if(!type) type = "misc";
// create a unique citation key
- var citekey = buildCiteKey(item, citekeys);
+ //var citekey = buildCiteKey(item, citekeys);
+ var citekey = hex_md5(buildCiteKey(item, citekeys));
// write citation key
I'm currently using the Zotero plugin [3] and the zotero bibtex auto-exporter plugin [4], I tested this using the preferences pane for the autoexporter and run a manual test. After a couple of tries the results were like this:
@misc{20c7358045528f33804340fb6510b8b9,
title = {tonejito {(Andres} Hernandez) · {GitHub}},
url = {https://github.com/tonejito/},
urldate = {2012-10-31},
howpublished = {https://github.com/tonejito/},
file = {tonejito (Andres Hernandez) · GitHub:/Users/tonejito/Library/Application Support/Firefox/Profiles/profile.default/zotero/storage/AAAAAAAA/tonejito.html:text/html}
},
@misc{823e4a8551f18d37794d3115226700ba,
title = {Tonejito},
url = {http://tonejito.blogspot.com/},
urldate = {2012-10-31},
howpublished = {http://tonejito.blogspot.com/},
file = {Tonejito:/Users/tonejito/Library/Application Support/Firefox/Profiles/profile.default/zotero/storage/BBBBBBBB/tonejito.blogspot.com.html:text/html}
},
@misc{d83e6f346506b44510957a2fa00fff13,
title = {Andres Hernandez {(Tonejito)} on Twitter},
url = {https://twitter.com/tonejito},
urldate = {2012-10-31},
howpublished = {https://twitter.com/tonejito},
file = {Andres Hernandez (Tonejito) on Twitter:/Users/tonejito/Library/Application Support/Firefox/Profiles/profile.default/zotero/storage/CCCCCCCC/tonejito.html:text/html}
}
So I can use any of this hashes in a LaTeX document like this and the bibliography entries will be sorted and referenced correctly.
\textbf{Twitter}
\cite{d83e6f346506b44510957a2fa00fff13}
\textbf{Blog}
\cite{823e4a8551f18d37794d3115226700ba}
\textbf{Github}
\cite{20c7358045528f33804340fb6510b8b9}
Thanks LaTeX and BibTeX
[1] http://www.curiousjason.com/zoterotobibtex.html
[2] https://gist.github.com/951664
[3] https://addons.mozilla.org/en-US/firefox/addon/zotero/
[4] https://addons.mozilla.org/en-US/firefox/addon/zotero-bib-autoexport/
--
= ^ . ^ =
Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts
Wednesday, October 31, 2012
Friday, June 29, 2012
% make FF
% cat Makefile
FOLLOWERS?=
ME?=Tonejito
SIGNATURE?="= ^ . ^ ="
FF:
if [ "${FOLLOWERS}" ] ; \
then \
for FOLLOWER in ${FOLLOWERS} ; \
do \
echo "FF @$$FOLLOWER" ; \
done ; \
else \
echo "FF @${ME}" ; \
fi ;
echo ${SIGNATURE} ;
--
% make -s
FF @Tonejito
= ^ . ^ =
% make -s FF FOLLOWERS="alpha beta gamma"
FF @alpha
FF @beta
FF @gamma
= ^ . ^ =
--
crontab -e
# m h dom mon dow command
0 12 * * 5 make FF
--
= ^ . ^ =
Tuesday, June 19, 2012
Kill annoying processes that match a pattern
So, there was a bunch of annoying processes named wit a pattern and I wanted to kill all of them
Here is the script (I know this can be done in a much cleaner way in awk, but I like this way)
#!/bin/sh
Here is the script (I know this can be done in a much cleaner way in awk, but I like this way)
#!/bin/sh
P="master(-worker)?"
PS=/bin/ps
SED=/bin/sed
KILL=/bin/kill
GREP=/bin/grep
CUT=/usr/bin/cut
$KILL `$PS ax | $GREP -E $P | $GREP -v grep | $SED -e 's/^\ \+//g' | $CUT -d ' ' -f 1 | $GREP -E '^[[:digit:]]+'`
--
= ^ . ^ =
Tuesday, May 29, 2012
VirtualBox serial console on Mac OS X
I normally access a VirtualBox VM serial console through minicom in GNU/Linux, but for some reason it didn't worked on Mac OS X, so I researched about how can I access the serial console.
VirtualBox (and VMware for what I saw on the pages [1]) map the serial device of the virtual machine to a "Named Pipe" (actually a UNIX Domain Socket) which can be accessed using netcat or minicom. I tried the nc -U variant as stated in the page but I had no luck making it work because the mac ports version of netcat does *not* support attaching to UNIX domain sockets [2].
The screen man page [3] describe how to attach to a existing tty device but the file is a named pipe so the program cannot do its magic with it. There were some pages describing how to use socat [4] to map a UNIX domain socket to a tty device (actually a PTY) [5] [6] [7]. I also found a couple VMware forum posts with useful links [8] [9].
Thanks to this I can happily run the following two commands to attach to the serial console
In this case the desired PTY is /dev/tty007 and then in another terminal window
I wanted to do this as painful (automated) as possible, but there were a few problems:
I managed to solve the problem by redirecting the socat output to a file (which might also be a FIFO if you are interested), and then pointing grep to get the desired line and piping that output to sed to clean the text and get the desired PTY name.
So the above line does the following:
Update: I ported the script to make it work with Linux, check out the new post for details and also the @Github gist.
VirtualBox (and VMware for what I saw on the pages [1]) map the serial device of the virtual machine to a "Named Pipe" (actually a UNIX Domain Socket) which can be accessed using netcat or minicom. I tried the nc -U variant as stated in the page but I had no luck making it work because the mac ports version of netcat does *not* support attaching to UNIX domain sockets [2].
The screen man page [3] describe how to attach to a existing tty device but the file is a named pipe so the program cannot do its magic with it. There were some pages describing how to use socat [4] to map a UNIX domain socket to a tty device (actually a PTY) [5] [6] [7]. I also found a couple VMware forum posts with useful links [8] [9].
Thanks to this I can happily run the following two commands to attach to the serial console
% socat -d -d ./Thesis.ttyS0 PTY
2012/05/29 01:08:00 socat[29713] N opening connection to LEN=16 AF=1 "./Thesis.ttyS0"
2012/05/29 01:08:00 socat[29713] N successfully connected from local address LEN=16 AF=1 ""
2012/05/29 01:08:00 socat[29713] N successfully connected via
2012/05/29 01:08:00 socat[29713] N PTY is /dev/ttys007
2012/05/29 01:08:00 socat[29713] N starting data transfer loop with FDs [3,3] and [4,4]
In this case the desired PTY is /dev/tty007 and then in another terminal window
% screen /dev/ttys007I wanted to do this as painful (automated) as possible, but there were a few problems:
- The PTY device allocated on Mac OS X is subject to the number of terminals currently being used, so it is a variable device.
- I have to run two commands in order to get the PTY and attach to it (socat, then screen)
- Simple shell magic can't work because socat outputs the messages to stderr.
- Map the UNIX domain socket to a PTY
- Somehow, get the PTY name (the tricky part)
- Once the name is known, attach to the PTY
Map the socket to a PTY
Same as above, still the messages are output to stderrsocat -d -d ./Thesis.ttyS0 PTYGet the PTY name
The device name is printed to stderr and simply by doing a 2>&1 and pipe it through a sed or awk instance will do the trick. NO!!!, for some reason (still unknown to me) sed and grep got stuck and even if they got the apropriate input they didn't send anything to the screen.I managed to solve the problem by redirecting the socat output to a file (which might also be a FIFO if you are interested), and then pointing grep to get the desired line and piping that output to sed to clean the text and get the desired PTY name.
Making it work altogether
Since the device is dynamically allocated and the socat output may vary, this kind of magic can be done, yes it might also be done with an sed [10] or awk script [11], but there was 2 or 3 AM and I just made it work.screen `socat -d -d ./Thesis.ttyS0 PTY 2>&1 | tee /tmp/x
&>/dev/null & grep '.*N\ PTY\ is\ ' /tmp/x | sed -e 's/.*N\
PTY\ is\ //g'`So the above line does the following:
- Map the socket
- Two choices here, I chose the first one because was faster but YMMV.
- Use
2>&1 | tee /tmp/x &>/dev/nulland redirect the output to a file and optionally to the terminal (I did it for debugging but wasn't interested in keeping it). - Use
&> /tmp/x & sleep 1to give time to socat to write in the file and then read it to get the device name. - Attach to the screen
screen `all the above thing in backquotes to execute it before`
socat -d -d ./Thesis.ttyS0 PTY 2>&1 | tee /tmp/x
&>/dev/null & grep '.*N\ PTY\ is\ ' /tmp/x | sed -e 's/.*N\
PTY\ is\ //g'socat -d -d ./Thesis.ttyS0 PTY &> /tmp/x & sleep 1 ; grep '.*N\ PTY\ is\ ' /tmp/x | sed -e 's/.*N\ PTY\ is\ //g' screen `socat -d -d ./Thesis.ttyS0 PTY 2>&1 | tee /tmp/x &>/dev/null & grep '.*N\ PTY\ is\ ' /tmp/x | sed -e 's/.*N\ PTY\ is\ //g'`
--
= ^ . ^ =
[1] http://wiki.networksecuritytoolkit.org/nstwiki/index.php/Console_Output_and_Serial_Terminals
[2] http://fixunix.com/slackware/537945-nc-does-not-support-unix-domain-socket.html
[3] http://linux.die.net/man/1/screen
[4] http://www.dest-unreach.org/socat/
[5] http://www.linuxsmiths.com/blog/?p=312
[6] http://blackmagic02881.wordpress.com/2007/02/05/linux-serial-console-how-to-with-vmware-server/
[7] http://thewayeye.net/2009/december/4/connecting-virtual-machines-serial-console-os-x-and-vmware-fusion[8] http://communities.vmware.com/thread/33528
[9] http://communities.vmware.com/thread/28508
[11] http://linux.die.net/man/1/sed
[10] http://linux.die.net/man/1/awk
Update: I ported the script to make it work with Linux, check out the new post for details and also the @Github gist.
--
= ^ . ^ =
Labels:
Development,
linux,
Mac OS X,
Script,
sh,
Thesis,
unix,
VirtualBox,
xNAS
Friday, May 11, 2012
OpenBSD - Check hosts alive
#!/bin/sh
# Check all hosts within the network
# BSD license
PING=/sbin/ping
SEQ=gseq
NET=192.168.2
ME=192.168.0.2
i=1;
while [ $i -le 254 ] ;
do
$PING -v -D -s 8 -t 1 -w 1 -c 1 -I $ME $NET.$i 1>/dev/null
printf "$?"
i=`expr $i + 1` ;
done
printf "\n"
Thanks to this site [1] for the while loop
[1] http://www.linuxmisc.com/27-linux-on-alpha/9fdb61f03bee119e.htm
--
= ^ . ^ =
Labels:
bsd,
Development,
Networking,
OpenBSD,
Script,
sh,
unix
Thursday, March 22, 2012
SQL TEST
CREATE DATABASE _ ;
CREATE TABLE _._ (_ int(1) not null primary key);
INSERT INTO _._(_) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
SELECT * FROM _._;
DROP TABLE _._ ;
DROP DATABASE _;
--
= ^ . ^ =
Delete temp files and directories
% while sleep 0.1 ; do if [ $(($RANDOM % 2)) -eq 0 ] ; then rmdir -v `mktemp -d` ; else rm -v `mktemp` ; fi ; done ;
--
= ^ . ^ =
--
= ^ . ^ =
Wednesday, March 14, 2012
show my ip address
#!/bin/sh
IP=/bin/ip
SED=/bin/sed
CUT=/usr/bin/cut
IF=en0
if [ ! -z ${1} ]
then
IF=${1}
fi
$IP addr show dev $IF | $SED -n 3p | $SED -e 's/\ \+/\ /g' -e 's/\/.*$//g' | $CUT -d ' ' -f 3
--
= ^ . ^ =
Labels:
Bash,
bsd,
Development,
linux,
Networking,
Script,
sh,
unix
Wednesday, February 1, 2012
make my life hard
% cat Makefile
# = ^ . ^ =
_:
make -f $(PWD)/Makefile &
% make
--
= ^ . ^ =
# = ^ . ^ =
_:
make -f $(PWD)/Makefile &
% make
--
= ^ . ^ =
Subscribe to:
Posts (Atom)