Skip to content

Instantly share code, notes, and snippets.

View un33k's full-sized avatar
🎯
Focusing

Val Neekman un33k

🎯
Focusing
View GitHub Profile
@un33k
un33k / samplecode.php
Created September 5, 2012 17:56
Some sample code in PHP
<?php
// truncate string to specified length with ... at end
//////////////////////////////////////////////////////////////
function jaStrTrunc($str, $size)
{
$slen = strlen($str);
if ($slen < $size){
return $str;
}
@un33k
un33k / screenflow_export_settings.txt
Created July 30, 2012 22:18
ScreenFlow Export Settings (HD)
# By Val Neekman [[email protected]
# Outsourcefactor.com
#
ScreenFlow Settings.
File -> Export
Preset = Web High
File -> Export -> Customize ->
@un33k
un33k / vmware_fusion_headless.sh
Created July 30, 2012 01:43
Run Fusion 3.x OR 4.x in headless mode
# Start and stop headless VMs
# Val Neekman @ Neekware Inc.
# [email protected]
# You need to fix this to point to the right directory on your MAC
VMHOME="${HOME}/Documents/VMs"
if [ -z $1 ]
then echo "Usage: vm stop|start|stopall"
exit 1
@un33k
un33k / loto_robo.py
Created July 26, 2012 13:40
simple script to scrape (http://www.calottery.com) winning numbers and email it out.
# By Val Neekman ([email protected])
import os, urllib2, sys, re, datetime, smtplib
## HOWTO:
# Change the following settings then run this script as "python loto_robo.py"
###### Settings ########
SEND_EMAIL = True
FROMADDR = "[email protected]"
@un33k
un33k / vmware_fusion_shared_folder.txt
Last active September 1, 2020 10:05
Enable Shared Folders on vmware Fusion 4.x, 5.x & 6.x (Linux Ubuntu 12.x as guest OS)
Enable Shared Folders on vmware Fusion (4.x)+ (Example OS: Linux Ubuntu 12.x as guest OS)
1. First update your linux system:
sudo apt-get update
sudo apt-get install -y build-essential
sudo aptitude -y safe-upgrade
2. Reboot your system just in case you have a new kernel
sudo shutdown -r now
@un33k
un33k / SingleSlash
Created July 5, 2012 11:56
This middleware removes extra back2back slashes from incoming request
from django.http import HttpResponseRedirect
import re
slash_re = re.compile('/{2,}')
class SingleSlashes:
""" This middleware removes extra back2back slashes from an incoming request """
def process_request(self, request):
if '//' in request.path:
new_path = slash_re.sub('/', request.path)
@un33k
un33k / slash_middleware.py
Created July 5, 2012 11:53 — forked from gregplaysguitar/slash_middleware.py
Append OR remove slash in django - like APPEND_SLASH but smarter.
from django import http
from django.utils.http import urlquote
from django.core import urlresolvers
class AppendOrRemoveSlashMiddleware(object):
"""
Like django's built in APPEND_SLASH functionality, but also works in reverse. Eg
will remove the slash if a slash-appended url won't resolve, but its non-slashed
counterpart will.
@un33k
un33k / onlinenow.py
Created June 12, 2012 01:47 — forked from dfalk/onlinenow.py
django online users
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth.models import User
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
@un33k
un33k / git-create-branch.sh
Created May 8, 2012 02:01
Create a git branch
#!/bin/sh
# git-create-branch <branch_name>
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi
set branch_name = $1
git push origin origin:refs/heads/${branch_name}
@un33k
un33k / text.py
Created April 20, 2012 00:12 — forked from joshourisman/text.py
A Django template filter that truncates a string to at most X characters while respecting word boundaries.
from django.template import Library
from django.utils.encoding import force_unicode
from django.utils.functional import allow_lazy
from django.template.defaultfilters import stringfilter
register = Library()
def truncate_chars(s, num):
"""
Template filter to truncate a string to at most num characters respecting word