mercredi 25 mars 2015

Firefox Detect if a page is loaded in the "sidebar" (Javascript)

Firefox has this wonderful option when you create a bookmark : you can load a specific page directly in the sidebar. But it's not very well documented on how you can detect as a web developer that your page is actually shown in such a sidebar.
This is the javascript trick I used (validated with Firefox version=20.0.1):
{ if (window.content == window) /* not sidebar */ else /* sidebar */ }
Source :

Aspect-Oriented Software Development

FROM : http://www.aspectprogramming.com/aosd


What is Aspect-Oriented Software Development?

Aspect-Oriented Software Development (AOSD), sometimes just called Aspect-Oriented Programming (AOP), is a new approach to software design that addresses modularity problems that are not handled well by other approaches, including Structured Programming and Object-Oriented Programming (OOP). AOSD complements, but doesn't replace those approaches.

Outlook VBA : mark a folder/subfolders tree as read

I have been forced to use Outlook (2010), and one of the main features I've been missing was to be able to mark all a folder and sub-folders trees as read in 1 shot. The solution I found was to activate the VBA macros, and to link one as a task icon in the usual Outlook views.
Note that the macro given below is prompting a list of your outlook folders. This could be enhanced by choosing the selected folder since outlook doesn't allow to select

How to activate the Developer tab in outlook and authorize the Macro execution

  • Go to the "File"
  • Go to "Options" to open the "Outlook Options" window
  • In "Customize Ribbon", on the right panel, select "Developer".
  • Finish this step with "Ok".
  • Go to "Trust Center", then "Trust Center Settings" to open the "Trust Center" window
  • Go to "Macro Settings".
  • Select "Enable all macros (not recommended; potentially dangerous code can run)".
  • Finish by clicking "Ok" to close the "Trust Center" and the "Outlook option" windows.

How to create a VBA macro in Outlook

A macro is any public subroutine in a code module. A function or a private subroutine cannot be a macro, and a macro cannot be located in a class or form module. To create a new macro :
  1. In Outlook, on the Developer tab of the Microsoft Office Fluent ribbon, click Visual Basic.
  2. In the Project window, double-click the module you want to contain the macro.
  3. On the Insert menu, click Procedure.
  4. In the Name box, type a name for the macro. The name cannot contain spaces.
  5. Click OK. The template for the macro subroutine appears in the code module window.
  6. Type the code you want to run in the body of the subroutine.
(from ref [2])

Source Code of the Macro

Sub MarkAllRead()

Dim ResultFolder As Folder
Dim Folder As Folder
Dim item As MailItem
Dim BaseFolder As Outlook.MAPIFolder
Dim WalkResult As Long

Set BaseFolder = Application.GetNamespace("MAPI").PickFolder
Set ResultFolder = GetFolder(BaseFolder.FolderPath)

For Each Folder In ResultFolder.Folders
WalkResult = GetNextLevel(ResultFolder.FolderPath)

For Each item In Folder.Items.Restrict("[unread] = true")
item.UnRead = False
Next
Next
Set ResultFolder = Nothing
Set Folder = Nothing
Set item = Nothing
End Sub

Function GetNextLevel(strFolderPath As String) As Long

Dim WalkResultFolder As Folder
Dim Folder As Folder
Dim item As MailItem
Dim WalkResult As Long
Set WalkResultFolder = GetFolder(strFolderPath)
For Each Folder In WalkResultFolder.Folders

WalkResult = GetNextLevel(Folder.FolderPath)

For Each item In Folder.Items.Restrict("[unread] = true")
item.UnRead = False
Next
Next
Set ResultFolder = Nothing
Set Folder = Nothing
Set item = Nothing
End Function

Function GetFolder(strFolderPath As String) As MAPIFolder

Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim i As Long
On Error Resume Next

strFolderPath = Replace(strFolderPath, "\\", "")

strFolderPath = Replace(strFolderPath, "/", "\")

arrFolders() = Split(strFolderPath, "\")

Set objFolder = Application.GetNamespace("MAPI").Folders.item(arrFolders(0))
If Not objFolder Is Nothing Then
For i = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.item(arrFolders(i))

If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
End Function
(from ref [1] )

How to add a quick access link to your macro


  • Right click on the arrow at the right end of the Quick Access Toolbar (top right of the outlook window)
  • Select "More Commands"
  • On the left panel, select "Macros" (by default it's on "Popular Commands")
  • Select your Macro on the list, and hit "Add >>". If you have some other icons, you can reorganize them with the up & down arrow on the right.

  • Sources / references

    To Do

    Change the macro so that it directly takes the selected Folder as an input.

    mardi 17 février 2015

    REF / Link : Benchmark of Python Web Servers

    http://nichol.as/benchmark-of-python-web-servers

    An extensive analysis of the different python web servers available on the market.

    mercredi 11 février 2015

    awk 'system()' vs xargs

    Two different syntaxes for processing a command over a list of arg.

    Let's take for example, the list of PID you want to kill(all the processes matching "toto") :

    ps | grep toto | awk -F' ' '{print $2}' | xargs kill -9

    is equivalent to

    ps | grep toto | awk -F' ' '{system("kill -9 "$2}'

    note that the space at the end of the string "kill -9 " is important since the $2 will be concatenated.

    mardi 10 février 2015

    while true for WPS

    While true permettant de se connecter dès que quelqu'un initie une connexion avec du WPS


    wpa_cli
    while : ; do sudo wpa_cli wps_pbc any ; sleep 120 ; done &
     
     
    Source :
    http://korben.info/intrusion-dans-un-reseau-wifi-grace-au-wps.html?utm_source=feedburner&utm_medium=email&utm_campaign=Feed:+Korben_nl+%28Korben%29

     

    lundi 26 janvier 2015

    Find big files

    In the current path, find all files bigger than, let's say 10MiB  (10^7Bytes).


    $ find . -type f -size +10000000c -exec ls -l {} \; 


    samedi 8 novembre 2014

    How to store you passwords

    a little tutorial on how to use bcrypt to store your passwords

    https://medium.com/@martyweiner/store-your-users-passwords-correctly-c155ac90f0c2

    mercredi 29 octobre 2014

    port install error "checksum does not exist" : clean and reinstall



    I had an error with the Mac Ports (https://www.macports.org/) on the dbus-glib install while trying to install some other packages. It was just saying that it did not exist in /opt/local/var/macports/distfiles/dbus-glib . It's not clear what broke this package for now, but the way to solve the issue was simple as found here : https://trac.macports.org/ticket/45534


            sudo port clean


    and then, reinstall...
            sudo port install


    And check, I could upgrade all the other packages and install some other new ones :-)



    ---
    (For "google" parse purpose, here are the errors I was getting)
    ---
    [...]
    --->  Found 5 broken port(s), determining rebuild order
    --->  Rebuilding in order
         libgnomeui @2.24.5 +x11
         net-snmp @5.7.2
         webkit-gtk @2.0.4 +video
         gimp2 @2.8.6 +help_browser+python27
         xsane @0.998
    --->  Computing dependencies for dbus-glib
    --->  Verifying checksums for dbus-glib
    Error: org.macports.checksum for port dbus-glib returned: dbus-glib-0.102.tar.gz does not exist in /opt/local/var/macports/distfiles/dbus-glib
    Please see the log file for port dbus-glib for details:
        /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_devel_dbus-glib/dbus-glib/main.log
    Error: Unable to upgrade port: 1
    Error rebuilding libgnomeui
        while executing
    "error "Error rebuilding $portname""
        (procedure "revupgrade_scanandrebuild" line 395)
        invoked from within
    "revupgrade_scanandrebuild broken_port_counts $opts"
        (procedure "macports::revupgrade" line 5)
        invoked from within
    "macports::revupgrade $opts"
        (procedure "action_revupgrade" line 2)
        invoked from within
    "action_revupgrade $action $portlist $opts"
        (procedure "action_target" line 96)
        invoked from within
    "$action_proc $action $portlist [array get global_options]"
        (procedure "process_cmd" line 93)
        invoked from within
    "process_cmd $remaining_args"
        invoked from within
    "if { [llength $remaining_args] > 0 } {

        # If there are remaining arguments, process those as a command
        set exit_status [process_cmd $remaining..."
        (file "/opt/local/bin/port" line 5254)

    jeudi 9 octobre 2014

    JavaScript multiline code (JSON description)

    It is currently not possible to store a multiline string in javascript. This is annoying since for example storing some JSON data often leads to long data to concatenate or to push into an array.
    If you want to avoid this, you can use the following trick, since javascript accepts multiline comments, and returns them to the toString call on a function :

    var jsonDescriptionText= function(){/*
    [
        {
            "cat": "Categ1",
            "links": [
                {
                    "txt": "text1",
                    "url": "http://url",
                    "title": "mouseover field"
                }
            ]
        }
    ]*/}.toString().slice(14,-3);
    Note 1 : This avoids using concatenation for each line :
    var longString2="string part1" + 
    "string part2" 
    or even escaping the new lines :
    var longString2="string part1\
    string part2"
    

    Note 2 :

    ECMA-262 5th Edition section 7.8.4 and called LineContinuation : "A line terminator character cannot appear in a string literal, except as part of a LineContinuation to produce the empty character sequence. The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as \n or \u000A."

    Note 3 :
     "In EcmaScript 6, you'll be able to use backticks for Template Strings, known in the spec as a NoSubstitutionTemplate:
    var htmlString = `Say hello to 
    multi-line
    strings!`;
     "


    (seen on : http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript)