Skip to content

Instantly share code, notes, and snippets.

View petrosDemetrakopoulos's full-sized avatar

Petros Demetrakopoulos petrosDemetrakopoulos

View GitHub Profile
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairballoons_deleteById.js
Created January 18, 2022 13:25
Ethairballoons deleteById
Car.deleteById('Audi A4', function (err, success) {
if (!err) {
console.log('object deleted successfully');
}
});
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairballoons_findById.js
Last active January 18, 2022 13:25
Ethairballoons findById
Car.findById('Audi A4', function (err, record) {
if (!err) {
console.log(record);
}
});
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairballoons_find.js
Last active January 18, 2022 13:26
Ethairballoons find
Car.find(function (err, allRecords) {
if (!err) {
console.log(allRecords);
}
});
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairballoons_save.js
Last active January 18, 2022 13:26
Ethairballoons save
var newCarObject = {model:'Audi A4', engine: 'V8', wheels: 4};
Car.save(newCarObject, function (err, objectSaved) {
if (!err) {
console.log('object saved');
}
})
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairbaloons_deploy.js
Last active January 18, 2022 13:27
Ethairballoons deploy
Car.deploy(function (err, success) {
if (!err) {
console.log('Deployed successfully');
}
});
@petrosDemetrakopoulos
petrosDemetrakopoulos / ethairballoons_init.js
Created January 18, 2022 07:59
Initializing EthairBalloons
var ethAirBalloons = require('ethairballoons');
var path = require('path');
var savePath = path.resolve(__dirname + '/contracts');
var ethAirBalloonsProvider = ethAirBalloons('http://localhost:8545', savePath);
//ethereum blockchain provider URL, path to save auto generated smart contracts
var Car = ethAirBalloonsProvider.createSchema({
name: "Car",
contractName: "carsContract",
return (
<div className="App">
<div style={{width: '270px', overflowY: 'scroll', margin: 'auto'}}>
{checkboxItems()}
<p>{state.selections.toString()}</p>
</div>
</div>
);
@petrosDemetrakopoulos
petrosDemetrakopoulos / handleCheckboxChange.ts
Created January 17, 2022 08:44
handleCheckboxChange function
function handleCheckboxChange(key: string) {
let sel = state.selections
let find = sel.indexOf(key)
if (find > -1) {
sel.splice(find, 1)
} else {
sel.push(key)
}
setState({
@petrosDemetrakopoulos
petrosDemetrakopoulos / checkbox_items.ts
Created January 17, 2022 08:43
Chackbox items function
function checkboxItems() {
return (
<React.Fragment>
{options.map((option) => (
<ListItem
key={option}
text={option}
handleOnChange={() => handleCheckboxChange(option)}
selected={state.selections.includes(option)}
></ListItem>
@petrosDemetrakopoulos
petrosDemetrakopoulos / state_vars.ts
Created January 17, 2022 08:42
State variables
const [state, setState] = React.useState<{ selections: string[] }>({ selections: [] });
const options = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9']