Transistor / MOSFET Cheat Sheet
Here’s a little cheat sheet to keep your Bases/Collectors/Emitters and Gates/Drains/Sources straight:
Thanks to wikipedia’s transistor article for the graphics.
$> :(){ :|:& };:
Here’s a little cheat sheet to keep your Bases/Collectors/Emitters and Gates/Drains/Sources straight:
Thanks to wikipedia’s transistor article for the graphics.
If you want to make sure you didn’t go over 79 or 80 characters in a file you can simply run:
#!/bin/bash
grep -Pn '.{80,}' file-to-check
This uses grep’s perl regex option (-P) so we can use the expression .{80,} to find any lines that have >= 80 characters. The -n option prints the line numbers in the output so you can find them easily.
#!/bin/bash
REMOTE_HOST='example.com'
REMOTE_PORT=22
REPO_NAME='my_repository'
# create the bare remote repo
ssh $REMOTE_HOST -p$REMOTE_PORT \
"mkdir -p /var/git/$REPO_NAME.git && \
cd /var/git/$REPO_NAME.git && git init --bare" &&
# configure the local repo
git remote add origin ssh://$REMOTE_HOST:$REMOTE_PORT/var/git/$REPO_NAME.git &&
git config branch.master.remote origin &&
git config branch.master.merge refs/heads/master &&
# see if it worked...
git push origin master
=== UPDATE ===
Thanks to Tomasz Muras from Open Source Tech Blog, I now know about ssh-copy-id, which basically renders this post useless, except for academic reasons… Nevertheless, it’s a good example of piping through ssh to programs on a remote machine, so I’ll leave it up.
If you’ve already got access to a server or workstation via ssh, but are tired of entering your password, or need more security… You can transfer the public key on the client straight into the authorized_keys2 file on the server with one step:
PUB_KEY='id_rsa.pub'
REMOTE_HOST='example.com'
REMOTE_PORT=22
cat ~/.ssh/$PUB_KEY | ssh $REMOTE_HOST -p$REMOTE_PORT \
"cat >> ~/.ssh/authorized_keys2"
PUB_KEY will most likely be id_rsa.pub or id_dsa.pub. REMOTE_HOST and REMOTE_PORT are the hostname and port number of the server you’re sending the key to (you can leave the port option out if its on the standard ssh port 22).
I’ve got a pretty good list of songs I like, and I wanted to copy them all to a USB stick for the car… So here’s the bash one-liner I wrote to take an m3u playlist and copy all the files to a new directory:
#!/bin/bash
cat playlist.m3u | grep -v '#' | \
while read i; do cp "${i}" /path/to/destination/ ; done
Fix found at the Ubuntu Forums:
#!/bin/bash wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add - sudo apt-get clean sudo cd /var/lib/apt sudo mv lists lists.old sudo mkdir -p lists/partial sudo apt-get clean sudo apt-get update
Django models automatically come with some very useful methods under the objects Manager. Methods like Model.objects.all(), Model.objects.filter() and Model.objects.get() work quite well.
But what if you are constantly using the same QuerySet over and over? You can either keep typing MyModel.objects.filter(way-to-many-kwargs).order_by(something).etc... over and over -or- extend the objects Manager with your own crazy method.
Let’s say you’ve got the following Model:
class MyModel(models.Model):
...
...
...
All you need to do is subclass Manager, add your method and override your model’s old Manager:
class MyModelManager(models.Manager):
def crazy_query(self):
...
# A bunch of queries, joins, logic, etc...
...
class MyModel(models.Model):
...
...
...
objects = MyModelManager()
In order to make a handy Documentation link available in the upper right portion of the Django admin site, simply add the admindocs app to your settings.py and the admindocs urls to your urls.py
# In your settings.py:
INSTALLED_APPS = (
...
'django.contrib.admindocs',
...
)
# In your urls.py:
urlpatterns = patterns('',
...
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
...
)
NOTE: The admindocs urlconf must precede the admin site urlconf to work properly.
I was recently working on something for my company and needed to transfer all of our product pictures to my home computer. Unfortunately, all the actual product PNGs are intermingled with their corresponding and huge XCFs and other working files. Thus, I needed to exclude all files except the PNGs. Or, to include only the PNGs.
Here’s how to do it:
#!/bin/bash
rsync --include='*/' --include='*.png' --exclude='*' \
--prune-empty-dirs \
example.com:/path/to/source ./
Thanks to Dude for the tip on pruning empty directories. See his Comment below.
I pulled this from here.
The SaltyCrane Blog has a great post on the use of *args and **kwargs in python functions. Very simple and a good reference. You can check it out here:
http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/