Skip to content

Instantly share code, notes, and snippets.

View sezgi's full-sized avatar

sezgi

View GitHub Profile
@sezgi
sezgi / hooks.jsx
Created December 7, 2019 02:14
Medium - hooks
const Shrubbery = () => {
const [price, setPrice] = useState(0);
return (
<div>
Too expensive? {price}
<button onClick={() => setPrice(price - 10)}>Bargain</button>
</div>
);
}
@sezgi
sezgi / recompose.jsx
Last active December 7, 2019 02:08
Medium - recompose
const enhance = withState('price', 'setPrice', 0);
const Shrubbery = enhance(({ price, setPrice }) => (
<div>
Too expensive? {price}
<button onClick={() => setPrice(n => n - 10)}>Bargain</button>
</div>
));
@sezgi
sezgi / connect.js
Created December 7, 2019 01:42
Medium - connect
// Redux's `connect`
const ConnectedShrubbery = connect(mapStateToProps, actionCreators)(Shrubbery);
@sezgi
sezgi / hoc.jsx
Last active December 7, 2019 01:53
Medium - HOC
const withLooksNice = BaseComponent => props => <BaseComponent looksNice={true} {...props} />;
const Shrubbery = ({price}) => <div>Too expensive? {price}</div>;
const NiceShrubbery = withLooksNice(Shrubbery);
@sezgi
sezgi / shrubberyFunction.jsx
Last active December 7, 2019 00:54
Medium - functional component
// Functional component
const Shrubbery = ({price}) => <div>Too expensive? {price}</div>;
@sezgi
sezgi / shrubberyClass.jsx
Last active December 7, 2019 00:54
Medium - class component
// Class component
class Shrubbery extends Component {
render() {
return <div>Too expensive? {this.props.price}</div>;
}
}
@sezgi
sezgi / addSlug.js
Created December 6, 2019 22:42
Medium - addSlug
function addSlug(sluglessObject) {
return {
...sluglessObject,
slug: '🐌'
}
// sluglessObject hasn't changed
}
@sezgi
sezgi / slugify.js
Created December 6, 2019 22:29
Medium - slugify
function slugify(myString) {
return myString.trim().toLowerCase().replace(/\s+/g, '🐌');
// myString hasn't changed
}
@sezgi
sezgi / facebook-delete-all-group-members.js
Last active January 11, 2019 08:15
Deletes all group members from a facebook group except yourself. Leaving the group after running this in the javascript console will delete the group. Tested on Chrome May 29, 2017. If your network is super slow, you might want to increase the timeout delay.
// removes your box from the page so you don't get removed from the group
$$('[data-name=GroupProfileGridItem]')[0].remove();
// member action dropdowns
const actions = $$('.adminActions');
// open all dropdowns so they're added to the DOM
for (var i = 0; i < actions.length; i++) {
$$('.adminActions a')[i] && $$('.adminActions a')[i].click();
}
@sezgi
sezgi / hamburger.js
Created May 3, 2016 21:24
Hamburger nav
// using http://johnm.io/project/hamburgler/
$(function () {
var open = false;
function toggleScroll () {
if (open) {
$('.body-wrap').height($('.hamburger-nav')[0].scrollHeight).css('overflow', 'hidden');
} else {
$('.body-wrap').height('auto').css('overflow', 'visible');