Skip to content

Instantly share code, notes, and snippets.

@fleepgeek
fleepgeek / react-testing-library--renderWithRedux.md
Last active November 26, 2020 22:16 — forked from darekzak/react-testing-library--renderWithRedux.md
An Improvement to renderWithRedux helper function to enable rerender

Basic Implmentation

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;
@fleepgeek
fleepgeek / drf_serializer_override.py
Created July 12, 2019 23:07
Code showing how to make dynamic serializer fields in Django Rest Framework
# serializers.py
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('id', 'name')
class TagSerializer(serializers.ModelSerializer):
class Meta:
model = Tag
@fleepgeek
fleepgeek / views.py
Created June 24, 2019 15:42 — forked from unpluggedcoder/views.py
Use corresponding serializer class for different request method in Django Rest Framework - Part 3
# 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):
'''
@fleepgeek
fleepgeek / routes.js
Created May 7, 2019 16:52 — forked from rcanepa/routes.js
Private routes with React Router v4
function PrivateRoute ({component: Component, authenticated, ...rest}) {
return (
<Route
{...rest}
render={(props) => authenticated === true
? <Component {...props} />
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
)
}
// 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
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;
$("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"});
function outside() {
let x = 5;
return function inside(y) {
return x + y;
}
}
// returns the inside function's declaration
/*
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.
document.addEventListener('DOMContentLoaded', () => {
// setTimeout(() => {
// console.log("Hello");
// }, 2000);
// console.log("World");
// setInterval(() => {
// console.log("hi");
// }, 1000)
// console.log("World");