Skip to content

Instantly share code, notes, and snippets.

View sktwentysix's full-sized avatar

Shane Kinsella sktwentysix

  • Software Engineer
  • Bangkok, Thailand
View GitHub Profile
const survey = [
{ name: "Zuri", votedFramework: 'react' },
{ name: "Sofia", votedFramework: 'angular' },
{ name: "Elon", votedFramework: 'react' },
{ name: "Joe", votedFramework: 'react' },
{ name: "Alex", votedFramework: 'angular' },
{ name: "Josh", votedFramework: 'vue' },
{ name: "Jade", votedFramework: 'react' },
{ name: "Ted", votedFramework: 'angular' },
{ name: "Leo", votedFramework: 'react' },
const survey = [
{ name: "Zuri", votedFramework: 'react' },
{ name: "Sofia", votedFramework: 'angular' },
{ name: "Elon", votedFramework: 'react' },
{ name: "Joe", votedFramework: 'react' },
{ name: "Alex", votedFramework: 'angular' },
{ name: "Josh", votedFramework: 'vue' },
{ name: "Jade", votedFramework: 'react' },
{ name: "Ted", votedFramework: 'angular' },
{ name: "Leo", votedFramework: 'react' },
const array = [1,5,3,9,6,2,4]
const reducerCallback = (prevItem, currItem) => {
return prevItem + currItem
}
console.log(array.reduce(reducerCallback)) // 30
@sktwentysix
sktwentysix / array_reducer_example_01.js
Created June 9, 2022 12:03
A simple array reducer example using objects
const array = [
{ id: 111, framework: 'react' },
{ id: 222, framework: 'angular' },
{ id: 333, framework: 'vue' }
];
const reducerCallback = (prevItem, currItem) => {
return {
id: prevItem.id + currItem.id,
framework: prevItem.framework + "-" + currItem.framework
@sktwentysix
sktwentysix / dates.js
Last active May 11, 2022 14:48
Javascript DateTime Functions
function getYearMonthDay(isoDateTime) {
const year = date.getFullYear()
const month = (date.getMonth() + 1 < 10 ? '0' : '') + (date.getMonth() + 1)
const day = date.getDate();
return year + '/' + month + '/' + day
}
function getDayMonthYear(isoDateTime) {
const year = date.getFullYear()
const month = (date.getMonth() + 1 < 10 ? '0' : '') + (date.getMonth() + 1)
@sktwentysix
sktwentysix / App.js
Last active May 2, 2019 10:06
medium-ocr-react-generate2
<button onClick={this.generateText} className="button">Generate</button>
...
{ /* Results */ }
<section className="results">
{ this.state.documents.map((value, index) => {
return (
<div key={index} className="results__result">
<div className="results__result__image">
@sktwentysix
sktwentysix / App.js
Last active May 2, 2019 10:03
medium-ocr-react-generate1
generateText = () => {
let uploads = this.state.uploads
for(var i = 0; i < uploads.length; i++) {
Tesseract.recognize(uploads[i], {
lang: 'eng'
})
.catch(err => {
console.error(err)
})
@sktwentysix
sktwentysix / App.js
Last active May 2, 2019 07:49
medium-ocr-react-handlechange2
{ /* File uploader */ }
<section className="hero">
<label className="fileUploaderContainer">
Click here to upload documents
<input type="file" id="fileUploader" onChange={this.handleChange} multiple />
</label>
<div>
{ this.state.uploads.map((value, index) => {
return <img key={index} src={value} width="100px" />
@sktwentysix
sktwentysix / App.js
Created May 2, 2019 07:25
medium-ocr-react-handlechange
handleChange = (event) => {
if (event.target.files[0]) {
var uploads = []
for (var key in event.target.files) {
if (!event.target.files.hasOwnProperty(key)) continue;
let upload = event.target.files[key]
uploads.push(URL.createObjectURL(upload))
}
this.setState({
uploads: uploads
@sktwentysix
sktwentysix / App.js
Last active May 2, 2019 08:57
medium-ocr-react-constr
constructor(props) {
super(props)
this.state = {
uploads: [],
patterns: [],
documents: []
};
}