function renderWithRedux(ui, { initialState, store = createStore(rootReducer, initialState) } = {}, renderFn = render) {
const obj = {
...renderFn(<Provider store={store}>{ui}</Provider>),
store,
};
obj.rerenderWithRedux = (el) => renderWithRedux(el, { store }, obj.rerender);
return obj;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serializers.py | |
class CategorySerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Category | |
fields = ('id', 'name') | |
class TagSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# views.py | |
from rest_framework import exceptions | |
from rest_framework import generics | |
from myapp import models | |
from myapp import serializers as ser | |
class MethodSerializerView(object): | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function PrivateRoute ({component: Component, authenticated, ...rest}) { | |
return ( | |
<Route | |
{...rest} | |
render={(props) => authenticated === true | |
? <Component {...props} /> | |
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />} | |
/> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function bubbleSort(passedArray) { | |
// // clone the array to prevent the passed array from | |
// // being modified | |
// const arr = [...passedArray]; | |
// const len = passedArray.length; | |
// let swapped = false; | |
// let count = 0; | |
// for (let i = 0; i < len; i++) { | |
// count++; | |
// // Swap elements if the current is greater than the next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const http = require("http"); | |
// fs.writeFileSync("hello.txt", "Hello World"); | |
// fs.writeFile("hello.txt", country, (err) => { | |
// if(!err) { | |
// console.log("Done Writing"); | |
// res.setHeader("Location", "/"); | |
// res.statusCode = 302; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("document").ready(function() { | |
// console.log("Loaded"); | |
let p1 = $(".p-one"); | |
let imgQuote = $(".img-quote"); | |
p1.html("Hello").css("color", "blue"); | |
p1.hover( | |
function() { | |
$(this).css("color", "green"); | |
imgQuote.css({opacity: 1, transition: "all .5s ease-in"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function outside() { | |
let x = 5; | |
return function inside(y) { | |
return x + y; | |
} | |
} | |
// returns the inside function's declaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ABOUT FUNCTIONS | |
--------------- | |
While coding, we could notice there are some similar tasks we | |
do over and over again. An example would be looping. | |
Most of the time, we do the same thing: | |
- declare a counter variable | |
- check if is is less than the array length | |
- increment the counter until the condition is false | |
This tasks above is pretty much the same thing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', () => { | |
// setTimeout(() => { | |
// console.log("Hello"); | |
// }, 2000); | |
// console.log("World"); | |
// setInterval(() => { | |
// console.log("hi"); | |
// }, 1000) | |
// console.log("World"); |