Recent Updates Page 2 RSS Toggle Comment Threads | Keyboard Shortcuts

  • diegor 3:28 pm on June 12, 2011 Permalink | Reply
    Tags:   

    HOWTO: ignore requests without user agent in Apache 

    A public web server could be reached by many http requests with no user agent. Apache can avoid this kind of requests. The configuration is very straightforward:

    <Directory /path/to/a/directory>
        SetEnvIfNoCase User-Agent "^-?$" noUserAgent
        Order Allow,Deny
        Allow from All
        Deny from env=noUserAgent
    </Directory>

    In this example Apache ignores all requests without user agent that are directed to /path/to/a/directory

    Any comments are appreciate.

     
  • diegor 9:45 am on May 20, 2011 Permalink | Reply
    Tags:   

    HOWTO: “ip_conntrack: table full, dropping packet” 

    I used to manage a server based on linux and once I had this strange message:

    #> ip_conntrack: table full, dropping packet

    One of the effects of this message is that you aren’t able to make and receive new connections.
    To solve that is enough increase ip_conntrack_max value. As first step check the current value typing:

    #> cat /proc/sys/net/ipv4/ip_conntrack_max
    65536

    Now, increase this value typing:

    #> echo 131072 > /proc/sys/net/ipv4/ip_conntrack_max

    Generally the right value of ip_conntrack_max is set to the total MB of RAM multiplied by 16. If you have 8GB RAM (8192 MB), the value should be 131072.

     
  • diegor 10:27 pm on April 18, 2011 Permalink | Reply
    Tags:   

    HOWTO: passing arguments to functions in Django Template 

    Django doesn’t permit you because it goes against MVC model, but sometime it’s useful to get output (in view level) depending on specific arguments. For example in my model i have this method:

    def get_value(self, arg_to_pass):
       if (arg_to_pass.is_type_A):
          return self.value_for_A
       else:
          return self.value_for_B

    In your template you’ll type {{ object.get_value }} but you can’t pass argument. You can solve this issue with templatetags.
    Create a templatetag like this below:

    def callMethod(obj, methodName):
        method = getattr(obj, methodName)
    
        if obj.__dict__.has_key("__callArg"):
            ret = method(*obj.__callArg)
            del obj.__callArg
            return ret
        return method()
    
    def args(obj, arg):
        if not obj.__dict__.has_key("__callArg"):
            obj.__callArg = []
    
        obj.__callArg += [arg]
        return obj
    
    register.filter("call", callMethod)
    register.filter("args", args)

    Ok, almost done. Now, in your template, call your method typying:

    {{ object|args:arg_to_pass|call:"get_value" }}

    Job done! If you have any question, leave a comment! :)

    Source: sprklab.com

     
  • diegor 12:52 pm on April 9, 2011 Permalink | Reply  

    Flash post: new, again 

    Yesterday I’ve decided to update my site and significant changes are:

    Do you like it? Comment!

     
  • diegor 1:00 pm on March 11, 2011 Permalink | Reply
    Tags:   

    HOWTO: make vim show ending line spaces as characters 

    When you edit a file with vim, it’s useful understand where the line ends especially if there are spaces at the end of the line. Instead checking all lines, you can highlight white spaces. How?

    1. Open Vim from Terminal
    2. type
      :set list
    3. You see an output like the one below
    4. If you want see each space as character, type this command
      :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
    5. The output should look like below

    Very simple and useful tip! :)

    If you have any doubt, advice or something else, comment this post! :)

    Source: Stackoverflow

     
    • proudlygeek 1:43 pm on March 11, 2011 Permalink | Reply

      Vim is my favourite text editor, i use it pretty anywhere :-)

      I’ll share a useful trick for commenting multiple lines of code:

      1) SHIFT-V to select multiple lines;
      2) Type “:s/^/#”

      Where “^” indicates the beginning of a line and “#” the comment symbol of your choice.

      To decomment a block of code:

      1) Shift-V
      2) Type “:s/^#//”

  • diegor 7:58 pm on March 4, 2011 Permalink | Reply
    Tags:   

    HOWTO: run cron job in seconds 

    If you know what cron is, you also know that the minimum time to execute a job is a minute. There is a small tip to execute a cron job every X seconds. For example if you need to run a cron job every 30 seconds (it’s a common case), you can do it adding these lines to crontab:

    * * * * * root sh /path/to/myscript.sh
    * * * * * root sleep 30 && sh /path/to/myscript.sh

    Both lines execute the job every minute, but the second one waits 30 seconds using “sleep” command from bash.

    If you have any question, comment this post. :)

     
    • Andrea 4:01 pm on July 24, 2011 Permalink | Reply

      Very nice guide! It’s very tricky. Anyway do you know some implementation of a scheduler such cron that deals with seconds instead of minutes?

    • diegor 11:17 pm on July 24, 2011 Permalink | Reply

      Mmm, sorry I don’t know any scheduler except cron..

  • diegor 1:23 pm on March 1, 2011 Permalink | Reply
    Tags:   

    Old HOWTOs.. Which translate? 

    For some years this blog has been written only in italian, and as you know, some time ago I decided to switch it in three languages. While I wrote only in italian, I made many HOWTOs (guess the language?!). In below list you can find all my italian howtos (yep, i’ve translated only the title).

    If you like one of them, tell me.. so I can translate it for you. If you like, you may translate too :)

    • modify html code from web browser
    • open a file with Vim at a specified line
    • improve wordpress performance on Dreamhost
    • remove “Briefly unavailable for scheduled maintenance. Check back in a minute.” in wordpress
    • install latex in OSX
    • uninstall fink in OSX
    • create a “tiltshift” image
    • strangeness in Google Earth
    • make speak and sing your mac
    • fix Firefox Home login in iPhone
    • create an “HDR” image
    • keep clean OSX with “periodic” command
    • write natively NTFS partition with OSX
    • fix Steam in OSX with a case-sensitive partition
    • “open” command in OSX
    • “psycopg2 module: cannot import name tz”
    • install iPhone application with XCode without certificate
    • enable SSL in Apache in OSX
    • discover your public IP from terminal
    • hide Disqus into static pages de wordpress
    • redirect output to file and/or to standard output
    • replace a broken disk from a software RAID in linux
    • “Certificate error” on Nokia S60
    • configure VirtualHost in OSX
    • opensource software for OSX
    • AppFresh, update your apps in OSX
    • install Tilimi on Linux
    • download photos and videos from iPhone with OSX
    • no Italian accented letters with OSX
    • list voice commands for iPhone 3Gs
    • change language of voice command in iPhone 3Gs
    • install mod_wsgi in OSX
    • tips & tricks, shortcuts and secrets in Snow Leopard
    • SSH authentication through key
    • what’s Growl?
    • create ringtones for iPhone with iTunes 9
    • create an encrypted disk in OSX
    • activate DHCP server in OSX
    • fix Macfusion in Snow Leopard
    • show iPhone battery’s percentage (3.X)
    • first steps with iPhone
    • Cache Out X, delete Mac’s cache
    • Geek Tool for OSX
    • execute 32-bit application on Snow Leopard
    • Snow Leopard + django + postgresql + psycopg2
    • drop the brand from Nokia E71
    • tunneling with SSH
    • wake on lan (WOL)
    • crossed and direct ethernet cable scheme
    • to Postbox to Thunderbird 3
    • default editor in SVN
    • python console programming
    • turn off the Mac with shortcuts
    • convert and transfer videos with Evon in OSX
    • compress folders in Windows XP
    • find and delete files with a command
    • download files with free download manager
    • “defaults” command in OSX
    • control fans of your MBP
    • create a network alias in OSX
    • create a network alias in Linux
    • change column name in postgresql
    • activate “fast user switching” in OSX
    • how to write email in the right way
    • “mdfind”, Spotlight from console
    • show date in OSX menu bar
    • enable from terminal “screen sharing” in OSX
    • DropBox, share your files
    • reset della PRAM, NVRAM e PMU on Mac
    • what are “.DS_Store” files in OSX?
    • EEE PC recovery via USB (windows and linux)
    • Zeroshell on Xen

    Comment this post with your request or write me an email!

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel

Switch to our mobile site

Powered by Google Talk Widget