SnippetVamp

Because spending time searching snippets sucks.



ALV 3 XPath 1 abap 9 ahk 1 autohotkey 6 bash 2 cli 2 clipboard 3 excel 1 file 1 file_path 1 greasemonkey 1 javascript 1 python 4 sap 1 screen 1 sql 1 ssh 1 tool 2 tunnel 1

.

python

Circle through list

class CircleList(list):
    """A list to circle throught""" # itertools.circle only goes one way
    def __init__(self, l, i=0, stop=None):
        super(CircleList, self).__init__(l)
        self.i = i
        self.stop = stop
    def current(self):
        return self[self.i]
    def previous(self):
        self.i -= 1
        if self.i < 0:
            self.i = 0 if self.stop else len(self)-1
        return self[self.i]
    def next(self):
        self.i += 1
        if self.i > len(self)-1:
            self.i = len(self)-1 if self.stop else 0
        return self[self.i]

python

<iframe width="100%" height="506" src="http://ginkobox.fr/vamp/index.php?embed=55c51d182921a" type="text/html"></iframe>

Text only - Permalink - Snippet public post date 07/08/2015

Translate clipboard content on Windows unsing Google Translate

#!/bin/python
# -*- coding: utf-8 -*-

"""Translate clipboard content on Windows unsing Google Translate"""

# Author : Ginko
# Date : 08/01/2015
# Version : 0.1.a
# License : zlib/libpng

# The zlib/libpng License

# Copyright (c) 2015 Ginko Aloe - ginkobox.fr

# This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
# Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
#     1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
#     2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
#     3. This notice may not be removed or altered from any source distribution.

# goslate module from http://pythonhosted.org/goslate/
# Clip object inspired from https://stackoverflow.com/a/25678113

# Example usage (from cmd.exe): C:\pathTo\python.exe C:\path\to\translate.py en

import ctypes, sys
import goslate

class Clip(object):
    def __init__(self):
        
        self.wcscpy = ctypes.cdll.msvcrt.wcscpy

        self.OpenClipboard = ctypes.windll.user32.OpenClipboard
        self.EmptyClipboard = ctypes.windll.user32.EmptyClipboard
        self.GetClipboardData = ctypes.windll.user32.GetClipboardData
        self.SetClipboardData = ctypes.windll.user32.SetClipboardData
        self.CloseClipboard = ctypes.windll.user32.CloseClipboard
        self.CF_UNICODETEXT = 13

        self.GlobalAlloc = ctypes.windll.kernel32.GlobalAlloc
        self.GlobalLock = ctypes.windll.kernel32.GlobalLock
        self.GlobalUnlock = ctypes.windll.kernel32.GlobalUnlock
        self.GMEM_DDESHARE = 0x2000 

    def get(self):
        self.OpenClipboard(None)
        handle = self.GetClipboardData(self.CF_UNICODETEXT)
        data = ctypes.c_wchar_p(handle).value
        pcontents = self.GlobalLock(handle)
        data = ctypes.c_wchar_p(pcontents).value if pcontents else u''
        self.GlobalUnlock(handle)
        self.CloseClipboard()
        return data

    def put(self, data):
        # if not isinstance(data, unicode):
            # data = data.decode('mbcs')
        self.OpenClipboard(None)
        self.EmptyClipboard()
        hCd = self.GlobalAlloc(self.GMEM_DDESHARE, 2 * (len(data) + 1))
        pchData = self.GlobalLock(hCd)
        self.wcscpy(ctypes.c_wchar_p(pchData), data)
        self.GlobalUnlock(hCd)
        self.SetClipboardData(self.CF_UNICODETEXT, hCd)
        self.CloseClipboard()
    
def main():
    clip = Clip()
    gs = goslate.Goslate()
    lang = sys.argv[1] if len(sys.argv) > 1 else 'fr'
    c = gs.translate(clip.get(), lang)
    clip.put(c)

if __name__ == "__main__":
    main()

clipboard python

<iframe width="100%" height="1550" src="http://ginkobox.fr/vamp/index.php?embed=54aec9f2a1d9d" type="text/html"></iframe>

Text only - Permalink - Snippet public post date 08/01/2015

fastRename, a tiny tiny tool to replace spaces in file names by other strings

#!/usr/bin/python
# -*- encoding:utf-8 -*-

"""fastRename, a tiny tiny tool to replace strings in file names by other strings"""

# Author : Ginko
# Date : 02/01/2015
# Version : 0.1.a
# License : zlib/libpng

# The zlib/libpng License

# Copyright (c) 2015 Ginko Aloe - ginkobox.fr

# This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
# Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
#     1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
#     2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
#     3. This notice may not be removed or altered from any source distribution.

import os, sys

if len(sys.argv) < 4:
    print("***{}***\n\nUsage: {} <from> <to> filenames ...".format(__doc__, sys.argv[0]))
else:
    for f in sys.argv[2:]:
        os.rename(f, f.replace(sys.argv[1], sys.argv[2]))

cli file python tool

<iframe width="100%" height="668" src="http://ginkobox.fr/vamp/index.php?embed=54a70f58f3451" type="text/html"></iframe>

Text only - Permalink - Snippet public post date 02/01/2015

pix0meter

#!/usr/bin/python
# -*- encoding:utf-8 -*-

"""pixOmeter, a tiny tool to calculate sizes in mm and px and definition in dpi"""

# Author : Ginko
# Date : 31/12/2014
# Version : 0.1.a
# License : zlib/libpng

# The zlib/libpng License

# Copyright (c) 2014 Ginko Aloe - ginkobox.fr

# This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
# Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
#     1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
#     2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
#     3. This notice may not be removed or altered from any source distribution.

ISO_formats = {'A0': (841, 1189), # from https://en.wikipedia.org/wiki/ISO_216
'B0': (1000, 1414), 
'A1': (594, 841), 
'B1': (707, 1000), 
'A2': (420, 594), 
'B2': (500, 707), 
'A3': (297, 420), 
'B3': (353, 500), 
'A4': (210, 297), 
'B4': (250, 353), 
'A5': (148, 210), 
'B5': (176, 250), 
'A6': (105, 148), 
'B6': (125, 176), 
'A7': (74, 105), 
'B7': (88, 125), 
'A8': (52, 74), 
'B8': (62, 88), 
'A9': (37, 52), 
'B9': (44, 62), 
'A10': (26, 37), 
'B10': (31, 44), 
'C0': (917, 1297), 
'C1': (648, 917), 
'C2': (458, 648), 
'C3': (324, 458), 
'C4': (229, 324), 
'C5': (162, 229), 
'C6': (114, 162), 
'C7/6': (81, 162), 
'C7': (81, 114), 
'C8': (57, 81), 
'C9': (40, 57), 
'C10': (28, 40), 
'DL': (110, 220) }

class Dimension(object):
    def __init__(self, size=0, definition=0, pixel=0):
        if definition:
            self.definition = definition
        if size and definition:
            self.size = size
            self.pixel = self.definition * self.size / 25.4 # def in inch to def in mm
        elif definition and pixel:
            self.pixel = pixel
            self.size = self.pixel / self.definition * 25.4
        elif size and pixel:
            self.size = size; self.pixel = pixel
            self.definition = self.pixel / self.size * 25.4
    def __str__(self):
        return("{size}mm @ {definition:.0f}dpi = {pixel:.0f}px".format(**self.__dict__))

def iso(_format, definition):
    if _format not in ISO_formats.keys():
        print("Unknow ISO format")
    else:
        l, w = ISO_formats[_format]
        L = Dimension(l, definition)
        W = Dimension(w, definition)
        print("{format}: {L.size} x {W.size} mm @ {definition:.0f}dpi = {L.pixel:.0f} x {W.pixel:.0f} px".format(
            format=_format,
            L=L,
            W=W,
            definition=definition))

def main():
    DEFAULT_DEF = 200
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("-i", "--iso", help="Paper size ISO format, -l for complete list", dest="format")
    parser.add_argument("-l", "--list", help="List of supported ISO formats", action='store_true')
    parser.add_argument("-s", "--size", help="Size in millimeters", dest="size", type=float)
    parser.add_argument("-d", "--definition", help="Definition in dpi", dest="definition", type=int)
    parser.add_argument("-p", "--pixel", help="Size in pixel", dest="pixel", type=int)
    args = parser.parse_args()
    if args.list:
        for k, (w, l) in sorted(ISO_formats.items()): print("{}: {} x {}".format(k, w, l))
    if args.format:
        if not args.definition:
            print("Default definition used: {}dpi".format(DEFAULT_DEF))
            iso(args.format, DEFAULT_DEF)
        else:
            iso(args.format, args.definition)
    else:
        defined = [i for i in (args.size, args.definition, args.pixel) if i]
        if len(defined) < 2:
            print("Missing arguments")
        elif len(defined) > 2:
            print("Too many arguments")
        else:
            print(Dimension(args.size, args.definition, args.pixel))

if __name__ == '__main__':
    main()

cli python tool

<iframe width="100%" height="2234" src="http://ginkobox.fr/vamp/index.php?embed=54a34acf4e8dc" type="text/html"></iframe>

Text only - Permalink - Snippet public post date 31/12/2014

This page's Feed


SnippetVamp 1.84 by Bronco - generated in 0.01 s