2023. 7. 15.

Passing custom event function from parent component to child in react

 


Passing  function  from parent to child component 
for click-event customizing 

1) define function in app level

    function. custom_event (key, event) {

      // this is custom function 

      console.log ("call custom function ") ;

    }

2) passing custom function to child by property

     when click item ,  item calls internalClick

       custom_event function is called by name "customFunction" in internalClick function 

        


// in app.js     

  function. custom_event (key, event) {

      // this is custom function 

      console.log ("call custom function ") ;

    }

 <BoardList  customFunction= { this.props.custom_event }  />    


//  in BoardList.js

      // some loop ... 

     <BoardRow keyField={ this.props.keyField}   customFunction = { this.props.customFunction} /> 


//  in BoardRow.js 

     <BoardItem keyField={ this.props.keyField} customFunction = { this.props.customFunction} /> 

// in BoardItem.js 

     internalClick = (e) => {

       console.log ( "click item ") ;

       this.props.customFunction(this.props.keyField , e) ;

     }

    render() {

          return (<button  onClick = { this.internalClick } > click </button>)

    }

    

      

    



Python new string format (update) f-string

 Update .. 

Late news 


My previous post:  2016 

https://blog.boxstory.com/2016/08/python-new-string-format.html


New Addition  :  f-string   ( support  from 3.6 )

variable = 'hello'
print(f' my variable is {variable}') # using f' xxxx {variable_name}'


 # output 
my variable is hello 

# Yes , It's very simple and powerful. 

2023. 5. 21.

brew command list in mac OS


homepage: 

  • site : https://brew.sh/ 
  • full command list : https://docs.brew.sh/Manpage

Minimum command list

  • Install
    • brew install {programname}
  • Start service 
    • brew services start {program name}
  • Stop service
    • brew services stop {program name }
  • List services
    • brew services list
  • Update brew itself
    • brew update
  • Upgrade program
    • brew upgrade {program name }

2023. 5. 20.

License listing used in java project ( maven, gradle )

maven ( POM.xml)

  • run task site,
  • files are generated in
    • target/site/dependencies.html
    • target/site/project-info.html
<Project> <reporting> <plugins> <plugin> <!-- This plugin needs site plugin" --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>3.4.3</version> <reportSets> <reportSet> <reports> <report>dependencies</report> <report>licenses</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting> ...

gradle (build.gradle)

  • run task : generateLicenseReport
  • file generated in
    • build/licenses/index.html
    • build/licenses.csv
    • build/index.xml
import com.github.jk1.license.render.* //import com.github.jk1.license.importer.* plugins { id 'java' id 'org.springframework.boot' version '3.0.6' id 'io.spring.dependency-management' version '1.1.0' id 'project-report' id 'com.github.jk1.dependency-license-report' version '2.1' } // ref : https://github.com/jk1/Gradle-License-Report // run generateLicenseReport licenseReport { outputDir = "$projectDir/build/licenses" renderers = [new InventoryHtmlReportRenderer(),new XmlReportRenderer(), new CsvReportRenderer()] }

2023. 4. 15.

Example code : Split PDF using PyPDF2 (python)

 

  • Very simple example code
  • ref : https://pypdf2.readthedocs.io/en/3.0.0/
* install 
  >> pip install PyPDF2 

*sample src: sample pdf has 38 pages.

12 files are generated and each file has three pages.

this code uses fixed file count number because I already know page count, 

but you can use "len(src_pdf.pages)" to get page count of source file.

from PyPDF2 import PdfFileReader, PdfFileWriter

src_pdf = PdfFileReader(open("./src.pdf'))

for file_index in range(12): # <= len(src_pdf.pages)/3
writer = PdfFileWriter()
for page_index in range(3):
writer.addPage(src_pdf.getPage(file_index*3+page_index+2))
writer.write(open("./out-{:02}.pdf".format(file_index), 'wb'))