List presets

    \b
    Usage:
        $ be preset ls
        - ad
        - game
        - film
356405
def preset_ls(remote):
    

    if self.isactive():
        lib.echo("ERROR: Exit current project first")
        sys.exit(lib.USER_ERROR)

    if remote:
        presets = _extern.github_presets()
    else:
        presets = _extern.local_presets()

    if not presets:
        lib.echo("No presets found")
        sys.exit(lib.NORMAL)
    for preset in sorted(presets):
        lib.echo("- %s" % preset)
    sys.exit(lib.NORMAL)
152690
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$inputValue, $namedParameters,
                     $placement )
    {
        if ( !$this->ImageGDSupported )
        {
            eZDebug::writeError( "$operatorName cannot be used since the following ImageGD functions are missing: " . implode( ', ', $this->MissingGDFunctions ) );
            return;
        }

        if ( $operatorName == 'texttoimage' )
        {
            $class = $namedParameters['class'];

            $family = $this->Family;
            $size = $this->PointSize;
            $angle = $this->Angle;
            $xadj = $this->XAdjust;
            $yadj = $this->YAdjust;
            $wadj = $this->WAdjust;
            $hadj = $this->HAdjust;
            $usecache = $this->UseCache;
            $bgcol = $this->color( "bgcolor" );
            $textcol = $this->color( "textcolor" );

            $ini = eZINI::instance( 'texttoimage.ini' );
            $family = $ini->variable( 'DefaultSettings', 'Family' );
            $size = $ini->variable( 'DefaultSettings', 'PointSize' );
            $angle = $ini->variable( 'DefaultSettings', 'Angle' );
            $xadj = $ini->variable( 'DefaultSettings', 'XAdjustment' );
            $yadj = $ini->variable( 'DefaultSettings', 'YAdjustment' );
            $wadj = $ini->variable( 'DefaultSettings', 'WidthAdjustment' );
            $hadj = $ini->variable( 'DefaultSettings', 'HeightAdjustment' );
            $bgcol = $this->decodeColor( $ini->variable( 'DefaultSettings', 'BackgroundColor' ) );
            $textcol = $this->decodeColor( $ini->variable( 'DefaultSettings', 'TextColor' ) );

            $absoluteWidth = false;
            $absoluteHeight = false;

            if ( $ini->hasVariable( $class, 'Family' ) )
                $family = $ini->variable( $class, 'Family' );
            if ( $ini->hasVariable( $class, 'PointSize' ) )
                $size = $ini->variable( $class, 'PointSize' );
            if ( $ini->hasVariable( $class, 'Angle' ) )
                $angle = $ini->variable( $class, 'Angle' );
            if ( $ini->hasVariable( $class, 'XAdjustment' ) )
                $xadj = $ini->variable( $class, 'XAdjustment' );
            if ( $ini->hasVariable( $class, 'YAdjustment' ) )
                $yadj = $ini->variable( $class, 'YAdjustment' );
            if ( $ini->hasVariable( $class, 'WidthAdjustment' ) )
                $wadj = $ini->variable( $class, 'WidthAdjustment' );
            if ( $ini->hasVariable( $class, 'HeightAdjustment' ) )
                $hadj = $ini->variable( $class, 'HeightAdjustment' );
            if ( $ini->hasVariable( $class, 'BackgroundColor' ) )
                $bgcol = $this->decodeColor( $ini->variable( $class, 'BackgroundColor' ) );
            if ( $ini->hasVariable( $class, 'TextColor' ) )
                $textcol = $this->decodeColor( $ini->variable( $class, 'TextColor' ) );
            if ( $ini->hasVariable( $class, 'AbsoluteWidth' ) )
                $absoluteWidth = $ini->variable( $class, 'AbsoluteWidth' );
            if ( $ini->hasVariable( $class, 'AbsoluteHeight' ) )
                $absoluteHeight = $ini->variable( $class, 'AbsoluteHeight' );

            if ( $namedParameters['family'] !== null )
                $family = $namedParameters["family"];
            if ( $namedParameters["pointsize"] !== null )
                $size = $namedParameters["pointsize"];
            if ( $namedParameters["angle"] !== null )
                $angle = $namedParameters["angle"];
            if ( $namedParameters["x"] !== null )
                $xadj = $namedParameters["x"];
            if ( $namedParameters["y"] !== null )
                $yadj = $namedParameters["y"];
            if ( $namedParameters["w"] !== null )
                $wadj = $namedParameters["w"];
            if ( $namedParameters["h"] !== null )
                $hadj = $namedParameters["h"];
            if ( $namedParameters["usecache"] !== null )
                $usecache = $namedParameters["usecache"];
            if ( $namedParameters["bgcolor"] !== null )
                $bgcol = $this->decodeColor( $namedParameters["bgcolor"] );
            if ( $namedParameters["textcolor"] !== null )
                $textcol = $this->decodeColor( $namedParameters["textcolor"] );
            $storeImage = $namedParameters["storeimage"];

            $fontDir = false;
            foreach ( $this->FontDir as $fontPath )
            {
                if ( eZImageFont::exists( $family, $fontPath ) )
                {
                    $fontDir = $fontPath;
                    break;
                }
            }
            if ( !$fontDir )
                return;
            $font = new eZImageFont( $family, $size, $fontDir, $xadj, $yadj );

            if ( $bgcol === null )
                $bgcol = $this->color( "bgcolor" );
            if ( !is_array( $bgcol ) or
                 count( $bgcol ) < 3 )
                $bgcol = array( 255, 255, 255 );
            if ( $textcol === null )
                $textcol = $this->color( "textcolor" );
            if ( !is_array( $textcol ) or
                 count( $textcol ) < 3 )
                $textcol = array( 0, 0, 0 );

            $alternativeText = htmlspecialchars( $inputValue );
            if ( is_string( $usecache ) )
                $md5Text = $usecache;
            else
                $md5Text = md5( $inputValue . $family . $size . $angle . $xadj . $yadj . $wadj . $hadj . $absoluteWidth . $absoluteHeight . implode( ",", $bgcol ) . implode( ",", $textcol ) );
            if ( is_string( $usecache ) or !$usecache or
                 !$this->hasImage( $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs ) )
            {
                $layer = eZImageTextLayer::createForText( $inputValue, $font,
                                                           $wadj, $hadj, $angle,
                                                           $absoluteWidth, $absoluteHeight );
                if ( !$layer )
                {
                    $tpl->error( $operatorName, "Could not open font \"$family\", no image created", $placement );
                    return;
                }
                $layer->allocateColor( 'bgcol', $bgcol[0], $bgcol[1], $bgcol[2] );
                $layer->allocateColor( 'textcol', $textcol[0], $textcol[1], $textcol[2] );
                $layer->setTextColor( 'textcol' );

                if ( $storeImage )
                    $this->storeImage( $layer, $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs );
                $layer->destroy();
            }
            else
            {
                $layer = $this->loadImage( $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs );
            }
            $layer->setAlternativeText( $alternativeText );
            $inputValue = $layer;
        }

        else if ( $operatorName == 'image' )
        {
            $useCache = $this->UseCache;
            $image = new eZImageObject();
            $md5Input = "image\n";
            $alternativeText = '';
            $this->readImageParameters( $tpl, $image, $operatorParameters, $rootNamespace, $currentNamespace, $md5Input, $alternativeText,
                                        $placement );
            $image->setAlternativeText( $alternativeText );
            $md5Text = md5( $md5Input );
            if ( !$useCache or
                 !$this->hasImage( $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs ) )
            {
                $this->storeImage( $image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs );
                $image->destroy();
                $inputValue = $image;
            }
            else
            {
                $this->setLoadImage( $image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs );
                $image->load();
                $inputValue = $image;
            }
        }
        else if ( $operatorName == 'imagefile' )
        {
            $file =& $namedParameters['filename'];
            $options =& $namedParameters['options'];
            $dir = '';
            if ( preg_match( "#^(.+)/([^/]+)$#", $file, $matches ) )
            {
                $dir = $matches[1];
                $file = $matches[2];
            }

            $layer = eZImageLayer::createForFile( $file, $dir );
            $alternativeText = $file;
            if ( preg_match( "#(.+)\.([^.]+)$#", $file, $matches ) )
                $alternativeText = $matches[1];
            $layer->setAlternativeText( $alternativeText );
            $inputValue = $layer;
        }
    }
1257200
def displayformat(codes=[], fg=None, bg=None):
        """"""
        if isinstance(codes, basestring):
            codes = [codes]
        else:
            codes = list(codes)
        for code in codes:
            if code not in Magic.DISPLAY.keys():
                raise ValueError("'%s' not a valid display value" % code)
        for color in (fg, bg):
            if color != None:
                if color not in Magic.COLORS.keys():
                    raise ValueError("'%s' not a valid color" % color)
        return [codes, fg, bg]
477549
def _bsd_brshow(br=None):
    '''
    
    '''
    if __grains__['kernel'] == 'NetBSD':
        return _netbsd_brshow(br)

    ifconfig = _tool_path('ifconfig')

    ifaces = {}

    if br:
        ifaces[br] = br
    else:
        cmd = '{0} -g bridge'.format(ifconfig)
        for line in __salt__['cmd.run'](cmd, python_shell=False).splitlines():
            ifaces[line] = line

    brs = {}

    for iface in ifaces:
        cmd = '{0} {1}'.format(ifconfig, iface)
        for line in __salt__['cmd.run'](cmd, python_shell=False).splitlines():
            brs[iface] = {
                'interfaces': [],
                'stp': 'no'
            }
            line = line.lstrip()
            if line.startswith('member:'):
                brs[iface]['interfaces'].append(line.split(' ')[1])
                if 'STP' in line:
                    brs[iface]['stp'] = 'yes'

    if br:
        return brs[br]
    return brs
956898
function parse_PtgName(blob, length, opts) {
	var type = (blob.read_shift(1) >>> 5) & 0x03;
	var w = (!opts || (opts.biff >= 8)) ? 4 : 2;
	var nameindex = blob.read_shift(w);
	switch(opts.biff) {
		case 2: blob.l += 5; break;
		case 3: case 4: blob.l += 8; break;
		case 5: blob.l += 12; break;
	}
	return [type, 0, nameindex];
}
948762
function B(iid, op, left, right, flags) {
        var bFlags = decodeBitPattern(flags, 3); // [isComputed, isOpAssign, isSwitchCaseComparison]
        var result, aret, skip = false;

        if (sandbox.analysis && sandbox.analysis.binaryPre) {
            aret = sandbox.analysis.binaryPre(iid, op, left, right, bFlags[1], bFlags[2], bFlags[0]);
            if (aret) {
                op = aret.op;
                left = aret.left;
                right = aret.right;
                skip = aret.skip;
            }
        }


        if (!skip) {
            switch (op) {
                case "+":
                    result = left + right;
                    break;
                case "-":
                    result = left - right;
                    break;
                case "*":
                    result = left * right;
                    break;
                case "/":
                    result = left / right;
                    break;
                case "%":
                    result = left % right;
                    break;
                case "<<":
                    result = left << right;
                    break;
                case ">>":
                    result = left >> right;
                    break;
                case ">>>":
                    result = left >>> right;
                    break;
                case "<":
                    result = left < right;
                    break;
                case ">":
                    result = left > right;
                    break;
                case "<=":
                    result = left <= right;
                    break;
                case ">=":
                    result = left >= right;
                    break;
                case "==":
                    result = left == right;
                    break;
                case "!=":
                    result = left != right;
                    break;
                case "===":
                    result = left === right;
                    break;
                case "!==":
                    result = left !== right;
                    break;
                case "&":
                    result = left & right;
                    break;
                case "|":
                    result = left | right;
                    break;
                case "^":
                    result = left ^ right;
                    break;
                case "delete":
                    result = delete left[right];
                    break;
                case "instanceof":
                    result = left instanceof right;
                    break;
                case "in":
                    result = left in right;
                    break;
                default:
                    throw new Error(op + " at " + iid + " not found");
                    break;
            }
        }

        if (sandbox.analysis && sandbox.analysis.binary) {
            aret = sandbox.analysis.binary(iid, op, left, right, result, bFlags[1], bFlags[2], bFlags[0]);
            if (aret) {
                result = aret.result;
            }
        }
        return (lastComputedValue = result);
    }
75407
public void setVbucketlist(short[] vbs) {
    int oldSize = (vblist.length + 1) * 2;
    int newSize = (vbs.length + 1) * 2;
    totalbody += newSize - oldSize;
    vblist = vbs;
  }
1234481
def s2b(s):
    
    ret = []
    for c in s:
        ret.append(bin(ord(c))[2:].zfill(8))
    return "".join(ret)
89485
def modify_usage_error(subcommand, program_list):
    
    import click
    from click._compat import get_text_stderr
    from click.utils import echo

    def show(self, file=None):
        import sys
        if file is None:
            file = get_text_stderr()
        color = None
        if self.ctx is not None:
            color = self.ctx.color
        echo('Error: %s\n' % self.format_message(), file=file, color=color)
        # Set the sys.argv to be the first two arguments passed to the script if the subcommand was specified
        arg2 = sys.argv[1] if sys.argv[1] in program_list else str()
        sys.argv = [' '.join([sys.argv[0], arg2])] if arg2 else [sys.argv[0]]
        # Call the help
        subcommand(['--help'])

    click.exceptions.UsageError.show = show
230862
function applyPresets(scope, defaults, presets) {
        if (!scope || !presets) { return; }

        // presets come from either scope (i.e. passed in directly) or get from the ui part presets
        var opts = scope.presets || (scope.item && scope.item.type && presets[scope.item.type]) || presets[scope.preset] ||
            (scope.preset && presets[scope.type + '.' + scope.preset]) || presets[scope.type];
        if (!opts) { return; }

        for (var name in opts) {
            if (opts.hasOwnProperty(name)) {
                if (!defaults || defaults[name] === undefined) {
                    throw new Error('No defaults value for ' + name + ' but in options.' + scope.preset);
                }
                else {
                    scope[name] = opts[name];
                }
            }
        }
    }
431054
def cli(ctx):
    """"""
    click.secho("\n v%s\n" % .__version__, bg="blue", fg="white", bold=True)
1036
def RRlist2bitmap(lst):
    
    # RFC 4034, 4.1.2. The Type Bit Maps Field

    import math

    bitmap = b""
    lst = [abs(x) for x in sorted(set(lst)) if x <= 65535]

    # number of window blocks
    max_window_blocks = int(math.ceil(lst[-1] / 256.))
    min_window_blocks = int(math.floor(lst[0] / 256.))
    if min_window_blocks == max_window_blocks:
        max_window_blocks += 1

    for wb in range(min_window_blocks, max_window_blocks + 1):
        # First, filter out RR not encoded in the current window block
        # i.e. keep everything between 256*wb <= 256*(wb+1)
        rrlist = sorted(x for x in lst if 256 * wb <= x < 256 * (wb + 1))
        if not rrlist:
            continue

        # Compute the number of bytes used to store the bitmap
        if rrlist[-1] == 0:  # only one element in the list
            bytes_count = 1
        else:
            max = rrlist[-1] - 256 * wb
            bytes_count = int(math.ceil(max // 8)) + 1  # use at least 1 byte
        if bytes_count > 32:  # Don't encode more than 256 bits / values
            bytes_count = 32

        bitmap += struct.pack("BB", wb, bytes_count)

        # Generate the bitmap
        # The idea is to remove out of range Resource Records with these steps
        # 1. rescale to fit into 8 bits
        # 2. x gives the bit position ; compute the corresponding value
        # 3. sum everything
        bitmap += b"".join(
            struct.pack(
                b"B",
                sum(2 ** (7 - (x - 256 * wb) + (tmp * 8)) for x in rrlist
                    if 256 * wb + 8 * tmp <= x < 256 * wb + 8 * tmp + 8),
            ) for tmp in range(bytes_count)
        )

    return bitmap
1119477
function beforeAddItem(Sb $sb, A $item) {
		df_state()->attributeSet($item);
		try {$item['frontend_label'] = (string)__($item['frontend_label']);}
		finally {df_state()->attributeUnset();}
		return [$item];
	}
1230310
function validateBemDecl(bemDecl, fileName) {
  let errors = [];

  bemDecl.forEach((decl) => {
    errors = errors.concat(validateBemDeclItem(decl, fileName));
  });

  return errors;
}
825326
def _embedded_frames(frame_list, frame_format):
    """"""
    template = '  frames[{0}] = "data:image/{1};base64,{2}"\n'
    embedded = "\n"
    for i, frame_data in enumerate(frame_list):
        embedded += template.format(i, frame_format,
                                    frame_data.replace('\n', '\\\n'))
    return embedded
749959
def RRlist2bitmap(lst):
    
    # RFC 4034, 4.1.2. The Type Bit Maps Field

    import math

    bitmap = b""
    lst = list(set(lst))
    lst.sort()
    
    #lst = filter(lambda x: x <= 65535, lst)
    #lst = map(lambda x: abs(x), lst)
    lst = [ abs(x) for x in lst if x<= 65535 ]

    # number of window blocks
    max_window_blocks = int(math.ceil(lst[-1] / 256.))
    min_window_blocks = int(math.floor(lst[0] / 256.))
    if min_window_blocks == max_window_blocks:
        max_window_blocks += 1

    for wb in range(min_window_blocks, max_window_blocks+1):
        # First, filter out RR not encoded in the current window block
        # i.e. keep everything between 256*wb <= 256*(wb+1)
        #rrlist = filter(lambda x: 256*wb <= x and x < 256*(wb+1), lst)
        rrlist = [ x for x in lst if 256*wb <= x and x < 256*(wb+1) ]
        rrlist.sort()
        if rrlist == []:
            continue
     
        # Compute the number of bytes used to store the bitmap
        if rrlist[-1] == 0: # only one element in the list
            bs = 1
        else:
            max = rrlist[-1] - 256*wb
            #bs = int(math.ceil(max / 8)) + 1  # use at least 1 byte
            bs = int(max // 8) + 1  # use at least 1 byte
        if bs > 32: # Don't encode more than 256 bits / values
            bs = 32

        bitmap += struct.pack("B", wb)
        bitmap += struct.pack("B", bs)

        # Generate the bitmap
        for tmp in range(bs):
            v = 0
            # Remove out of range Ressource Records
            #tmp_rrlist = filter(lambda x: 256*wb+8*tmp <= x and x < 256*wb+8*tmp+8, rrlist)
            tmp_rrlist = [ x for x in rrlist if 256*wb+8*tmp <= x and x < 256*wb+8*tmp+8 ]
            if not tmp_rrlist == []:
                # 1. rescale to fit into 8 bits
                tmp_rrlist = map(lambda x: (x-256*wb)-(tmp*8), tmp_rrlist)
                # 2. x gives the bit position ; compute the corresponding value
                tmp_rrlist = map(lambda x: 2**(7-x) , tmp_rrlist)
                # 3. sum everything
                #v = reduce(lambda x,y: x+y, tmp_rrlist)
                v = sum(tmp_rrlist)
            bitmap += struct.pack("B", v)
   
    return bitmap
127226
def cmd_ls(self, *args):
        
        cmd_str = ' '.join(['ls'] + list(args))
        self.plugin.exec_shell(cmd_str)