This file contains hidden or 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
/* | |
Kill long-running read-only queries | |
*/ | |
SELECT | |
application_name, | |
pg_cancel_backend(pid), /* returns boolean indicating whether or not query was killed */ | |
state, | |
age(clock_timestamp(), query_start), | |
usename, | |
query |
This file contains hidden or 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
SELECT count(*) | |
FROM pg_stat_activity | |
WHERE state != 'idle' | |
AND query_start < (NOW() - INTERVAL '60 seconds'); |
This file contains hidden or 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
SELECT application_name, | |
pid, | |
state, | |
age(clock_timestamp(), query_start), /* How long has the query has been running in h:m:s */ | |
usename, | |
query /* The query text */ | |
FROM pg_stat_activity | |
WHERE state != 'idle' | |
AND query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start asc; |
This file contains hidden or 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
require "jwt" | |
SIGNING_SECRET = 'jwtsigningsecret' | |
ALGORITHM = 'HS512' | |
# A payload with sensitive information | |
payload_sensitive = { social_security_number: "555-44-7777" } | |
# The token has been encoded, but not encrypted | |
token_with_sensitive = JWT.encode payload_sensitive, SIGNING_SECRET, ALGORITHM |
This file contains hidden or 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
require "jwt" | |
SIGNING_SECRET = 'jwtsigningsecret' | |
ALGORITHM = 'HS512' | |
# Suppose a sender wants to send the following payload | |
transfer_50_payload = { transfer_amt: 50 } | |
token_legit = JWT.encode payload, SIGNING_SECRET, ALGORITHM | |
# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ0cmFuc2Zlcl9hbXQiOiI1MCJ9.tf8g0nTprdIzoqLVrjLJS5bYFysiLYal8o4OeBbOuebU1UxGdKYhtADLD2oLzO_P2QmZBFqsF7uAAaN3DvYYAw |
This file contains hidden or 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
export default function applyMiddleware(...middlewares) { | |
return createStore => (...args) => { | |
const store = createStore(...args) | |
let dispatch = () => { | |
throw new Error( | |
'Dispatching while constructing your middleware is not allowed. ' + | |
'Other middleware would not be applied to this dispatch.' | |
) | |
} |
This file contains hidden or 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
import { createStore, applyMiddleware } from 'redux'; | |
import someMiddleware from 'some-redux-middleware'; | |
import rootReducer from './reducers/index'; | |
const store = createStore(rootReducer, applyMiddleware(someMiddleware)); |
This file contains hidden or 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
class SomeForm extends React.Component { | |
handleFirstNameChange = (event) => { | |
this.setState({firstName: event.currentTarget.value}); | |
console.log(this.state.firstName) | |
} | |
render () { | |
return ( | |
<div> |
This file contains hidden or 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
// form_container.js | |
import { connect } from 'react-redux'; | |
import { ReduxControlledComponent } from './components'; | |
const mapStateToProps = (state) => { | |
return { | |
name: state.name, | |
email: state.email, | |
password: state.password | |
} |
This file contains hidden or 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
class ButtonComponent extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
message: 'I do not need to be manually binded!', | |
} | |
} | |
// this is now defined using the arrow function syntax | |
handleClick = () => { |