答: I had the same issue and after some searching found this solution which has you remove all shortcuts from your Windows Desktop. Apparently the installer chokes on these for some reason. Worked like a charm.

Title: HotSpot Virtual Machine error on Oracle Installation

Body:
I am trying to Install Oracle 11G on Windows Xp 64 bit. The installer shows the progress bar for checking prerequisites and then crashes.

The log file is as below.
What can I do to solve the issue?

#

An unexpected error has been detected by HotSpot Virtual Machine:

#

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077d64e95,

pid=3580, tid=2860
  #

Java VM: Java HotSpot(TM) 64-Bit Server VM (1.5.0_17-b04 mixed mode)

Problematic frame:

C  [kernel32.dll+0x24e95]

#

---------------  T H R E A D  ---------------

Current thread (0x0000000001ba0740):
  JavaThread "AWT-EventQueue-0"
  [_thread_in_native, id=2860]

siginfo: ExceptionCode=0xc0000005,
  reading address 0x000000007f366f48

Registers: EAX=0x0000000000000000,
  EBX=0x000000007f366f48,
  ECX=0xffffffffffffffff,
  EDX=0x0000000000000104
  ESP=0x000000000776de70,
  EBP=0x0000000000000000,
  ESI=0x00000000000004e4,
  EDI=0x000000007f366f48
  EIP=0x0000000077d64e95,
  EFLAGS=0x0000000000010246

Top of Stack: (sp=0x000000000776de70)
  0x000000000776de70:   0000000000000006
  0000000000000000 0x000000000776de80:

  0000000000000000 0000000000000020
  0x000000000776de90:   0000000000000005
  00000000001956b0 0x000000000776dea0:

  0000000010020200 00000000080b95e6
  0x000000000776deb0:   0000000020a9c058
  0000000077efb1e9 0x000000000776dec0:

  0000000000000000 0000000077c4ef3d
  0x000000000776ded0:   0000ebe94f6aad20
  0000000001ba0740 0x000000000776dee0:

  000000000776e388 000000001257ad50
  0x000000000776def0:   0000000001e9cba1
  0000000020a9c340 0x000000000776df00:

  000000000000006d 000000000776e348
  0x000000000776df10:   000000001257ad50
  0000000006cbd5f9 0x000000000776df20:

  000000000776dfe8 000000000776e0a8
  0x000000000776df30:   0000000000000000
  000007ff7f1e4273 0x000000000776df40:

  000000000776e080 0000000000000104
  0x000000000776df50:   0000ebe94f6aad20
  00000000001956b0 0x000000000776df60:

  000000000016a090 000000000776dfe8

Instructions: (pc=0x0000000077d64e95)
  0x0000000077d64e85:   ff 33 c0 48 b9
  ff ff ff ff ff ff ff ff 48 8b fb
  0x0000000077d64e95:   f2 ae 48 f7 d1
  44 8b e9 e9 1e 86 00 00 90 90 90

Stack:
  [0x0000000007670000,0x0000000007770000),
  sp=0x000000000776de70,  free
  space=1015k Native frames: (J=compiled
  Java code, j=interpreted, Vv=VM code,
  C=native code) C
  [kernel32.dll+0x24e95]

[error occurred during error
  reporting, step 120, id 0xc0000005]

Java frames: (J=compiled Java code,
  j=interpreted, Vv=VM code) j
  sun.awt.shell.Win32ShellFolder2.getLinkLocation(JJZ)J+0
  j
  sun.awt.shell.Win32ShellFolder2.getLinkLocation(Z)Lsun/awt/shell/ShellFolder;+20
  j
  sun.awt.shell.Win32ShellFolder2.isDirectory()Z+69
  j
  sun.awt.shell.Win32ShellFolder2.isDirectory()Z+79
  j
  sun.awt.shell.Win32ShellFolderManager2.get(Ljava/lang/String;)Ljava/lang/Object;+156
  j
  sun.awt.shell.ShellFolder.get(Ljava/lang/String;)Ljava/lang/Object;+4
  j
  oracle.bali.ewt.olaf2.OracleFileChooserUI.installComponents(Ljavax/swing/JFileChooser;)V+794
  j
  javax.swing.plaf.basic.BasicFileChooserUI.installUI(Ljavax/swing/JComponent;)V+47
  j
  oracle.bali.ewt.olaf2.OracleFileChooserUI.installUI(Ljavax/swing/JComponent;)V+2
  j
  javax.swing.JComponent.setUI(Ljavax/swing/plaf/ComponentUI;)V+42
  j
  javax.swing.JFileChooser.updateUI()V+40
  j
  javax.swing.JFileChooser.setup(Ljavax/swing/filechooser/FileSystemView;)V+73
  j
  javax.swing.JFileChooser.(Ljava/io/File;Ljavax/swing/filechooser/FileSystemView;)V+133
  j
  javax.swing.JFileChooser.()V+9 j
  oracle.install.commons.swing.XmlBeanStoreFileChooser.()V+1
  j
  oracle.install.commons.base.summary.SummaryPane.buildUI()V+25
  j
  oracle.install.commons.base.summary.SummaryPane.()V+35
  j
  oracle.install.commons.base.interview.common.view.SummaryGUI.()V+9
  v  ~StubRoutines::call_stub j
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Ljava/lang/reflect/Constructor;[Ljava/lang/Object;)Ljava/lang/Object;+0
  j
  sun.reflect.NativeConstructorAccessorImpl.newInstance([Ljava/lang/Object;)Ljava/lang/Object;+72
  j
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance([Ljava/lang/Object;)Ljava/lang/Object;+5
  j
  java.lang.reflect.Constructor.newInstance([Ljava/lang/Object;)Ljava/lang/Object;+92
  j
  java.lang.Class.newInstance0()Ljava/lang/Object;+118
  j
  java.lang.Class.newInstance()Ljava/lang/Object;+15
  j
  oracle.install.commons.flow.ViewManager.getView(Ljava/lang/String;)Loracle/install/commons/flow/View;+72
  j
  oracle.install.commons.flow.State.getView()Loracle/install/commons/flow/View;+19
  j
  oracle.install.commons.flow.AbstractFlowExecutor.loadView(Loracle/install/commons/util/Graph;)V+20
  j
  oracle.install.commons.flow.AbstractGraphicalFlowExecutor.access$001(Loracle/install/commons/flow/AbstractGraphicalFlowExecutor;Loracle/install/commons/util/Graph;)V+2
  j
  oracle.install.commons.flow.AbstractGraphicalFlowExecutor$1.call()Ljava/lang/Void;+8
  j
  oracle.install.commons.flow.AbstractGraphicalFlowExecutor$1.call()Ljava/lang/Object;+1
  j
  java.util.concurrent.FutureTask$Sync.innerRun()V+22
  j
  java.util.concurrent.FutureTask.run()V+4
  j
  java.awt.event.InvocationEvent.dispatch()V+47
  j
  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+26
  j
  java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+233
  j
  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
  j
  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
  j
  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
  j
  java.awt.EventDispatchThread.run()V+9
  v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )

  0x0000000001ba0490 JavaThread "Image
  Fetcher 0" daemon [_thread_blocked,
  id=3088]   0x0000000001ba1cc0
  JavaThread "TimerQueue" daemon
  [_thread_blocked, id=3252]

  0x0000000001ba1a10 JavaThread
  "pool-1-thread-1" [_thread_blocked,
  id=4912]   0x0000000001b9e700
  JavaThread "DestroyJavaVM"
  [_thread_blocked, id=3504]

  0x0000000001ba1760 JavaThread "Worker
  3" daemon [_thread_blocked, id=3660]

  0x0000000001ba14b0 JavaThread "Worker
  2" daemon [_thread_blocked, id=3720]

  0x0000000001ba1200 JavaThread "Worker
  1" daemon [_thread_blocked, id=1936]

  0x0000000001ba0f50 JavaThread "Worker
  0" daemon [_thread_blocked, id=4016]
  =>0x0000000001ba0740 JavaThread "AWT-EventQueue-0" [_thread_in_native,
  id=2860]   0x0000000001b9f720
  JavaThread "AWT-Shutdown"
  [_thread_blocked, id=2276]

  0x0000000001b9ff30 JavaThread "Java2D
  Disposer" daemon [_thread_blocked,
  id=4064]   0x0000000001b9f9d0
  JavaThread "AWT-Windows" daemon
  [_thread_in_native, id=2376]

  0x0000000001b9f1c0 JavaThread "Low
  Memory Detector" daemon
  [_thread_blocked, id=1764]

  0x000000000557f720 JavaThread
  "CompilerThread1" daemon
  [_thread_blocked, id=4204]

  0x000000000557f450 JavaThread
  "CompilerThread0" daemon
  [_thread_blocked, id=3604]

  0x000000000557f180 JavaThread
  "AdapterThread" daemon
  [_thread_blocked, id=1976]

  0x0000000001b9ef10 JavaThread "Signal
  Dispatcher" daemon [_thread_blocked,
  id=2296]   0x0000000001b9ec60
  JavaThread "Finalizer" daemon
  [_thread_blocked, id=3608]

  0x0000000001b9e9b0 JavaThread
  "Reference Handler" daemon
  [_thread_blocked, id=2012]

Other Threads:   0x0000000001b8d980
  VMThread [id=4856]

  0x0000000001b8daa0 WatcherThread
  [id=1224]

VM state:not at safepoint (normal
  execution)

VM Mutex/Monitor currently owned by a
  thread: None

Heap  PSYoungGen      total 62592K,
  used 56702K [0x000000001d410000,
  0x0000000021410000,
  0x0000000021410000)   eden space
  59648K, 93% used
  [0x000000001d410000,0x0000000020aab7d8,0x0000000020e50000)
  from space 2944K, 26% used
  [0x0000000020e50000,0x0000000020f140c0,0x0000000021130000)
  to   space 2880K, 0% used
  [0x0000000021140000,0x0000000021140000,0x0000000021410000)
  PSOldGen        total 12800K, used
  9744K [0x0000000015410000,
  0x0000000016090000,
  0x000000001d410000)   object space
  12800K, 76% used
  [0x0000000015410000,0x0000000015d94300,0x0000000016090000)
  PSPermGen       total 54016K, used
  38334K [0x0000000010010000,
  0x00000000134d0000,
  0x0000000015410000)   object space
  54016K, 70% used
  [0x0000000010010000,0x000000001257f820,0x00000000134d0000)

Dynamic libraries: 0x0000000000400000
  - 0x0000000000412000  C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\javaw.exe
  0x0000000077ec0000 -
  0x0000000077ff9000
    C:\WINDOWS\system32\ntdll.dll
  0x0000000077d40000 -
  0x0000000077eb3000
    C:\WINDOWS\system32\kernel32.dll
  0x000007ff7fee0000 -
  0x000007ff7ffe5000
    C:\WINDOWS\system32\ADVAPI32.dll
  0x000007ff7fd30000 -
  0x000007ff7fec9000
    C:\WINDOWS\system32\RPCRT4.dll
  0x000007ff7e9c0000 -
  0x000007ff7e9e2000
    C:\WINDOWS\system32\Secur32.dll
  0x0000000077c20000 -
  0x0000000077d2c000
    C:\WINDOWS\system32\USER32.dll
  0x000007ff7fc90000 -
  0x000007ff7fd2b000
    C:\WINDOWS\system32\GDI32.dll
  0x000007ff7fc00000 -
  0x000007ff7fc86000
    C:\WINDOWS\system32\msvcrt.dll
  0x0000000180000000 -
  0x00000001800f3000
    c:\progra~1\quickh~1\quickh~2\wl_hoo~1.dll
  0x000007ff7f190000 -
  0x000007ff7fb9a000
    C:\WINDOWS\system32\SHELL32.dll
  0x000007ff7ef60000 -
  0x000007ff7effb000
    C:\WINDOWS\system32\SHLWAPI.dll
  0x000007ff7f000000 -
  0x000007ff7f187000
    C:\WINDOWS\WinSxS\amd64_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.3790.3959_x-ww_0A7B2435\comctl32.dll 0x0000000008000000 -
  0x0000000008561000
    C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\server\jvm.dll 0x000007ff7e240000 -
  0x000007ff7e290000
    C:\WINDOWS\system32\WINMM.dll
  0x0000000010000000 -
  0x000000001000b000
    C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\hpi.dll
  0x000007ff7e380000 -
  0x000007ff7e390000
    C:\WINDOWS\system32\PSAPI.DLL
  0x00000000003d0000 -
  0x00000000003e1000
    C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\verify.dll
  0x0000000001e40000 -
  0x0000000001e6c000
    C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\java.dll 0x0000000001e70000 -
  0x0000000001e86000
    C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\zip.dll
  0x0000000006b50000 -
  0x0000000006d6b000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\awt.dll
  0x000007ff78f10000 -
  0x000007ff78f51000
    C:\WINDOWS\system32\WINSPOOL.DRV
  0x000007ff7d500000 -
  0x000007ff7d539000
    C:\WINDOWS\system32\IMM32.dll
  0x000007ff57140000 -
  0x000007ff573c5000
    C:\WINDOWS\system32\ole32.dll
  0x000007ff77230000 -
  0x000007ff772af000
    C:\WINDOWS\system32\uxtheme.dll
  0x000007ff79190000 -
  0x000007ff79202000
    C:\WINDOWS\system32\ddraw.dll
  0x000007ff793e0000 -
  0x000007ff793e8000
    C:\WINDOWS\system32\DCIMAN32.dll
  0x000007ff7a410000 -
  0x000007ff7a4af000
    C:\WINDOWS\system32\MSCTF.dll
  0x0000000007430000 -
  0x00000000074aa000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\fontmanager.dll
  0x00000000075b0000 -
  0x00000000075cb000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\net.dll
  0x000007ff77310000 -
  0x000007ff77340000
    C:\WINDOWS\system32\WS2_32.dll
  0x000007ff77140000 -
  0x000007ff7714c000
    C:\WINDOWS\system32\WS2HELP.dll
  0x0000000007650000 -
  0x000000000765c000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\nio.dll
  0x0000000007770000 -
  0x00000000077ad000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64\oraInstaller.dll
  0x000007ff7fbf0000 -
  0x000007ff7fbfb000
    C:\WINDOWS\system32\VERSION.dll
  0x0000000078000000 -
  0x0000000078060000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64\msvcrt.dll
  0x000007ff771b0000 -
  0x000007ff7722d000
    C:\WINDOWS\System32\mswsock.dll
  0x000007ff7e8f0000 -
  0x000007ff7e93e000
    C:\WINDOWS\system32\DNSAPI.dll
  0x000007ff7e9f0000 -
  0x000007ff7e9fb000
    C:\WINDOWS\System32\winrnr.dll
  0x000007ff7e950000 -
  0x000007ff7e9b6000
    C:\WINDOWS\system32\WLDAP32.dll
  0x000007ff7ea00000 -
  0x000007ff7ea07000
    C:\WINDOWS\system32\rasadhlp.dll
  0x000007ff57040000 -
  0x000007ff57071000
    C:\WINDOWS\system32\iphlpapi.dll
  0x000007ff7e560000 -
  0x000007ff7e58b000
    C:\WINDOWS\system32\MPRAPI.dll
  0x000007ff7e780000 -
  0x000007ff7e7db000
    C:\WINDOWS\system32\ACTIVEDS.dll
  0x000007ff7e730000 -
  0x000007ff7e770000
    C:\WINDOWS\system32\adsldpc.dll
  0x000007ff77370000 -
  0x000007ff77409000
    C:\WINDOWS\system32\NETAPI32.dll
  0x000007ff7e3a0000 -
  0x000007ff7e3d9000
    C:\WINDOWS\system32\credui.dll
  0x000007ff7e040000 -
  0x000007ff7e05c000
    C:\WINDOWS\system32\ATL.DLL
  0x000007ff7ebc0000 -
  0x000007ff7ecd6000
    C:\WINDOWS\system32\OLEAUT32.dll
  0x000007ff7e610000 -
  0x000007ff7e625000
    C:\WINDOWS\system32\rtutils.dll
  0x000007ff77150000 -
  0x000007ff77166000
    C:\WINDOWS\system32\SAMLIB.dll
  0x000007ff7dac0000 -
  0x000007ff7dc38000
    C:\WINDOWS\system32\SETUPAPI.dll
  0x000007ff6d200000 -
  0x000007ff6d293000
    C:\WINDOWS\system32\hnetcfg.dll
  0x000007ff77170000 -
  0x000007ff7717b000
    C:\WINDOWS\System32\wshtcpip.dll
  0x0000000007970000 -
  0x0000000007977000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64\orauts.dll
  0x0000000007b20000 -
  0x0000000007b2d000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64\orawsec11.dll
  0x0000000078130000 -
  0x00000000781f9000
    C:\WINDOWS\WinSxS\amd64_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4027_x-ww_189D5EB0\MSVCR80.dll 0x0000000007c50000 -
  0x0000000007cf4000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64\orasrvm11.dll
  0x0000000007a90000 -
  0x0000000007abd000    C:\Documents and
  Settings\rrscw\Local
  Settings\Temp\OraInstall2011-03-30_10-02-25AM\jdk\jre\bin\dcpr.dll 0x000007ff76200000 -
  0x000007ff762ef000
    C:\WINDOWS\WinSxS\amd64_Microsoft.Windows.Common-Controls_6595b64144ccf1df_5.82.3790.3959_x-ww_AB06DEB0\comctl32.dll 0x000007ff772d0000 -
  0x000007ff772f1000
    C:\WINDOWS\system32\MPR.dll
  0x000007ff7ccc0000 -
  0x000007ff7ccca000
    C:\WINDOWS\System32\drprov.dll
  0x000007ff649f0000 -
  0x000007ff64a06000
    C:\WINDOWS\System32\ntlanman.dll
  0x000007ff65140000 -
  0x000007ff65164000
    C:\WINDOWS\System32\NETUI0.dll
  0x000007ff650e0000 -
  0x000007ff65138000
    C:\WINDOWS\System32\NETUI1.dll
  0x000007ff7ceb0000 -
  0x000007ff7cebd000
    C:\WINDOWS\System32\davclnt.dll
  0x000007ff7ce50000 -
  0x000007ff7ce91000
    C:\WINDOWS\system32\apphelp.dll
  0x000007ff7ea10000 -
  0x000007ff7eaee000
    C:\WINDOWS\system32\CLBCatQ.DLL
  0x000007ff7eaf0000 -
  0x000007ff7ebb6000
    C:\WINDOWS\system32\COMRes.dll
  0x000007ff7df70000 -
  0x000007ff7df7c000
    C:\WINDOWS\system32\LINKINFO.dll
  0x000007ff7df80000 -
  0x000007ff7dfb1000
    C:\WINDOWS\system32\ntshrui.dll

VM Arguments: jvm_args:
  -Doracle.installer.library_loc=C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\oui\lib\win64
  -Doracle.installer.oui_loc=C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\oui
  -Doracle.installer.bootstrap=TRUE -Doracle.installer.startup_location=I:\Setups\Oracle\database\install
  -Doracle.installer.jre_loc=C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM\jdk/jre
  -Doracle.installer.exec_location=I:\Setups\Oracle\database\install\oui.exe
  -Doracle.installer.nlsEnabled=TRUE -Doracle.installer.prereqConfigLoc= -Xmx192m java_command: oracle.install.ivw.db.driver.DBInstaller
  -scratchPath C:\DOCUME~1\rrscw\LOCALS~1\Temp\OraInstall2011-03-30_10-02-25AM
  -sourceLoc I:\Setups\Oracle\database\install../stage/products.xml
  -sourceType network -timestamp 2011-03-30_10-02-25AM Launcher Type:
  SUN_STANDARD

Environment Variables:
  PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program
  Files (x86)\Common Files\Roxio
  Shared\DLLShared\;C:\Program Files
  (x86)\Common Files\Roxio
  Shared\10.0\DLLShared\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program
  Files (x86)\Microsoft SQL
  Server\100\Tools\Binn\;C:\Program
  Files (x86)\Microsoft SQL
  Server\100\DTS\Binn\;C:\Program
  Files\R\R-2.12.2\library\rscproxy\libs\i386;C:\Program
  Files\R\R-2.12.2\bin\i386;C:\Program
  Files (x86)\Microsoft SQL
  Server\100\Tools\Binn\VSShell\Common7\IDE\
  USERNAME=rrscw OS=Windows_NT
  PROCESSOR_IDENTIFIER=EM64T Family 6
  Model 26 Stepping 5, GenuineIntel

---------------  S Y S T E M  ---------------

OS: Windows XP 64bit Build 3790
  Service Pack 2

CPU:total 4 em64t ht

Memory: 4k page, physical
  6273948k(4849464k free), swap
  7972228k(7161264k free)

vm_info: Java HotSpot(TM) 64-Bit
  Server VM (1.5.0_17-b04) for
  windows-amd64, built on Nov 10 2008
  01:04:27 by "java_re" with unknown MS
  VC++:1400


来源: stackexchange

问:
How to serialize data to a given file using ujson library in python
I am using below code to generate json file.

```<code>f = open("test.txt", 'r')
buffer = f.readlines()
rec_cnt = 1
with open("test.json", "w") as ujson_file:
for line in buffer:
    data_dict[rec_cnt] = {line}
    if rec_cnt == 100:
        ujson.dump(data_dict.values(), ujson_file)
        data_dict.clear()
rec_cnt +=1
f.close()
ujson_file
</code>```

The issue is whenever I do it by batch, each batch of records are enclosed with [], which is forming an invalid json file.

for example
Input file will be

```<code> fruits      Orange       Apple        Kiwi        Banana     Veggies     Tomato       Potatoe      Carrot      Peas       Bigfruits   WaterMelon   cantaloupes  Papaya      melon
</code>```

output file should be:

```<code>[{Key:fruits, Values: [Orange, Apple, Kiwi, Banana]}][{Key:Veggies, Values: [Tomato, Potatoe, Carrot, Peas]}][{Key:Bigfruits, Values: [WaterMelon, cantaloupes, Papaya, melon]}]
</code>```

Any suggestions of serializing the data with only one '[]' or without '[]'

答:
data_dict.values() is always going to return a list object, which you are writing directly to ujson_file.

If this is not what you want, try writing data_dict.values()[0] instead. I only see one dictionary per list so I assume this pattern remains consistent.

ContentLicense: CC BY-SA 3.0

Body:
I am using below code to generate json file.

f = open("test.txt", 'r')
buffer = f.readlines()
rec_cnt = 1
with open("test.json", "w") as ujson_file:
for line in buffer:
    data_dict[rec_cnt] = {line}
    if rec_cnt == 100:
        ujson.dump(data_dict.values(), ujson_file)
        data_dict.clear()
rec_cnt +=1
f.close()
ujson_file

The issue is whenever I do it by batch, each batch of records are enclosed with [], which is forming an invalid json file.

for example
Input file will be

 fruits      Orange       Apple        Kiwi        Banana     Veggies     Tomato       Potatoe      Carrot      Peas       Bigfruits   WaterMelon   cantaloupes  Papaya      melon

output file should be:

[{Key:fruits, Values: [Orange, Apple, Kiwi, Banana]}][{Key:Veggies, Values: [Tomato, Potatoe, Carrot, Peas]}][{Key:Bigfruits, Values: [WaterMelon, cantaloupes, Papaya, melon]}]

Any suggestions of serializing the data with only one '[]' or without '[]'


问:
CSS/html center text next to floated number
I have a list of items with a number and text stacked ontop of each other - I am struggling with trying to vertically align the text next to the number it is sitting along side. I have the number and text just floated left inside a div - possibly I need to take a different approach? See working exmaple here - https://codepen.io/ajmajma/pen/gRpxrQ?editors=1100

My html for the items is structured like so :

```<code>  <div class="featured-posts wrapper">
  <div class="featured-posts--posts row">
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">1</span><a href="/blog/1">10 Tips to Avoid Dry Flaky Winter Skin, Safely</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">2</span><a href="/blog/2">10 Ways to Spa at Home</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">3</span><a href="/blog/3">13 Healthy Ways Winterize Your Routine</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">4</span><a href="/blog/4">18 Things to Love About Our Follain Soap</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">5</span><a href="/blog/5"><3 at First Site</a></div>
      </div>
    </div>
  </div>
</div>
</code>```

And the CSS (SCSS) looks like so :

```<code>.featured-posts {
   counter-reset: section;

   .featured-posts--posts {
     .featured-post {
       margin-bottom: 40px;
       width: 100%;

       .featured-post--wrapper {
         margin: 0 auto;
       }

       .featured-post--count {
         width: 45px;
         float: left;
         color: red;
         height: 100%;
         display: block;
          font-size: 30px;
       }

       .featured-post--body {
         width: 350px;
         max-width: 100%;
         margin: 0 auto;
         color: black;

         a {
           cursor: pointer;
           text-decoration: none;
           color: black;
           transition: color 0.2s ease-in;

           &:hover {
             color: red;
           }
         }
       }
     }
   }
 }
</code>```

I am trying to have so no matter what length the text is - it is vertically aligned against the "Count" (the left number). Any input would be welcome! Thanks.

答:
I would use display: flex; align-items: center; on the parent

.wrapper {
  margin: 0 auto;
  max-width: 600px;
}

.featured-posts {
  counter-reset: section;
}
.featured-posts .featured-posts--posts .featured-post {
  margin-bottom: 40px;
  width: 100%;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--wrapper {
  margin: 0 auto;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--count {
  width: 45px;
  color: red;
  height: 100%;
  display: block;
  font-size: 30px;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body {
  width: 350px;
  max-width: 100%;
  margin: 0 auto;
  color: black;
  display: flex;
  align-items: center;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a {
  cursor: pointer;
  text-decoration: none;
  color: black;
  transition: color 0.2s ease-in;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a:hover {
  color: red;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="featured-posts wrapper">
  <div class="featured-posts--posts row">
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">1</span>10 Tips to Avoid Dry Flaky Winter Skin, Safely</div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">2</span>10 Ways to Spa at Home</div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">3</span>13 Healthy Ways Winterize Your Routine</div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">4</span>18 Things to Love About Our Follain Soap</div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">5</span><3 at First Site</div>
      </div>
    </div>
  </div>
</div></code>```

Body:
I have a list of items with a number and text stacked ontop of each other - I am struggling with trying to vertically align the text next to the number it is sitting along side. I have the number and text just floated left inside a div - possibly I need to take a different approach? See working exmaple here - https://codepen.io/ajmajma/pen/gRpxrQ?editors=1100

My html for the items is structured like so :

110 Tips to Avoid Dry Flaky Winter Skin, Safely

210 Ways to Spa at Home

313 Healthy Ways Winterize Your Routine

418 Things to Love About Our Follain Soap

5<3 at First Site

And the CSS (SCSS) looks like so :

.featured-posts {
   counter-reset: section;

   .featured-posts--posts {
     .featured-post {
       margin-bottom: 40px;
       width: 100%;

       .featured-post--wrapper {
         margin: 0 auto;
       }

       .featured-post--count {
         width: 45px;
         float: left;
         color: red;
         height: 100%;
         display: block;
          font-size: 30px;
       }

       .featured-post--body {
         width: 350px;
         max-width: 100%;
         margin: 0 auto;
         color: black;

         a {
           cursor: pointer;
           text-decoration: none;
           color: black;
           transition: color 0.2s ease-in;

           &:hover {
             color: red;
           }
         }
       }
     }
   }
 }

I am trying to have so no matter what length the text is - it is vertically aligned against the "Count" (the left number). Any input would be welcome! Thanks.

Body:
I would use display: flex; align-items: center; on the parent

.wrapper {
  margin: 0 auto;
  max-width: 600px;
}

.featured-posts {
  counter-reset: section;
}
.featured-posts .featured-posts--posts .featured-post {
  margin-bottom: 40px;
  width: 100%;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--wrapper {
  margin: 0 auto;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--count {
  width: 45px;
  color: red;
  height: 100%;
  display: block;
  font-size: 30px;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body {
  width: 350px;
  max-width: 100%;
  margin: 0 auto;
  color: black;
  display: flex;
  align-items: center;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a {
  cursor: pointer;
  text-decoration: none;
  color: black;
  transition: color 0.2s ease-in;
}
.featured-posts .featured-posts--posts .featured-post .featured-post--body a:hover {
  color: red;
}

<div class="featured-posts wrapper">
  <div class="featured-posts--posts row">
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">1</span><a href="/blog/1">10 Tips to Avoid Dry Flaky Winter Skin, Safely</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">2</span><a href="/blog/2">10 Ways to Spa at Home</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">3</span><a href="/blog/3">13 Healthy Ways Winterize Your Routine</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">4</span><a href="/blog/4">18 Things to Love About Our Follain Soap</a></div>
      </div>
    </div>
    <div class="featured-post col-12">
      <div class="featured-post--wrapper">
        <div class="featured-post--body"><span class="featured-post--count">5</span><a href="/blog/5">&lt;3 at First Site</a></div>
      </div>
    </div>
  </div>
</div>


问:
DNS name from IP address
I need to create a list of IP addresses and DNS names. I
   am trying to get DNS names from IP addresses. I have tried two ways:

try/catch but it ends afterwards.

Without and it just outputs DNS names that I can't relate to the IP addresses.

Here's what I have so far:

```<code>#try {
 Get-Content C:\Users\pintose\Documents\IP_Address.txt | ForEach-Object
{([system.net.dns]::GetHostByAddress($_)).hostname >> C:\Users\user\Documents\hostname.txt}
# }
 # catch {
 if ($_.Exception.Message -like "*The requested name is valid*") {
            Write-Output "UNREACHABLE" | Out-File C:\Users\user\Documents\hostname.txt }
# }
</code>```

答:
This uses a workflow so it can do parallel foreach</p>

```<code>Workflow Get-DNSNames([string[]]$IPAddresses){
    foreach -parallel ($IP in $IPAddresses){
        try{
            @{$IP = $(([system.net.dns]::GetHostByAddress($IP)).hostname)}
        }catch{
            @{$IP = "N/A"}
        }
    }
}

$List = Get-DNSNames -IPAddresses $(Get-Content "C:\IPAddresses.txt").Split("[\r\n]")
$List | Out-File "C:\IPAddresses_Complete.txt"
</code>```

Title: DNS name from IP address

Body:
I need to create a list of IP addresses and DNS names. I
   am trying to get DNS names from IP addresses. I have tried two ways:

try/catch but it ends afterwards.

Without and it just outputs DNS names that I can't relate to the IP addresses.

Here's what I have so far:

#try {
 Get-Content C:\Users\pintose\Documents\IP_Address.txt | ForEach-Object
{([system.net.dns]::GetHostByAddress($_)).hostname >> C:\Users\user\Documents\hostname.txt}
# }
 # catch {
 if ($_.Exception.Message -like "*The requested name is valid*") {
            Write-Output "UNREACHABLE" | Out-File C:\Users\user\Documents\hostname.txt }
# }

Body:
This uses a workflow so it can do parallel foreach

Workflow Get-DNSNames([string[]]$IPAddresses){
    foreach -parallel ($IP in $IPAddresses){
        try{
            @{$IP = $(([system.net.dns]::GetHostByAddress($IP)).hostname)}
        }catch{
            @{$IP = "N/A"}
        }
    }
}

$List = Get-DNSNames -IPAddresses $(Get-Content "C:\IPAddresses.txt").Split("[\r\n]")
$List | Out-File "C:\IPAddresses_Complete.txt"


问:
typescript definitions for officejs v1.1
Is there anyway we could find the type definitions for the office js api v.1.1 to be used in javascript. There is one available here but it seems to be for the latest version (yes 1.1 is quite different in some places as compared to the latest version).</p>

答:
So, its not that the api's are different. In some of the methods i noticed few parameters were skipped and it still worked which lead me to think the APIs might be different (in future versions).

Example, in Office.body both these seem to work.

```<code>getAsync(coercionType, options, callback)
getAsync(coercionType, callback)
</code>```

Body:
So, its not that the api's are different. In some of the methods i noticed few parameters were skipped and it still worked which lead me to think the APIs might be different (in future versions).

Example, in Office.body both these seem to work.

getAsync(coercionType, options, callback)
getAsync(coercionType, callback)


问:
How to query search numbers in php mysql
I need a search query.
Age value 10 - 15 , 20 - 25 , 17 - 19 , 12 - 59 , 2 - 19 , 18 - 40 , 10 - 20

I send 10 - 25 and I want to get results by matching the numbers

```<code><?php
  $Age1 = 10;
  $Age2 = 25;

  $Age = $Age1." - ".$Age2;

  $stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age LIKE '%" . $Age .  "%'");

?>
</code>```

Thanks to All

答:
You should use the BETWEEN operator, it selects values within a given range.

Example:

```<code>$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");
</code>```

Body:
I need a search query.
Age value 10 - 15 , 20 - 25 , 17 - 19 , 12 - 59 , 2 - 19 , 18 - 40 , 10 - 20

I send 10 - 25 and I want to get results by matching the numbers

<?php
  $Age1 = 10;
  $Age2 = 25;

  $Age = $Age1." - ".$Age2;

  $stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age LIKE '%" . $Age .  "%'");

?>

Thanks to All

Body:
You should use the BETWEEN operator, it selects values within a given range.

Example:

$stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age BETWEEN 10 AND 25");


问:
Gradient from actionbar in to tabs
I've googled for hours trying to find an answer to this seemingly obvious question but I can't even find another example of someone trying to do this. Is it possible to have a gradient extend from an Android actionbar down in to tabs as per the mock up below.

Creating the gradient in the actionbar or the tabs is straightforward but a continuous gradient currently escapes me

as requested here is the gradient xml

```<code><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="135"
        android:endColor="@color/colorPrimary"
        android:startColor="@color/colorAccent" />
</shape>
</code>```

I've built the tabs like this but I haven't included any attempt at a gradient here as everything I have tried is so terrible its not worth posting. The closest I came was recreating the gradient but thats rubbish

```<code><?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:myapp="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/item_menu_ok"
          android:icon="@drawable/ic_action_ok"
          android:title="@string/ok"
          myapp:showAsAction="ifRoom"></item>
    <item android:id="@+id/item_menu_cancel"
          android:icon="@drawable/ic_action_cancel"
          android:title="@string/cancel"
          myapp:showAsAction="ifRoom"></item>
   <item android:id="@+id/item_menu_third"
          android:icon="@drawable/ic_action_third"
          android:title="@string/third"
          myapp:showAsAction="ifRoom"></item>
</menu>
</code>```

答:
You might consider ditching ActionBar for the more modern ToolBar

That would enable you to make the TabLayout a child of the Toolbar view, make it transparent and set the gradient as a background for Toolbar

Other reasons for switching over to using Toolbar are discussed in "Should we replace Action Bar by ToolBar?"

Title: Gradient from actionbar in to tabs

Body:
I've googled for hours trying to find an answer to this seemingly obvious question but I can't even find another example of someone trying to do this. Is it possible to have a gradient extend from an Android actionbar down in to tabs as per the mock up below.

Creating the gradient in the actionbar or the tabs is straightforward but a continuous gradient currently escapes me

as requested here is the gradient xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="135"
        android:endColor="@color/colorPrimary"
        android:startColor="@color/colorAccent" />
</shape>

I've built the tabs like this but I haven't included any attempt at a gradient here as everything I have tried is so terrible its not worth posting. The closest I came was recreating the gradient but thats rubbish

<?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:myapp="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/item_menu_ok"
          android:icon="@drawable/ic_action_ok"
          android:title="@string/ok"
          myapp:showAsAction="ifRoom"></item>
    <item android:id="@+id/item_menu_cancel"
          android:icon="@drawable/ic_action_cancel"
          android:title="@string/cancel"
          myapp:showAsAction="ifRoom"></item>
   <item android:id="@+id/item_menu_third"
          android:icon="@drawable/ic_action_third"
          android:title="@string/third"
          myapp:showAsAction="ifRoom"></item>
</menu>


问:
AJAX on Load command for a Liquid code
I wanted to add a onClick function when I click on the link.
Basically, whenever I click on "Click" it should add the liquid code in the div.
What it is doing is, adding a liquid code yes, but just the code and not the content it should be adding with the liquid code. Here is my code:

Index

```<code>    <a href="#" id="myLink">Click me!</a>
    <div id="result"></div>

    <script src="http://code.jquery.com/jquery-latest.min.js"

type="text/javascript"></script>
    <script>
      $("#myLink").on("click", function(){
        $("#result").load("liquidcode.html");
      });
    </script>
</code>```

liquidcode.html

```<code>{% include 'cod-checker' %}
</code>```

What I get after clicking on "Click Me" is this {% include 'cod-checker' %}

答: Liquid is rendered server-side so you will not be able to render liquid after the page loads using jquery.  You can circumvent this issue by inserting whatever code resides in 'liquidcode.html' from the very beginning, but hiding it by adding a class to the div with display set to none.  You can then remove that class when the user clicks on "Click". </p>

Title: AJAX on Load command for a Liquid code

Body:
I wanted to add a onClick function when I click on the link.
Basically, whenever I click on "Click" it should add the liquid code in the div.
What it is doing is, adding a liquid code yes, but just the code and not the content it should be adding with the liquid code. Here is my code:

Index

    Click me!

liquidcode.html

{% include 'cod-checker' %}

What I get after clicking on "Click Me" is this {% include 'cod-checker' %}


问:
Converting Facebook post ID from String to int
I am making a news feed where I retrieve Facebook posts from a specific Facebook page. I retrieve those posts with help of the Facebook Graph API. I have a FeedItem which has an ID (int). The ID is also used to check which item is at the current position (Recyclerview).

The problem is that Facebook gives the posts a String ID. I have no idea how I can possibly convert this so that it will work with my application.

My Adapter:

```<code>public class FeedListAdapter extends RecyclerView.Adapter<FeedListAdapter.ViewHolder> {

private ImageLoader imageLoader = AppController.getInstance().getImageLoader();
private List<FeedItem> mFeedItems;
private Context mContext;

public FeedListAdapter(List<FeedItem> pFeedItems, Context pContext) {
    this.mFeedItems = pFeedItems;
    this.mContext = pContext;
}

/* Create methods for further adapter use.*/
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
    View feedView = LayoutInflater.from(parent.getContext())
                                  .inflate(R.layout.feed_item, parent, false);
    return new ViewHolder(feedView);
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.populateRow(getFeedItem(position));
}

@Override
public long getItemId(int position) {
    return mFeedItems.get(position).getId();
}

@Override
public int getItemCount() {
    return mFeedItems.size();
}

private FeedItem getFeedItem(int position) {
    return mFeedItems.get(position);
}

class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {

    private ImageView mProfilePic;
    private TextView mName;
    private TextView mTimestamp;
    private TextView mTxtStatusMsg;
    private FeedImageView mFeedImage;

    //initialize the variables
    ViewHolder(View view) {
        super(view);
        mProfilePic = (ImageView) view.findViewById(R.id.feedProfilePic);
        mName = (TextView) view.findViewById(R.id.feedName);
        mTimestamp = (TextView) view.findViewById(R.id.feedTimestamp);
        mTxtStatusMsg = (TextView) view.findViewById(R.id.feedStatusMessage);
        mFeedImage = (FeedImageView) view.findViewById(R.id.feedImage);
        view.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

    }

    private void populateRow(FeedItem pFeedItem) {
        getProfilePic(pFeedItem);

        mName.setText(pFeedItem.getName());

        mTimestamp.setText(pFeedItem.getTimeStamp());

        mTxtStatusMsg.setText(pFeedItem.getStatus());

        getStatusImg(pFeedItem);
    }

    private void getProfilePic(FeedItem pFeedItem) {
        imageLoader.get(pFeedItem.getProfilePic(), new ImageListener() {
            @Override
            public void onResponse(ImageContainer response, boolean arg1) {
                if (response.getBitmap() != null) {
                    // load image into imageview
                    mProfilePic.setImageBitmap(response.getBitmap());
                }
            }

            @Override
            public void onErrorResponse(final VolleyError pVolleyError) {

            }
        });
    }

    private void getStatusImg(FeedItem pFeedItem) {
        if (pFeedItem.getImage() != null) {
            mFeedImage.setImageUrl(pFeedItem.getImage(), imageLoader);
            mFeedImage.setVisibility(View.VISIBLE);
            mFeedImage
                    .setResponseObserver(new FeedImageView.ResponseObserver() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onSuccess() {
                        }
                    });
        } else {
            mFeedImage.setVisibility(View.GONE);
        }
    }
}
</code>```

My FeedFragment:

```<code>public class FeedFragment extends android.support.v4.app.Fragment {

private static final String TAG = FeedFragment.class.getSimpleName();
private FeedListAdapter mListAdapter;
private List<FeedItem> mFeedItems;
private RecyclerView mRecyclerView;
private String FACEBOOKURL = "**URL OF MY FB-POSTDATA**";

// newInstance constructor for creating fragment with arguments
public static FeedFragment newInstance() {
    FeedFragment fragment = new FeedFragment();
    return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout resource file
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_feed, container, false);

    initRecyclerView(view);
    initCache();

    return view;
}

@Override
public void onStart() {
    super.onStart();
}

@Override
public void onResume() {
    super.onResume();
}

private void initRecyclerView(View pView) {
    mRecyclerView = (RecyclerView) pView.findViewById(R.id.fragment_feed_recyclerview);
    LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setHasFixedSize(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRecyclerView.setNestedScrollingEnabled(true);
    }

    mFeedItems = new ArrayList<>();

    mListAdapter = new FeedListAdapter(mFeedItems, getActivity());
    mRecyclerView.setAdapter(mListAdapter);
}

private void initCache() {
    // We first check for cached request
    Cache cache = AppController.getInstance().getRequestQueue().getCache();
    Entry entry = cache.get(FACEBOOKURL);
    if (entry != null) {
        // fetch the data from cache
        try {
            String data = new String(entry.data, "UTF-8");
            try {
                parseJsonFeed(new JSONObject(data));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    } else {
        // making fresh volley request and getting json
        JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
                FACEBOOKURL, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                VolleyLog.d(TAG, "Response: " + response.toString());
                if (response != null) {
                    parseJsonFeed(response);
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
            }
        });

        // Adding request to volley request queue
        AppController.getInstance().addToRequestQueue(jsonReq);
    }
}
private void parseJsonFeed(JSONObject response) {
    try {
        JSONArray feedArray = response.getJSONArray("data");

        for (int i = 0; i < feedArray.length(); i++) {
            JSONObject feedObj = (JSONObject) feedArray.get(i);

            FeedItem item = new FeedItem();
            item.setId(Integer.parseInt(feedObj.getString("id")));
            item.setName("name of page");

            // Image might be null sometimes
            String image = feedObj.isNull("full_picture") ? null : feedObj
                    .getString("full_picture");
            item.setImage(image);
            // Status message might be null sometimes
            String status = feedObj.isNull("message") ? null : feedObj
                    .getString("message");
            item.setStatus(status);

            item.setProfilePic("**profile picture url**");
            item.setTimeStamp(feedObj.getString("created_time"));

            mFeedItems.add(item);
        }

        // notify data changes to list adapter
        mListAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }
} }
</code>```

As I said; I have no idea how to handle this and I figured someone here would maybe have an idea on how to convert this, so that I can use the String that the graph api gives me, and use it as an integer.

答:
If the value is numeric and you want an integer object, do

```<code>Integer id = Integer.valueOf(facebookId);
</code>```

If you want the primitive type int, then do

```<code>int id = Integer.parseInt(facebookId);
</code>```

or

```<code>int id = Integer.valueOf(facebookId);
</code>```

Body:
I am making a news feed where I retrieve Facebook posts from a specific Facebook page. I retrieve those posts with help of the Facebook Graph API. I have a FeedItem which has an ID (int). The ID is also used to check which item is at the current position (Recyclerview).

The problem is that Facebook gives the posts a String ID. I have no idea how I can possibly convert this so that it will work with my application.

My Adapter:

public class FeedListAdapter extends RecyclerView.Adapter<FeedListAdapter.ViewHolder> {

private ImageLoader imageLoader = AppController.getInstance().getImageLoader();
private List<FeedItem> mFeedItems;
private Context mContext;

public FeedListAdapter(List<FeedItem> pFeedItems, Context pContext) {
    this.mFeedItems = pFeedItems;
    this.mContext = pContext;
}

/* Create methods for further adapter use.*/
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
    View feedView = LayoutInflater.from(parent.getContext())
                                  .inflate(R.layout.feed_item, parent, false);
    return new ViewHolder(feedView);
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.populateRow(getFeedItem(position));
}

@Override
public long getItemId(int position) {
    return mFeedItems.get(position).getId();
}

@Override
public int getItemCount() {
    return mFeedItems.size();
}

private FeedItem getFeedItem(int position) {
    return mFeedItems.get(position);
}

class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {

    private ImageView mProfilePic;
    private TextView mName;
    private TextView mTimestamp;
    private TextView mTxtStatusMsg;
    private FeedImageView mFeedImage;

    //initialize the variables
    ViewHolder(View view) {
        super(view);
        mProfilePic = (ImageView) view.findViewById(R.id.feedProfilePic);
        mName = (TextView) view.findViewById(R.id.feedName);
        mTimestamp = (TextView) view.findViewById(R.id.feedTimestamp);
        mTxtStatusMsg = (TextView) view.findViewById(R.id.feedStatusMessage);
        mFeedImage = (FeedImageView) view.findViewById(R.id.feedImage);
        view.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

    }

    private void populateRow(FeedItem pFeedItem) {
        getProfilePic(pFeedItem);

        mName.setText(pFeedItem.getName());

        mTimestamp.setText(pFeedItem.getTimeStamp());

        mTxtStatusMsg.setText(pFeedItem.getStatus());

        getStatusImg(pFeedItem);
    }

    private void getProfilePic(FeedItem pFeedItem) {
        imageLoader.get(pFeedItem.getProfilePic(), new ImageListener() {
            @Override
            public void onResponse(ImageContainer response, boolean arg1) {
                if (response.getBitmap() != null) {
                    // load image into imageview
                    mProfilePic.setImageBitmap(response.getBitmap());
                }
            }

            @Override
            public void onErrorResponse(final VolleyError pVolleyError) {

            }
        });
    }

    private void getStatusImg(FeedItem pFeedItem) {
        if (pFeedItem.getImage() != null) {
            mFeedImage.setImageUrl(pFeedItem.getImage(), imageLoader);
            mFeedImage.setVisibility(View.VISIBLE);
            mFeedImage
                    .setResponseObserver(new FeedImageView.ResponseObserver() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onSuccess() {
                        }
                    });
        } else {
            mFeedImage.setVisibility(View.GONE);
        }
    }
}

My FeedFragment:

public class FeedFragment extends android.support.v4.app.Fragment {

private static final String TAG = FeedFragment.class.getSimpleName();
private FeedListAdapter mListAdapter;
private List<FeedItem> mFeedItems;
private RecyclerView mRecyclerView;
private String FACEBOOKURL = "**URL OF MY FB-POSTDATA**";

// newInstance constructor for creating fragment with arguments
public static FeedFragment newInstance() {
    FeedFragment fragment = new FeedFragment();
    return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout resource file
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_feed, container, false);

    initRecyclerView(view);
    initCache();

    return view;
}

@Override
public void onStart() {
    super.onStart();
}

@Override
public void onResume() {
    super.onResume();
}

private void initRecyclerView(View pView) {
    mRecyclerView = (RecyclerView) pView.findViewById(R.id.fragment_feed_recyclerview);
    LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setHasFixedSize(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mRecyclerView.setNestedScrollingEnabled(true);
    }

    mFeedItems = new ArrayList<>();

    mListAdapter = new FeedListAdapter(mFeedItems, getActivity());
    mRecyclerView.setAdapter(mListAdapter);
}

private void initCache() {
    // We first check for cached request
    Cache cache = AppController.getInstance().getRequestQueue().getCache();
    Entry entry = cache.get(FACEBOOKURL);
    if (entry != null) {
        // fetch the data from cache
        try {
            String data = new String(entry.data, "UTF-8");
            try {
                parseJsonFeed(new JSONObject(data));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    } else {
        // making fresh volley request and getting json
        JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
                FACEBOOKURL, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                VolleyLog.d(TAG, "Response: " + response.toString());
                if (response != null) {
                    parseJsonFeed(response);
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
            }
        });

        // Adding request to volley request queue
        AppController.getInstance().addToRequestQueue(jsonReq);
    }
}
private void parseJsonFeed(JSONObject response) {
    try {
        JSONArray feedArray = response.getJSONArray("data");

        for (int i = 0; i < feedArray.length(); i++) {
            JSONObject feedObj = (JSONObject) feedArray.get(i);

            FeedItem item = new FeedItem();
            item.setId(Integer.parseInt(feedObj.getString("id")));
            item.setName("name of page");

            // Image might be null sometimes
            String image = feedObj.isNull("full_picture") ? null : feedObj
                    .getString("full_picture");
            item.setImage(image);
            // Status message might be null sometimes
            String status = feedObj.isNull("message") ? null : feedObj
                    .getString("message");
            item.setStatus(status);

            item.setProfilePic("**profile picture url**");
            item.setTimeStamp(feedObj.getString("created_time"));

            mFeedItems.add(item);
        }

        // notify data changes to list adapter
        mListAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }
} }

As I said; I have no idea how to handle this and I figured someone here would maybe have an idea on how to convert this, so that I can use the String that the graph api gives me, and use it as an integer.

Body:
If the value is numeric and you want an integer object, do

Integer id = Integer.valueOf(facebookId);

If you want the primitive type int, then do

int id = Integer.parseInt(facebookId);

or

int id = Integer.valueOf(facebookId);


问:
How to pass parameters to remote shell in jenkins job
I am trying to pass a parameter to remote machine with ssh. I have used ssh plugin to add remote host.

```<code># works for local shell
+ echo sdk
sdk
executing script:
BUILD="sdk"

# doesn't work for remote shell
export BUILD
echo "$BUILD"
BUILD=sdk: Command not found.
export: Command not found.
BUILD: Undefined variable.
[SSH] exit-status: 1
Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE
</code>```

I tried with double quotes, curly braces, export, but with nothing I am able to get the value of the parameter on remote shell. Can someone let me know if I am missing any configuration on jenkins?

答: The issue was with remote machine's default shell. It was tcsh, changed default shell to bash and it resolved the issue.</p>

Body:
I am trying to pass a parameter to remote machine with ssh. I have used ssh plugin to add remote host.

# works for local shell
+ echo sdk
sdk
executing script:
BUILD="sdk"

# doesn't work for remote shell
export BUILD
echo "$BUILD"
BUILD=sdk: Command not found.
export: Command not found.
BUILD: Undefined variable.
[SSH] exit-status: 1
Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE

I tried with double quotes, curly braces, export, but with nothing I am able to get the value of the parameter on remote shell. Can someone let me know if I am missing any configuration on jenkins?


问:
YUI paginator infinity records in table
I am using YUI for displaying data.

This row is used for set count of records per page:

```<code>rowsPerPageOptions : [ 10, 25, 50, 100 ]
</code>```

Does it have ability to set infinity number of records?

答:
Resolved using custom page count names and max int.</p>

```<code>rowsPerPageOptions       : [
                                    { value : 20, text : '20' },
                                    { value : 50, text : '50' },
                                    { value : 100, text : '100' },
                                    { value : 250, text : '250' },
                                    { value : 500, text : '500' },
                                    { value : 1000, text : '1000' },
                                    { value : 9007199254740992, text : 'All' }],
</code>```

ContentLicense: CC BY-SA 2.5

Title: YUI paginator infinity records in table

Body:
I am using YUI for displaying data.

This row is used for set count of records per page:

rowsPerPageOptions : [ 10, 25, 50, 100 ]

Does it have ability to set infinity number of records?

Body:
Resolved using custom page count names and max int.

rowsPerPageOptions       : [
                                    { value : 20, text : '20' },
                                    { value : 50, text : '50' },
                                    { value : 100, text : '100' },
                                    { value : 250, text : '250' },
                                    { value : 500, text : '500' },
                                    { value : 1000, text : '1000' },
                                    { value : 9007199254740992, text : 'All' }],


问:
Javascript Promises recall until acceptable return
ES6

I want to keep calling this method until it returns 0 as the result. Sometimes it takes 5 seconds to return a value, sometimes it takes 10 seconds. Sometimes it doesnt return the value but i want to keep going until it returns 0. It should wait until the answer has come back or timeout in 10 seconds to recall it.

This is how i tried this, but it is not working for some reason.

```<code> function method() {
        doSomething(from_api).then(function (status) {
            if(status != "0") {
                method();
            } else {
                console.log("success");
            }
        }), function (error) {
            method();
        });
}
</code>```

What is the right way to do this?

答:
Your code works. You just had an extra closing parenthesis.
Change:

```<code>}), function (error) {
</code>```

to:

```<code>}, function (error) {
</code>```

Body:
ES6

I want to keep calling this method until it returns 0 as the result. Sometimes it takes 5 seconds to return a value, sometimes it takes 10 seconds. Sometimes it doesnt return the value but i want to keep going until it returns 0. It should wait until the answer has come back or timeout in 10 seconds to recall it.

This is how i tried this, but it is not working for some reason.

 function method() {
        doSomething(from_api).then(function (status) {
            if(status != "0") {
                method();
            } else {
                console.log("success");
            }
        }), function (error) {
            method();
        });
}

What is the right way to do this?

Body:
Your code works. You just had an extra closing parenthesis.
Change:

}), function (error) {

to:

}, function (error) {


问:
shows the value empty even after having value in text field
I have a form where data are fetched from the server and is shown to the text field. Albeit the data is in text field, when i click on save button, i get error on all the fields displaying following fields cannot be empty. Also when i try to change the value, i cant get to type any text neither i can erase the text. Why the value is shown empty when having value over there?</p>

```<code>const mapStateToProps = createStructuredSelector({
  cloudinaryData: selectCloudinary()
});

class Cloudinary extends React.Component {
  state = {
    cloudinary: {
      cloudinary_cloud_name: "",
      cloudinary_api_key: "",
    },
    errors: {}
  };

  componentDidMount() {
    this.props.loadCloudinary();
  }

  handleChange = event => {
    const fieldName = event.target.name;
    this.setState(
      {
        cloudinary: {
          ...this.state.cloudinary,
          [event.target.name]: event.target.value
        }
      },
      () => {
        this.validateField([fieldName]);
      }
    );
  };

  handleSubmit = event => {
    event.preventDefault();
    this.props.requestCloudinary(this.state.cloudinary);
  };

  render() {
    const { cloudinary, errors } = this.state;
    const { cloudinaryData } = this.props;
    if (cloudinaryData.size === 0) {
      return <div>Fetching Data...</div>;
    }
    return (
      <form onSubmit={this.handleSubmit}>
        <TextFieldGroup
          name="cloudinary_cloud_name"
          type="text"
          value={
            cloudinaryData
              ? cloudinaryData.cloudinary_cloud_name
              : cloudinary.cloudinary_cloud_name
          }
          onChange={this.handleChange}
          onBlur={this.handleBlur}
          error={errors.cloudinary_cloud_name}
        />
        <button className="btn btn-primary">Save changes</button>
      </form>
    );
  }
}
</code>```

答:
It's because you are setting the value to props instead of your state here:

```<code><TextFieldGroup
  name="cloudinary_cloud_name"
  type="text"
  value={
    cloudinaryData
      ? cloudinaryData.cloudinary_cloud_name
      : cloudinary.cloudinary_cloud_name
  }
  onChange={this.handleChange}
  onBlur={this.handleBlur}
  error={errors.cloudinary_cloud_name}
/>
</code>```

Instead, create a constructor and initialize your state to your props and replace your value to use state:

```<code>const mapStateToProps = createStructuredSelector({
  cloudinaryData: selectCloudinary()
});

class Cloudinary extends React.Component {

  constructor(props){
      super(props);
      state = {
          cloudinary: {
            cloudinary_cloud_name: props.cloudinaryData.cloudinary_cloud_name,
            cloudinary_api_key: props.cloudinaryData.cloudinary_api_key,
       },
       errors: {}
     }
  }

  componentDidMount() {
    this.props.loadCloudinary();
  }

  handleChange = event => {
    const fieldName = event.target.name;
    this.setState(
      {
        cloudinary: {
          ...this.state.cloudinary,
          [event.target.name]: event.target.value
        }
      },
      () => {
        this.validateField([fieldName]);
      }
    );
  };

  handleSubmit = event => {
    event.preventDefault();
    this.props.requestCloudinary(this.state.cloudinary);
  };

  render() {
    const { cloudinary, errors } = this.state;
    const { cloudinaryData } = this.props;
    if (cloudinaryData.size === 0) {
      return <div>Fetching Data...</div>;
    }
    return (
      <form onSubmit={this.handleSubmit}>
        <TextFieldGroup
          name="cloudinary_cloud_name"
          type="text"
          value={cloudinary.cloudinary_cloud_name}
          onChange={this.handleChange}
          onBlur={this.handleBlur}
          error={errors.cloudinary_cloud_name}
        />
        <button className="btn btn-primary">Save changes</button>
      </form>
    );
  }
}
</code>```

Body:
I have a form where data are fetched from the server and is shown to the text field. Albeit the data is in text field, when i click on save button, i get error on all the fields displaying following fields cannot be empty. Also when i try to change the value, i cant get to type any text neither i can erase the text. Why the value is shown empty when having value over there?

const mapStateToProps = createStructuredSelector({
  cloudinaryData: selectCloudinary()
});

class Cloudinary extends React.Component {
  state = {
    cloudinary: {
      cloudinary_cloud_name: "",
      cloudinary_api_key: "",
    },
    errors: {}
  };

  componentDidMount() {
    this.props.loadCloudinary();
  }

  handleChange = event => {
    const fieldName = event.target.name;
    this.setState(
      {
        cloudinary: {
          ...this.state.cloudinary,
          [event.target.name]: event.target.value
        }
      },
      () => {
        this.validateField([fieldName]);
      }
    );
  };

  handleSubmit = event => {
    event.preventDefault();
    this.props.requestCloudinary(this.state.cloudinary);
  };

  render() {
    const { cloudinary, errors } = this.state;
    const { cloudinaryData } = this.props;
    if (cloudinaryData.size === 0) {
      return
Fetching Data...
;
    }
    return (
      <form onSubmit={this.handleSubmit}>
        <TextFieldGroup
          name="cloudinary_cloud_name"
          type="text"
          value={
            cloudinaryData
              ? cloudinaryData.cloudinary_cloud_name
              : cloudinary.cloudinary_cloud_name
          }
          onChange={this.handleChange}
          onBlur={this.handleBlur}
          error={errors.cloudinary_cloud_name}
        />
        <button className="btn btn-primary">Save changes</button>
      </form>
    );
  }
}

Body:
It's because you are setting the value to props instead of your state here:

<TextFieldGroup
  name="cloudinary_cloud_name"
  type="text"
  value={
    cloudinaryData
      ? cloudinaryData.cloudinary_cloud_name
      : cloudinary.cloudinary_cloud_name
  }
  onChange={this.handleChange}
  onBlur={this.handleBlur}
  error={errors.cloudinary_cloud_name}
/>

Instead, create a constructor and initialize your state to your props and replace your value to use state:

const mapStateToProps = createStructuredSelector({
  cloudinaryData: selectCloudinary()
});

class Cloudinary extends React.Component {

  constructor(props){
      super(props);
      state = {
          cloudinary: {
            cloudinary_cloud_name: props.cloudinaryData.cloudinary_cloud_name,
            cloudinary_api_key: props.cloudinaryData.cloudinary_api_key,
       },
       errors: {}
     }
  }

  componentDidMount() {
    this.props.loadCloudinary();
  }

  handleChange = event => {
    const fieldName = event.target.name;
    this.setState(
      {
        cloudinary: {
          ...this.state.cloudinary,
          [event.target.name]: event.target.value
        }
      },
      () => {
        this.validateField([fieldName]);
      }
    );
  };

  handleSubmit = event => {
    event.preventDefault();
    this.props.requestCloudinary(this.state.cloudinary);
  };

  render() {
    const { cloudinary, errors } = this.state;
    const { cloudinaryData } = this.props;
    if (cloudinaryData.size === 0) {
      return <div>Fetching Data...</div>;
    }
    return (
      <form onSubmit={this.handleSubmit}>
        <TextFieldGroup
          name="cloudinary_cloud_name"
          type="text"
          value={cloudinary.cloudinary_cloud_name}
          onChange={this.handleChange}
          onBlur={this.handleBlur}
          error={errors.cloudinary_cloud_name}
        />
        <button className="btn btn-primary">Save changes</button>
      </form>
    );
  }
}


问:
mysql query optimization and manipulation of field value
```<code>mysql> select * from dts;
+----+------+------+--------+------+------+------+------+------+
| Id | key1 | key2 | serial | pr1  | pr2  | pr3  | pr4  | pr5  |
+----+------+------+--------+------+------+------+------+------+
|  1 |    1 |    1 |      1 |    0 |    0 |    1 |    0 |    2 |
|  2 |    1 |    1 |      2 |    0 |    0 |    0 |    0 |    0 |
|  3 |    1 |    1 |      3 |    0 |    0 |    0 |    1 |    0 |
|  4 |    1 |    1 |      4 |    1 |    0 |    1 |    1 |    3 |
|  5 |    1 |    2 |      5 |    0 |    0 |    0 |    2 |    5 |
|  6 |    1 |    2 |      6 |    0 |    0 |    0 |    0 |    1 |
|  7 |    1 |    2 |      7 |    0 |    1 |    0 |    0 |    0 |
|  8 |    2 |    2 |      1 |    1 |    1 |    1 |    1 |    2 |
|  9 |    2 |    2 |      2 |    0 |    0 |    0 |    0 |    0 |
| 10 |    3 |    2 |      3 |    0 |    0 |    0 |    0 |    0 |
| 11 |    3 |    3 |      1 |    1 |    1 |    0 |    0 |    1 |
| 12 |    3 |    3 |      5 |    0 |    0 |    1 |    1 |    0 |
+----+------+------+--------+------+------+------+------+------+
12 rows in set (0.00 sec)
</code>```

Logic I want to implement here is as follows

check is there any non zero data in fields(pr1-pr5) of table dts ?

If found concat field name with comma, suppose if all fields are non zero, just concat fields and stop reading records of same key
  (combination of key1,key2 to save execution time, look it 8th row in
  above table for key1=2 and key2=2 all are non zero, so stop reading
  next record with same keys), go to next key1,key2

What is not working is as follows

At present code which I am using is working, but its not skipping
  reading row when enough fields are found, as you can see for current
  example it creates 12 rows X 5 Col = 60 Rows (if you execute inner
  select statement it returns 60 rows) and then groups it by key1 and
  key2, can it be done in any simple way which is efficient too so that
  table with 2-3 million records will be faster.

Expected output

```<code>+------+------+---------------------+
| key1 | key2 | prs                 |
+------+------+---------------------+
|    1 |    1 | pr1,pr3,pr4,pr5     |
|    1 |    2 | pr2,pr4,pr5         |
|    2 |    2 | pr1,pr2,pr3,pr4,pr5 |
|    3 |    2 | NULL                |
|    3 |    3 | pr1,pr2,pr3,pr4,pr5 |
+------+------+---------------------+
</code>```

So how this can be simplified to improve performance with large table, as you can see above my intention is simple, I just want to see how many fields (pr1-pr5) exists with non zero value for each combinations of key1, key2

Code am using

```<code>SELECT
    key1,
    key2,
    group_concat(distinct case when val > 0 then pr end order by pr separator ',') prs
FROM (
    SELECT
        d.key1,
            d.key2,
            t.pr,
            CASE t.pr
                WHEN 'pr1' THEN pr1
                WHEN 'pr2' THEN pr2
                WHEN 'pr3' THEN pr3
                WHEN 'pr4' THEN pr4
                WHEN 'pr5' THEN pr5
            END val
    FROM
        dts d
    CROSS JOIN (
        SELECT 'pr1' pr UNION ALL
        SELECT 'pr2' UNION ALL
        SELECT 'pr3' UNION ALL
        SELECT 'pr4' UNION ALL
        SELECT 'pr5'
    ) t
) r
GROUP BY key1 , key2;
</code>```

Structure

```<code>DROP TABLE IF EXISTS `dts`;
CREATE TABLE `dts` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `key1` int(11) DEFAULT '-99',
  `key2` int(11) DEFAULT '-99',
  `serial` int(11) DEFAULT '-99',
  `pr1` int(11) DEFAULT '-99',
  `pr2` int(11) DEFAULT '-99',
  `pr3` int(11) DEFAULT '-99',
  `pr4` int(11) DEFAULT '-99',
  `pr5` int(11) DEFAULT '-99',
  PRIMARY KEY (`Id`),
  KEY `main` (`key1`,`key2`,`serial`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;

LOCK TABLES `dts` WRITE;
INSERT INTO `dts` VALUES (1,1,1,1,0,0,1,0,2),(2,1,1,2,0,0,0,0,0),(3,1,1,3,0,0,0,1,0),(4,1,1,4,1,0,1,1,3),(5,1,2,5,0,0,0,2,5),(6,1,2,6,0,0,0,0,1),(7,1,2,7,0,1,0,0,0),(8,2,2,1,1,1,1,1,2),(9,2,2,2,0,0,0,0,0),(10,3,2,3,0,0,0,0,0),(11,3,3,1,1,1,0,0,1),(12,3,3,5,0,0,1,1,0);
UNLOCK TABLES;
</code>```

Blockquote

答:
```<code>SELECT key1, key2,
       CONCAT_WS(',',
         IF(pr1=0, NULL, 'pr1'),
         IF(pr2=0, NULL, 'pr2'),
         IF(pr3=0, NULL, 'pr3'),
         IF(pr4=0, NULL, 'pr4'),
         IF(pr5=0, NULL, 'pr5') ) AS prs
    FROM (
           SELECT key1, key2,
               SUM(pr1) AS pr1,
               SUM(pr2) AS pr2,
               SUM(pr3) AS pr3,
               SUM(pr4) AS pr4,
               SUM(pr5) AS pr5
            FROM dts
            GROUP BY key1, key2
         ) AS sums;
</code>```

If you need "NULL" in the 3,2 row, you can add an IFNULL to fix it.

Body:
mysql> select * from dts;
+----+------+------+--------+------+------+------+------+------+
| Id | key1 | key2 | serial | pr1  | pr2  | pr3  | pr4  | pr5  |
+----+------+------+--------+------+------+------+------+------+
|  1 |    1 |    1 |      1 |    0 |    0 |    1 |    0 |    2 |
|  2 |    1 |    1 |      2 |    0 |    0 |    0 |    0 |    0 |
|  3 |    1 |    1 |      3 |    0 |    0 |    0 |    1 |    0 |
|  4 |    1 |    1 |      4 |    1 |    0 |    1 |    1 |    3 |
|  5 |    1 |    2 |      5 |    0 |    0 |    0 |    2 |    5 |
|  6 |    1 |    2 |      6 |    0 |    0 |    0 |    0 |    1 |
|  7 |    1 |    2 |      7 |    0 |    1 |    0 |    0 |    0 |
|  8 |    2 |    2 |      1 |    1 |    1 |    1 |    1 |    2 |
|  9 |    2 |    2 |      2 |    0 |    0 |    0 |    0 |    0 |
| 10 |    3 |    2 |      3 |    0 |    0 |    0 |    0 |    0 |
| 11 |    3 |    3 |      1 |    1 |    1 |    0 |    0 |    1 |
| 12 |    3 |    3 |      5 |    0 |    0 |    1 |    1 |    0 |
+----+------+------+--------+------+------+------+------+------+
12 rows in set (0.00 sec)

Logic I want to implement here is as follows

check is there any non zero data in fields(pr1-pr5) of table dts ?

If found concat field name with comma, suppose if all fields are non zero, just concat fields and stop reading records of same key
  (combination of key1,key2 to save execution time, look it 8th row in
  above table for key1=2 and key2=2 all are non zero, so stop reading
  next record with same keys), go to next key1,key2

What is not working is as follows

At present code which I am using is working, but its not skipping
  reading row when enough fields are found, as you can see for current
  example it creates 12 rows X 5 Col = 60 Rows (if you execute inner
  select statement it returns 60 rows) and then groups it by key1 and
  key2, can it be done in any simple way which is efficient too so that
  table with 2-3 million records will be faster.

Expected output

+------+------+---------------------+
| key1 | key2 | prs                 |
+------+------+---------------------+
|    1 |    1 | pr1,pr3,pr4,pr5     |
|    1 |    2 | pr2,pr4,pr5         |
|    2 |    2 | pr1,pr2,pr3,pr4,pr5 |
|    3 |    2 | NULL                |
|    3 |    3 | pr1,pr2,pr3,pr4,pr5 |
+------+------+---------------------+

So how this can be simplified to improve performance with large table, as you can see above my intention is simple, I just want to see how many fields (pr1-pr5) exists with non zero value for each combinations of key1, key2

Code am using

SELECT
    key1,
    key2,
    group_concat(distinct case when val > 0 then pr end order by pr separator ',') prs
FROM (
    SELECT
        d.key1,
            d.key2,
            t.pr,
            CASE t.pr
                WHEN 'pr1' THEN pr1
                WHEN 'pr2' THEN pr2
                WHEN 'pr3' THEN pr3
                WHEN 'pr4' THEN pr4
                WHEN 'pr5' THEN pr5
            END val
    FROM
        dts d
    CROSS JOIN (
        SELECT 'pr1' pr UNION ALL
        SELECT 'pr2' UNION ALL
        SELECT 'pr3' UNION ALL
        SELECT 'pr4' UNION ALL
        SELECT 'pr5'
    ) t
) r
GROUP BY key1 , key2;

Structure

DROP TABLE IF EXISTS `dts`;
CREATE TABLE `dts` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `key1` int(11) DEFAULT '-99',
  `key2` int(11) DEFAULT '-99',
  `serial` int(11) DEFAULT '-99',
  `pr1` int(11) DEFAULT '-99',
  `pr2` int(11) DEFAULT '-99',
  `pr3` int(11) DEFAULT '-99',
  `pr4` int(11) DEFAULT '-99',
  `pr5` int(11) DEFAULT '-99',
  PRIMARY KEY (`Id`),
  KEY `main` (`key1`,`key2`,`serial`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;

LOCK TABLES `dts` WRITE;
INSERT INTO `dts` VALUES (1,1,1,1,0,0,1,0,2),(2,1,1,2,0,0,0,0,0),(3,1,1,3,0,0,0,1,0),(4,1,1,4,1,0,1,1,3),(5,1,2,5,0,0,0,2,5),(6,1,2,6,0,0,0,0,1),(7,1,2,7,0,1,0,0,0),(8,2,2,1,1,1,1,1,2),(9,2,2,2,0,0,0,0,0),(10,3,2,3,0,0,0,0,0),(11,3,3,1,1,1,0,0,1),(12,3,3,5,0,0,1,1,0);
UNLOCK TABLES;

Blockquote

Body:
SELECT key1, key2,
       CONCAT_WS(',',
         IF(pr1=0, NULL, 'pr1'),
         IF(pr2=0, NULL, 'pr2'),
         IF(pr3=0, NULL, 'pr3'),
         IF(pr4=0, NULL, 'pr4'),
         IF(pr5=0, NULL, 'pr5') ) AS prs
    FROM (
           SELECT key1, key2,
               SUM(pr1) AS pr1,
               SUM(pr2) AS pr2,
               SUM(pr3) AS pr3,
               SUM(pr4) AS pr4,
               SUM(pr5) AS pr5
            FROM dts
            GROUP BY key1, key2
         ) AS sums;

If you need "NULL" in the 3,2 row, you can add an IFNULL to fix it.


问:
android get real path by Uri.getPath()
I'm trying to get image from gallery.

```<code>Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );
</code>```

After I returned from this activity I have a data, which contains Uri. It looks like:

```<code>content://media/external/images/1
</code>```

How can I convert this path to real one  (just like '/sdcard/image.png') ?

Thanks

答:
This helped me to get uri from Gallery and convert to a file for Multipart upload

```<code>File file = FileUtils.getFile(this, fileUri);
</code>```

https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java

Title: android get real path by Uri.getPath()

Body:
I'm trying to get image from gallery.

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );

After I returned from this activity I have a data, which contains Uri. It looks like:

content://media/external/images/1

How can I convert this path to real one  (just like '/sdcard/image.png') ?

Thanks

Body:
This helped me to get uri from Gallery and convert to a file for Multipart upload

File file = FileUtils.getFile(this, fileUri);

https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java


答:
I guess what you need is between operator. The between operator aims to select values within a given range. In your scenario, an age range. This operator is inclusive. This means that begin and end values are included. </p>

```<code><?php

$Age1 = 10;
$Age2 = 25;

$stmt = mysqli_query(
    $con,
    "SELECT * " .
    "FROM job_post_p1 " .
    "WHERE Age BETWEEN $Age1 AND $Age2"
);
</code>```

Title: How to query search numbers in php mysql

Body:
I need a search query.
Age value 10 - 15 , 20 - 25 , 17 - 19 , 12 - 59 , 2 - 19 , 18 - 40 , 10 - 20

I send 10 - 25 and I want to get results by matching the numbers

<?php
  $Age1 = 10;
  $Age2 = 25;

  $Age = $Age1." - ".$Age2;

  $stmt = mysqli_query($con,"SELECT * FROM job_post_p1 where Age LIKE '%" . $Age .  "%'");

?>

Thanks to All

Body:
I guess what you need is between operator. The between operator aims to select values within a given range. In your scenario, an age range. This operator is inclusive. This means that begin and end values are included.

<?php

$Age1 = 10;
$Age2 = 25;

$stmt = mysqli_query(
    $con,
    "SELECT * " .
    "FROM job_post_p1 " .
    "WHERE Age BETWEEN $Age1 AND $Age2"
);


问:
UINavigationButton in Tabbar - possible rejection?
Someone wants me to make an App, where the NavigationButton (usually top left) shall be put into the Tabbar (in this case leftmost Button of the Tabbar). I wonder if that might yield a possible rejection.

It reads in the Appstore Review Guidelines:

a) Apps that alter the functions of standard switches, such as the Volume Up/Down and Ring/Silent switches, will be rejected

-> Could that also include NavButtons?

Furthermore:

b) Apps that do not use system provided items, such as buttons and icons, correctly and as described in the Apple iPhone Human Interface Guidelines and the Apple iPad Human Interface Guidelines may be rejected

I do not know whether we crossed the line there.

What's your opinion on this?

答:
I'd say it's a bit of a crap shoot and you need to weigh whether the feature is important enough to possibly delay your release by 2 weeks or more.  If you submit it with the feature I would spend some time working on a different solution so that if it is rejected you can submit with the changes right away.

From personal experience, I had an app rejected because they didn't like the image I used on a button since that image was meant to convey "picking a contact for use in the app" not picking a contact to add information too.  It was my opinion that this was a petty almost silly thing, but I corrected it and resubmitted.  Both reviews took over 2 weeks.  So it took me over 4 weeks to get approved.

Apple has gotten better about telling you what won't be accepted, etc.  But different reviewers seem to have different opinions.  I'd say the description of your feature is likely to be rejected, but you'll never know until you submit it.


问:
My sharedpreference doesn't update,
I've been trying to get this working for a while now with no success.I'm running out of options and hope you guys can help.
I want to save the text in the edit text using sharedprefernce. Then send that text to my appwidgetprovider,which sends the text back for editing,when the widget is clicked.When editing is done and i save it it should send the text back to the appwidgetprovider and so on.

But that not the case. The edit text opens up with previous saved text,but once I've saved it doesn't update the shared preference. The value of the shared preference in the app-widget provider remains the same.

Here's the class which sends the text to the appwidgetprovider.

```<code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(widget_handler);

    editText = (EditText) findViewById(R.id.widget_note);
    editText.requestFocus();
    final InputMethodManager imm2 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm2.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_widget);
    setSupportActionBar(toolbar);
    editText.setText(getIntent().getStringExtra("Name"));

  toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    String newEntry = editText.getText().toString();
        final SharedPreferences sharedPreferences=getSharedPreferences("Key",WidgetHandler.MODE_PRIVATE);
        final SharedPreferences.Editor editor=getSharedPreferences(newEntry,WidgetHandler.MODE_PRIVATE).edit();
        sharedPreferences.edit().putString("Name",newEntry).apply();
        editor.putString("Name",newEntry);
        editor.apply();
        Intent intent3= getIntent();
        Bundle extras=intent3.getExtras();

        if (extras!= null) {
            mAppWidgetId = extras.getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
        }

            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
            RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.new_app_widget);

            remoteViews.setTextViewText(R.id.appwidget_text, newEntry);
            appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews);
           final  Intent intent = new Intent();
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            intent.putExtra("Name",newEntry);

        setResult(RESULT_OK, intent);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            finish();
            Intent home = new Intent(Intent.ACTION_MAIN);
            home.addCategory(Intent.CATEGORY_HOME);
            home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(home);

    }
});
</code>```

Here's my appwidgetprovider which is supposed to receive the updated text.

```<code>static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);

       SharedPreferences sharedPreferences=context.getSharedPreferences("Key",Context.MODE_PRIVATE);
        String name=sharedPreferences.getString("Name","");
        Log.e("name",name);

        final Intent clickIntent = new Intent(context, WidgetHandler.class);
        clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetId);
        clickIntent.putExtra("Name",name);
        PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        views.setOnClickPendingIntent(R.id.appwidget_text,clickPI);

        // Instruct the widget manager to update the widget
        appWidgetManager.updateAppWidget(appWidgetId, views);

    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

@Override
public void onEnabled(Context context) {

    // Instruct the widget manager to update the widget

}

@Override
public void onDisabled(Context context) {

    // Enter relevant functionality for when the last widget is disabled
}
</code>```

Thanks in advance :).

答: Try editor.commit() instead of editor.apply()</p>

Title: My sharedpreference doesn't update,

Body:
I've been trying to get this working for a while now with no success.I'm running out of options and hope you guys can help.
I want to save the text in the edit text using sharedprefernce. Then send that text to my appwidgetprovider,which sends the text back for editing,when the widget is clicked.When editing is done and i save it it should send the text back to the appwidgetprovider and so on.

But that not the case. The edit text opens up with previous saved text,but once I've saved it doesn't update the shared preference. The value of the shared preference in the app-widget provider remains the same.

Here's the class which sends the text to the appwidgetprovider.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(widget_handler);

    editText = (EditText) findViewById(R.id.widget_note);
    editText.requestFocus();
    final InputMethodManager imm2 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm2.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_widget);
    setSupportActionBar(toolbar);
    editText.setText(getIntent().getStringExtra("Name"));

  toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    String newEntry = editText.getText().toString();
        final SharedPreferences sharedPreferences=getSharedPreferences("Key",WidgetHandler.MODE_PRIVATE);
        final SharedPreferences.Editor editor=getSharedPreferences(newEntry,WidgetHandler.MODE_PRIVATE).edit();
        sharedPreferences.edit().putString("Name",newEntry).apply();
        editor.putString("Name",newEntry);
        editor.apply();
        Intent intent3= getIntent();
        Bundle extras=intent3.getExtras();

        if (extras!= null) {
            mAppWidgetId = extras.getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
        }

            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
            RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.new_app_widget);

            remoteViews.setTextViewText(R.id.appwidget_text, newEntry);
            appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews);
           final  Intent intent = new Intent();
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            intent.putExtra("Name",newEntry);

        setResult(RESULT_OK, intent);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            finish();
            Intent home = new Intent(Intent.ACTION_MAIN);
            home.addCategory(Intent.CATEGORY_HOME);
            home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(home);

    }
});

Here's my appwidgetprovider which is supposed to receive the updated text.

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);

       SharedPreferences sharedPreferences=context.getSharedPreferences("Key",Context.MODE_PRIVATE);
        String name=sharedPreferences.getString("Name","");
        Log.e("name",name);

        final Intent clickIntent = new Intent(context, WidgetHandler.class);
        clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetId);
        clickIntent.putExtra("Name",name);
        PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        views.setOnClickPendingIntent(R.id.appwidget_text,clickPI);

        // Instruct the widget manager to update the widget
        appWidgetManager.updateAppWidget(appWidgetId, views);

    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

@Override
public void onEnabled(Context context) {

    // Instruct the widget manager to update the widget

}

@Override
public void onDisabled(Context context) {

    // Enter relevant functionality for when the last widget is disabled
}

Thanks in advance :).


问:
I am providing a key for each child in react, but I am still getting an error?
I have done this before and I am providing a key, but for some reason I am still getting the error. I am a bit new to react so it could be a silly mistake somewhere.

Edit: Error is the each child in an array should have a unique key

Here is the code:

```<code>import React, { Component } from 'react';
import { connect } from 'react-redux';
import _ from 'lodash';

class BooksList extends Component {
  renderList() {
    return _.map(this.props.books, book => {
      return (
        <div key={book.id}>
          <h2>{book.title}</h2>
          <h3>{book.description}</h3>
          <h4>{book.price}</h4>
        </div>
      );
    });
  }
  render() {
    return (
      <div>
        {this.renderList()}
      </div>
    );
  }
}

function mapStateToProps(state) {
  return {
    books: state.books
  }
}

export default connect(mapStateToProps)(BooksList);
</code>```

Edit:

I tried binding this.renderList, in the constructor, but still have the same issue:

```<code>constructor(props) {
    super(props);
    this.renderList = this.renderList.bind(this);
}
</code>```

答:
Your issue is you are not loading the books before the map happens initially.. so you have invalid data initially.

Initially this.props.books is this

then you load the books and it turns to this.

The fix for this is to only render when you have a valid object. Use the lodash isEmpty check for an object... use a forEach so you dont return empty in an array (less items to hold in array). and then just return that array at the end :)

```<code>renderList() {
  const elems = [];
  _.forEach(this.props.books, book => {
    if (_.isEmpty(book)) return;
    elems.push(
      <div key={book.id}>
        <h2>{book.title}</h2>
        <h3>{book.description}</h3>
        <h4>{book.price}</h4>
      </div>
    );
  });
  return elems;
}
</code>```

Body:
I have done this before and I am providing a key, but for some reason I am still getting the error. I am a bit new to react so it could be a silly mistake somewhere.

Edit: Error is the each child in an array should have a unique key

Here is the code:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import _ from 'lodash';

class BooksList extends Component {
  renderList() {
    return _.map(this.props.books, book => {
      return (

{book.title}

{book.description}

{book.price}

      );
    });
  }
  render() {
    return (

        {this.renderList()}

    );
  }
}

function mapStateToProps(state) {
  return {
    books: state.books
  }
}

export default connect(mapStateToProps)(BooksList);

Edit:

I tried binding this.renderList, in the constructor, but still have the same issue:

constructor(props) {
    super(props);
    this.renderList = this.renderList.bind(this);
}

Body:
Your issue is you are not loading the books before the map happens initially.. so you have invalid data initially.

Initially this.props.books is this

then you load the books and it turns to this.

The fix for this is to only render when you have a valid object. Use the lodash isEmpty check for an object... use a forEach so you dont return empty in an array (less items to hold in array). and then just return that array at the end :)

renderList() {
  const elems = [];
  _.forEach(this.props.books, book => {
    if (_.isEmpty(book)) return;
    elems.push(
      <div key={book.id}>
        <h2>{book.title}</h2>
        <h3>{book.description}</h3>
        <h4>{book.price}</h4>
      </div>
    );
  });
  return elems;
}