Skip to content

Instantly share code, notes, and snippets.

View Geekfish's full-sized avatar
🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝

Eleni Lixourioti Geekfish

🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝
View GitHub Profile
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@dionyziz
dionyziz / primes.php
Created August 23, 2011 21:57
An interesting way to implement the Sieve of Eratosthenes in PHP
<?php
class PrimeIterator implements Iterator {
private $i;
private $primes;
private function generateNextPrime() {
$candidate = $this->primes[ count( $this->primes ) - 1 ];
do {
$candidate += 2;
$isPrime = true;
@kesor
kesor / profile_middleware.py
Last active March 16, 2021 15:37
Django cProfile middleware
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
import cProfile
import pstats
import marshal
from cStringIO import StringIO
class ProfileMiddleware(object):
def __init__(self):
if not settings.DEBUG:
@midu
midu / no-console.log.sh
Created November 8, 2011 21:05
pre-commit git hook to prevent console.log in javascript files
FILES_PATTERN='\.(js|coffee)(\..+)?$'
FORBIDDEN='console.log'
git diff --cached --name-only | grep -E $FILES_PATTERN | GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && echo 'COMMIT REJECTED Found "console.log" references in your javascript. Please remove them before commiting';
# my zsh does annoying things with !
[ $? -ne 0 ]
@soemarko
soemarko / theme.html
Created November 26, 2011 16:18
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@yuchant
yuchant / capture.py
Created February 28, 2012 00:16
Django capture contents of block - variable assignment in template like Shopify
"""
Capture contents of block into context
--------------------------------------
Use case: variable accessing based on current variable values.
{% capture foo %}{{ foo.value }}-suffix{% endcapture %}
{% if foo in bar %}{% endif %}
Created on Monday, February 2012 by Yuji Tomita
@jlesquembre
jlesquembre / postmkvirtualenv
Created March 15, 2012 08:12
Creates a symlink to PyQt libraries when a new virtual environment is created
#!/bin/bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv
libs=( PyQt4 sip.so )
python_version=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
var=( $(which -a $python_version) )
get_python_lib_cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
var gistPrefix = 'https://gist.github.com/',
// Cache document.write so that it can be restored once all Gists have been
// embedded.
cachedWrite = document.write,
body = $('body'),
// Map each p.gist to an object that contains the paragraph to be replaced
// and the Gist's identifier.
gists = $('a.gist').map(function(n, a) {
a = $(a);
var href = a.attr('href');
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@abrookins
abrookins / gist:3440646
Created August 23, 2012 19:32
Set the path of an ImageField in Django
from django.db import models
# Assuming this model.
class Example(models.Model):
image = models.ImageField(upload_to="somewhere/special")
# You want to set this field to point to an existing image (in a script, or a view, etc.).
example = Example.objects.get(id=1)