snippets with tag 'system'

Shell : Perfect django .bat dev startup scriptCréez un fichier run.bat qu'il vous suffira de double cliquer pour lancer Django dans une boucle 'infinie'. Faites Ctrl+C pour relancer le serveur si besoin. (uniquement pour le serveur de dev)
@ECHO OFF

SET PORT=9000

:BEGIN
cd %~dp0
c:\python25\python.exe manage.py runserver 192.168.1.31:%PORT%
GOTO BEGIN
 
tags : system, django, bat, windows

Shell : afficher la branche GIT en cours dans votre prompt shell Ceci vous affichera un shell de ce style : ks12344876:~/django/KillerApp(newfeature) $
# a mettre dans  votre .bashrc

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

export PS1="\h:\w\$(parse_git_branch) $ "
tags : system, bash, git

Python : cross platform library loader helperdrax's answer for loading a named or absolute library on any platform :)
import os, sys, ctypes

# Types reminder:
#!/usr/bin/python
# String  : ctypes.c_char_p
# Integer : ctypes.c_int
# Long    : c_ulonglong

def loadbinlib(libname="", libpath=""):
   if not libpath:
       if sys.platform in ['win32','win64']:
          libpath = '%s.dll' % libname
       elif sys.platform in ['mac']:
          libpath = '%s.dylib' % libname
       elif sys.platform in ['linux', 'linux2']:
          libpath = '%s.so' % libname
   return ctypes.CDLL(libpath)
tags : python, system, linux, windows

Python : Hide static files in FiddlerFiddler is very powerful ! Customise the rules to not be spammed with useless requests. see also : http://www.fiddlertool.com/fiddler/dev/scriptsamples.asp
// Click 'Customize rules'

// add in class Handlers

public static RulesOption("Hide Js,Css,jpg,gif,png files [200, 304]")
var m_HideStatics: boolean = false;

// add in OnBeforeResponse
if (m_HideStatics && (oSession.responseCode == 200 || oSession.responseCode == 304) && ( oSession.url.toLowerCase().indexOf(".js")>-1 || oSession.url.toLowerCase().indexOf(".css")>-1 || oSession.url.toLowerCase().indexOf(".jpg")>-1 ||  oSession.url.toLowerCase().indexOf(".gif")>-1 || oSession.url.toLowerCase().indexOf(".png")>-1))
        {
            oSession["ui-hide"]="true"; 
        }
tags : system, proxy, windows

Shell : trouver tous les fichiers qui contiennent un patternAffiche toutes les lignes contenant 'todo' (insensible a la casse avec -i) dans tous les fichiers .py du repertoire en cours et recursivement. Affiche 2 lignes au dessous et en dessous du match, le nom du fichier, et colore les matches dans le term. 'todo' peut etre une expression régulière.
#!/bin/sh

find . -iname '*.py' -exec grep -H -B 2 -A 2 --color -i todo {} \;
tags : system, linux, regexp, bash

Django : Use your django project outside djangoThis is how to use your django models and data outside your web project. For example this can be used to create some cron jobs.
#!/usr/bin/python

from django.core.management import setup_environ
import settings
setup_environ(settings)

# do your stuff
tags : python, system, django

Shell : recursive search and replace in linux with find and sedreplace all occurences of oldtext with newtext in any .py file in /home/juju/project directory
#!/bin/sh

find /home/juju/project -iname '*.py' -exec sed -i 's/oldtext/newtext/g' {} \
tags : system, bash

Shell : Change windows default shell (replace explorer)This will change your windows default shell to your custom shell. (Ctrl+Alt+Del still active so you can reactivate explorer.exe if needed)
@echo off
REM create a .bat file with this command inside. execute then reboot.

reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /V Shell /t REG_SZ /d  "FullPathToYourApp.exe" /f
tags : system, bat, windows

Python : Détecter la version de l'OS
import sys
print sys.platform
tags : python, system

Shell : Liste fichiers récemment modifiés (récursif)
find . -type f -printf "%TY-%Tm-%Td %TT %p\n" | sort | less
tags : system, linux

Shell : Compter le nombre total de lignes dans un dossier (récursif)
#!/bin/sh
find . -type f -exec wc -l "{}" \; | awk ' { sum += $1 } END {print sum}'
tags : system, linux

all tags : python, system, vlc, video, apache, proxy, linux, django, MySQL, .NET, XML, XSL, regexp, bat, windows, bash, git

back to snippets home
site réalisé et hébergé par revolunet © 2009 - informations légales