Skip to content

Instantly share code, notes, and snippets.

@DZuz14
DZuz14 / Survey.js
Created September 9, 2017 13:02
Survey Component
class Survey extends React.Component {
constructor(props) {
super(props)
this.state = {
questions: [],
voteCount: {}
}
}
@DZuz14
DZuz14 / SurveyRow.js
Created September 9, 2017 13:04
SurveyRow
/**
* Renders an individual question row. Each SurveyRow contains the questions text
* and contains a Controls component as one of its children.
*/
const SurveyRow = ({text, id, increment, decrement, count}) => {
return (
<div className="survey-row">
<div className="text">
<div className="content">
@DZuz14
DZuz14 / Controls.js
Created September 9, 2017 13:09
Controls
/**
* Displays count and houses the increment and decrement buttons
*/
const Controls = ({ id, increment, decrement, count }) => {
return (
<div className="controls">
<div data-id={id} className="minus" onClick={e => decrement(e.target.getAttribute("data-id"))}>
-
</div>
@DZuz14
DZuz14 / SheetsAppend.php
Created December 31, 2017 16:27
Appending To A Google Sheet Via PHP
<?php
$formData = array("Mike Rosoft", "24637", "mikerosoft@gmail.com", "14562342943");
$options = array('valueInputOption' => 'RAW');
$values = [$formData];
$body = new Google_Service_Sheets_ValueRange(['values' => $values]);
$append = $this->service->spreadsheets_values->append(SHEET_ID, 'A2:D', $body, $options);
@DZuz14
DZuz14 / SheetsGet.php
Created December 31, 2017 16:40
Get Values From Google Sheets API
<?php
$exampleEmail = 'mikerosoft@gmail.com';
$result = $this->service->spreadsheets_values->get(SHEET_ID, 'C2:C');
$emails = $result->values;
// $emails will be an array, that you can loop through
for($i = 0; $i < count($emails); $i++) {
if($exampleEmail === $emails[$i][0]) {
// The email exists in the spreadsheet already.
@DZuz14
DZuz14 / signup-user.js
Last active June 25, 2019 14:07
Async Await Action Creator with Redux Thunk
const BACKEND_URL = 'https://fakeserver.com/api'
export function signUpUser(email, password) {
return async (dispatch) => {
try {
const signUp = await axios.post(`${BACKEND_URL}/signup`, {
email: email,
password: password
})
@DZuz14
DZuz14 / index.js
Created February 17, 2018 14:02
JavaScript Object To Explain Redux
var someObject = {
propertyOne: true,
propertyTwo: []
}
@DZuz14
DZuz14 / action.js
Created February 17, 2018 15:15
Redux Action
{
type: "login"
}
@DZuz14
DZuz14 / action-creator.js
Created February 17, 2018 15:25
Action Creator
function login() {
return {
type: "login"
}
}
@DZuz14
DZuz14 / reducer.js
Created February 17, 2018 15:36
Reducer
function loggedIn(state = false, action) {
switch(action.type) {
case "login":
return true;
default:
return state;
}
}