working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,848 snippets matching: flat

    public by JonahM  275571  4  7  4

    Fluid CSS Rows

    I've realised in my coding experience that I need to To allow for space in the div or row tags when using text. Because everything is responsive on a web page, it's a good idea to use these classes. They work really well. Example: http://j.mp/1oilINn
    
    
    .strip-md{
    	padding-top:80px;
    	padding-bottom:80px;
    	position:relative;
    	overflow:hidden;
    }
    
    .strip-sm{
    	padding-top:30px;
    	padding-bottom:30px;
    }
    
    

    public by sTiLL-iLL @ SniPitz-KND  181407  1  7  10

    "flatten" your complex arrays

    a flattening Array helper function
    // go flat yerself!
    
    function flatten(arrayToFlatten, rslt) {
        rslt = rslt || [];
        arrayToFlatten.forEach(function(itm) {
            if (Array.isArray(itm)){
                rslt = flatten(itm, rslt);
            }
            else {
                rslt.push(itm);
            }
        });
        return rslt;
    }
    
    // use it...
    
    var someArrayData = [[60, 121, 4, 832],[71, 188, 6, 33]];
    
    // [60, 121, 4, 832, 71, 188, 6, 33]
    
    console.log(flatten(someArrayData));            

    public by JonahM  4701  1  6  2

    Sublime - Flat UI Theme Predawn

    https://github.com/jamiewilson/predawn
    {
      "theme": "predawn.sublime-theme",
      "color_scheme": "Packages/Predawn/predawn.tmTheme"
    }
    
    # Really decent flat theme for Submlime text:
    # https://github.com/jamiewilson/predawn

    public by lbottaro  7205  40  8  2

    Using Pickle to Save Objects in Python - String Serialization

    You can use the pickle module to save data in a serialized format, typically in a txt string, performing what is better known as data serialization, marshalling, or flattening. Pickle allows you to save an object to a file for later retrieval. Pickling some data will write the python object (dictionary, list, tuple, class) as one long strea
    import pickle 
    
    # The data to save
    myDict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
    # The object to pickle
    object_pi = myDict 
    # The file where to write the serialized string
    file_pi = open('filename_pi.obj', 'w')
    # Dump the data as string to file 
    pickle.dump(object_pi, file_pi)
    file_pi.close()

    public by msdn  1336  0  6  0

    GetActivityData: Converts the collection of activity data items into a flat array.

    Converts the collection of activity data items into a flat array. The activity supplying data items. An array containing activity item names and their values or a null reference if the specified activity doesn't contain any data items.
    /// <summary>
    /// Converts the collection of activity data items into a flat array.
    /// </summary>
    /// <param name="activity">The activity supplying data items.</param>
    /// <returns>An array containing activity item names and their values or a null reference if the specified activity doesn't contain any data items.</returns>
    public static object[] GetActivityData(ActivityBase activity)
    {
        Guard.ArgumentNotNull(activity, "activity");
    
        IDictionary<string, object> activityData = activity.ActivityData;
    
        if (activityData != null)
        {
            ArrayList props = new ArrayList(activityData.Count * 2);
    
            foreach (KeyValuePair<string, object> activityItem in activityData)
            {
                props.Add(activityItem.Key);
                props.Add(activityItem.Value);
            }
    
            return props.ToArray();
        }
        else
        {
            return null;
        }
    }

    public by msdn  1807  0  7  0

    FlattenCheckedRows

    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Windows.Forms;
    
    public static string FlattenCheckedRows(this List<DataRow> sender)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        foreach (DataRow row in sender)
        {
            sb.AppendLine(string.Join(",", row.ItemArray));
        }
        return sb.ToString();
    }

    public by msdn  1664  0  7  0

    StringifyProperty: This function takes a string or vector string property value and returns a flattened string representation of it.

    This function takes a string or vector string property value and returns a flattened string representation of it.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    /// <summary>
    /// This function takes a string or vector string property value and returns a flattened string representation of it.
    /// </summary>
    public static string StringifyProperty(object property)
    {
        string propertyString = "";
        if (property != null)
        {
            var vectorProperty = property as IEnumerable<string>;
            if (vectorProperty != null)
            {
                foreach (var prop in vectorProperty)
                {
                    propertyString += prop + "; ";
                }
            }
            else
            {
                propertyString = property.ToString();
            }
        }
        return propertyString;
    }

    external by tjvc  1490763  454  4  0

    Flatten JSON and output as CSV

    Flatten JSON and output as CSV: json2csv.py
    # coding: utf-8
    
    #
    # Flatten JSON and output as CSV
    #
    # Invoke with the path to the JSON file as an argument, e.g.
    #
    #   python json2csv.py data.json
    #
    # Outputs to a CSV file in the working directory
    #
    # JSON flattening function from: http://goo.gl/z0mzsH
    #
    
    from collections import OrderedDict
    import csv
    import json
    import sys
    
    infile = sys.argv[1]
    outfile = open("output.csv", "w")
    
    writer = csv.writer(outfile, delimiter=",")
    
    data = json.load(open(infile), object_pairs_hook=OrderedDict)
    
    # Recursively flatten JSON
    def flatten(structure, key="", path="", flattened=None): 
        if flattened is None:
            flattened = OrderedDict()    
        if type(structure) not in(OrderedDict, list):
            flattened[((path + "_") if path else "") + key] = structure    
        elif isinstance(structure, list):
            for i, item in enumerate(structure):
                flatten(item, "", path + "_" + key, flattened)    
        else:
            for new_key, value in structure.items():
                flatten(value, new_key, path + "_" + key, flattened)    
        return flattened
    
    # Write fields
    fields = []
    for result in data["results"]:
        flattened = flatten(data["results"][0])
        for k, v in flattened.iteritems():
            if k not in fields:
                fields.append(k)
    writer.writerow(fields)
    
    # Write values
    for result in data["results"]:
        flattened = flatten(result)
        row = []
        for field in fields:
            if field in flattened.iterkeys():
                row.append(flattened[field])
            else:
                row.append("")
        writer.writerow(row)
    
    

    external by mikhailov  150  0  2  0

    flatten an array of arbitrarily nested arrays of integers into a flat array of integers (can't use Array#flatten built-in method)

    flatten an array of arbitrarily nested arrays of integers into a flat array of integers (can't use Array#flatten built-in method): flattenizer.rb
    class Flattenizer
    
      def initialize(params)
        if params.empty?
          raise ArgumentError, 'Data set is empty'
        end
        if !params.is_a?(Array)
          raise TypeError, 'Data set is not an array'
        end
        @input_array = params
      end
    
    
      def flatten
        @resulted_array = []
        inner_flatten_loop(@input_array)
        return @resulted_array
      end
    
    
      private
    
      def inner_flatten_loop(inner_array)
        inner_array.each do |i|
          if i.is_a?(Fixnum)
            @resulted_array << i
          elsif i.is_a?(Array)
            inner_flatten_loop(i)
          end
        end
      end
    
    end
    
    
    
    require 'minitest/autorun'
    
    class TestFlattenizer < Minitest::Unit::TestCase
    
      def test_that_array1_flattens
        object = Flattenizer.new([[1,2,[3]],4]).flatten
        assert_equal( [1,2,3,4], object )
      end
    
      def test_that_array2_flattens
        object = Flattenizer.new([[1,2,[3],[[1]]],[1],[[[[3]]]],4]).flatten
        assert_equal( [1,2,3,1,1,3,4], object )
      end
    
      def test_that_array3_flattens
        object = Flattenizer.new([[1,2,[3]],"","bug",4]).flatten
        assert_equal( [1,2,3,4], object )
      end
    
      def test_that_string_doesnt_flatten
        assert_raises( TypeError ) { Flattenizer.new("string not an array") }
      end
    
      def test_that_empty_array_doesnt_flatten
        assert_raises( ArgumentError ) { Flattenizer.new([]) }
      end
    
    end
    
    
    

    external by andela-omesanni  118  0  2  0

    This file contains a flatten function flattens an array of arbitrarily nested arrays of integers into one flat array

    This file contains a flatten function flattens an array of arbitrarily nested arrays of integers into one flat array: flatten.js
    /**
      * Flattens an array of arbitrarily nested arrays of integers into one flat array
      * @param  {Array} arr An array of arbitrarily nested arrays
      * @return {Array}     Flattened array
      */
    function flatten(arr) {
      if(!Array.isArray(arr)) {
        return console.log('Only arrays are allowed');
      }
      
      return arr.reduce(function (flatArr, currentVal) {
        return flatArr.concat(Array.isArray(currentVal) ? flatten(currentVal) : currentVal);
      }, []);
    }
    
    
    
    • Public Snippets
    • Channels Snippets