Export csv file from array

By Ankit Doshi

I am using below code for export multidimensional array.
I have below problems with my code so any one please look at it or help me out.
I am using codeigniter framework(2.1.0 Version)

Problems :

  1. I have no any double quotes/single quotes in array but in csv file some fields have doble quotes.

  2. Each and every csv file give me first two line blanks then contents i can see

CODE :

function array_to_csv($array, $download = "")
    {
        if ($download != "")
        {   
            header('Content-Type: text/csv');
            header('Content-Disposition: attachement; filename="' . $download . '"');
            header("Pragma: no-cache");
            header("Expires: 0");
        }       

        ob_start();
        $f = fopen('php://output', 'w') or show_error("Can't open php://output");
        $n = 0;     
        foreach ($array as $line)
        {
        $line = str_replace('"', '', $line); //Try to resolve first problem but it doesn't work for me.
            $n++;
            if ( ! fputcsv($f, $line))
            {
                show_error("Can't write line $n: $line");
            }
        }
        fclose($f) or show_error("Can't close php://output");
        $str = ob_get_contents();
        ob_end_clean();

        if ($download == "")
        {
            return $str;    
        }
        else
        {   
            echo $str;
        }       
    }

Source: Stack Overflow

    

Create GUI UI at GameObject position

By shell

I want to create a GUI UI at the position of a GameObject, specifically this example menu:

http://docs.unity3d.com/Manual/gui-Basics.html

I’ve tried this:

new Rect (playerPosX, playerPosY, 100, 90)

as the first argument using gameObject.transform.position.x and y but the GUI is top-left based.

How do I do this?

Source: Stack Overflow

    

webpack importing exports unnecessarily

By archytect

new to webpack and es6 modules,

I have two simple functions, one for square the other for drag, I’m only trying to export and import square. why does diag get added into the bundle at all? isn’t the point to only load what’s needed?

test.js

function square(x) {
    return x * x;
}

function diag(x, y) {
    return sqrt(square(x) + square(y));
}

export { square }

index.js

import { square } from './test';

webpack

webpack
Hash: 9a7d113bc9fb07b1955e
Version: webpack 1.13.1
Time: 494ms
         Asset     Size  Chunks             Chunk Names
pages/index.js  1.74 kB       0  [emitted]  pages/index
    + 2 hidden modules

cat public/pages/index*
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _test = __webpack_require__(1);

/***/ },
/* 1 */
/***/ function(module, exports) {

	"use strict";

	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
	function square(x) {
	    return x * x;
	}

	function diag(x, y) {
	    return sqrt(square(x) + square(y));
	}

	exports.square = square;

/***/ }
/******/ ]);

webpack.config.js

cat webpack.config.js

module.exports = {
	entry: {
		'pages/index': './src/pages/index.js'
	},
	output: {
		path: './public',
		filename: '[name].js'
	},
	module: {
		loaders: [
			{
				test: /.js/,
				loader: 'babel',
				query: { 
					presets: ['es2015']
				}
			}
		],	
	}
};

Source: Stack Overflow

    

How to correctly take out text from an element and destroy the element?

By Zulhilmi Zainudin

JSFIDDLE

I’ve a paragraph tag with 2 (can be more) highlight tags inside it.

What I want to do now is, when I click the button, I want the highlight tag that contains ‘removable’ text to be destroyed and replace with plain text of ‘removable’ without the highlight tag and all data-* attributes.

HTML:

<p>
  <highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class=&quot;btn edit_annotation&quot; data-id=&quot;1464586442243&quot;>Edit</button>&amp;nbsp;<button class=&quot;btn delete_annotation&quot; data-id=&quot;1464586442243&quot;>Delete</button>"
  id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1
  <highlight class="highlight" data-id="1464586450092" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>second</p><button class=&quot;btn edit_annotation&quot; data-id=&quot;1464586450092&quot;>Edit</button>&amp;nbsp;<button class=&quot;btn delete_annotation&quot; data-id=&quot;1464586450092&quot;>Delete</button>"
  id="anchor_1464586450092" data-original-title="" title="">removable</highlight> true</p>
<button id="remove" type="button">Remove</button>

JS:

$(function() {
  $('#remove').click(function() {
    // i stuck here
  });
});

EXPECTED RESULT:

<p>
  <highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class=&quot;btn edit_annotation&quot; data-id=&quot;1464586442243&quot;>Edit</button>&amp;nbsp;<button class=&quot;btn delete_annotation&quot; data-id=&quot;1464586442243&quot;>Delete</button>" id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1 removable true
</p>

How to do it? I tried using .contents().unwrap() like mentioned here but it didn’t work for me.

This is my current result after using .contents().unwrap():

<p><highlight class="highlight" data-id="1464586442243" data-container="body" data-toggle="popover" data-placement="right" data-content="<p>first</p><button class=&quot;btn edit_annotation&quot; data-id=&quot;1464586442243&quot;>Edit</button>&amp;nbsp;<button class=&quot;btn delete_annotation&quot; data-id=&quot;1464586442243&quot;>Delete</button>" id="anchor_1464586442243" data-original-title="" title="">Section</highlight> 1 remov<highlight></highlight>able true</p>

Source: Stack Overflow