Skip to content

Instantly share code, notes, and snippets.

View arekgotfryd's full-sized avatar
👽
Working from home

Arkadiusz arekgotfryd

👽
Working from home
View GitHub Profile
@arekgotfryd
arekgotfryd / Authorization HOC in React
Created September 5, 2017 17:34
How to use HOC in order to achieve proper authorziation handling in React
export default function Authorized(WrappedComponent) {
return class extends Component {
render() {
if (auth.isAuthenticated()) {
return <WrappedComponent {...this.props} />;
} else {
return <LogIn/>;
}
}
};
@arekgotfryd
arekgotfryd / gist:8e4a40e049353ddc3197cb2388f84ab2
Created September 6, 2017 09:38
Great Generator example ES6
function *foo(x) {
var y = 2 * (yield (x + 1));
var z = yield (y / 3);
return (x + y + z);
}
var it = foo( 5 );
// note: not sending anything into `next()` here
console.log( it.next() ); // { value:6, done:false }
function getTweets (uid) {
return fetch('https://api.users.com/' + uid)
.then((response) => {
return response.json()
})
.then((response) => {
return response.data
}).then((tweets) => {
return tweets.filter((tweet) => {
return tweet.stars > 50
After doing some code changes on master local branch
you just have type following commands and you will create
new remote branch out of code changes
git checkout -b <new-branch-name>
git add .
git commit -m <new-branch-name>
git push -u origin <new-branch-name>
async function getFirstUser() {
//getUsers() returns Promise
let users = await getUsers();
return users[0].name;
}
let user = await getFirstUser();
@arekgotfryd
arekgotfryd / gist:9cc860e5e0864fb8d03bb4305f231b73
Created February 19, 2018 12:49
Create db under different name for MSSQL (here we create new database which previously was calles GDPR I only changed files names)
USE [master]
GO
CREATE DATABASE [GDPRBCK] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.GDPR\MSSQL\DATA\GDPRBCK.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.GDPR\MSSQL\DATA\GDPRBCK_log.ldf' )
FOR ATTACH
GO
@arekgotfryd
arekgotfryd / gist:87649b197052120d206dfa235bfa3f2a
Created February 20, 2018 13:24
Proper auth enablement for fresh mongo installation
1. Start mongo without authentication
`mongod --port 27017 --dbpath /data/db1`
2. Run mongo shell
`mongo --port 27017`
3. Run following command to give admin user root priviliges
use admin
db.createUser(
{
@arekgotfryd
arekgotfryd / gist:b5995aec77cebb4d8cd8ed2048a3f6fe
Created February 21, 2018 10:21
Mail Accounts and Profiles Management SQL Server
You can use folowing system stored procedures to get some info about SQL server mail accounts and profiles:
EXEC msdb.dbo.sysmail_help_configure_sp;
EXEC msdb.dbo.sysmail_help_account_sp;
EXEC msdb.dbo.sysmail_help_profile_sp;
EXEC msdb.dbo.sysmail_help_profileaccount_sp;
EXEC msdb.dbo.sysmail_help_principalprofile_sp;
The following example creates a Database Mail account and a Database Mail profile.
The example then adds the account to the profile and grants access to the profile to the DBMailUsers database role in the msdb database.
-- Create a Database Mail account
@arekgotfryd
arekgotfryd / gist:dbab294703c8e09f0ada90d2bc21fc64
Created February 24, 2018 09:15
Hard delete unpublished commits
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
UserSchema.pre("save", function(next) {
var user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified("password")) return next();
// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
if (err) return next(err);
// hash the password using our new salt
bcrypt.hash(user.password, salt, function(err, hash) {