Skip to content

Instantly share code, notes, and snippets.

View iRayan7's full-sized avatar
🎯
Focusing

Rayan Aldafas iRayan7

🎯
Focusing
View GitHub Profile
@iRayan7
iRayan7 / git.md
Last active March 16, 2020 10:46
Git random stuff

To clean the clone (delete all untracked files): git clean -d -x -f

Reset head at previous commit: (will destory any commits ahead of this commit) git reset --hard bc30a26 git push -f

Revert a merge: git revert -m 1 bc30a26

@iRayan7
iRayan7 / awaitInsideMap.js
Created May 16, 2019 10:39
Using await inside Map function
// To use await inside a Map function
// From https://medium.com/@pyapar/another-approach-using-map-instead-of-foreach-82a85f536c9c
const waitFor = (ms) => new Promise(r => setTimeout(r, ms));
await Promise.all([1, 2, 3].map(async num => {
await waitFor(50)
console.log(num)
})))
@iRayan7
iRayan7 / Redux.md
Last active December 21, 2019 15:59

Principles:

  1. whether your app is a simpleton or a huge one. The state of the app is a single javascript object.
  2. The state tree is redundant. You can’t modify or write to it. instead anytime you want to change the state you need to dispatch an action.
  3. To describe state mutations, you have to write a function that take the current state and the action being dispatched and returns the next state. And this function has to be pure. This functions is called Reducer.
  • State: The minimal representation of the data in your app.
  • Action: a plain JavaScript object describing the change. The minimal representation of the change to the state.
@iRayan7
iRayan7 / Random Color in Swift.md
Last active November 15, 2018 16:01
A Random Color Generator in Swift
func randomCGFloat() -> CGFloat {
        return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
    
func randomColor() -> UIColor {
        return UIColor(red:   randomCGFloat(),
                       green: randomCGFloat(),
 blue: randomCGFloat(),
@iRayan7
iRayan7 / random.js
Created July 11, 2018 17:51
Generate random strings in Javacript
//
// different ways to generate random string in javascript
//
// 1-
[...Array(30)].map(() => Math.random().toString(36)[3]).join('')
// "bcssk06hjt8nbsxpp1ovqad55j2unp"
// 2-
new Array(30).join().replace(/(.|$)/g, function(){return ((Math.random()*36)|0).toString(36)[Math.random()<.5?"toString":"toUpperCase"]();})
@iRayan7
iRayan7 / CSSTipsAndTricks.md
Last active April 27, 2020 11:23
CSS Tips And Tricks

CSS Tips And Tricks

Personal Gist to save different CSS tips and tricks. Sub-titles used to group similar ideas.

General Articles

Layout

Performance