Skip to content

Instantly share code, notes, and snippets.

View ikhsanalatsary's full-sized avatar
🏠
Working from home

Abdul Fattah Ikhsan ikhsanalatsary

🏠
Working from home
View GitHub Profile
@ikhsanalatsary
ikhsanalatsary / user_auth.rb
Last active November 21, 2018 16:53
rails action
def auth
user = User.find_by(username: params[:username])
if user&.check_password(params[:password])
render json: user
else
render json: { errors: ['wrong username or password'] }, status: :unauthorized
end
end
@ikhsanalatsary
ikhsanalatsary / run.sh
Created October 25, 2019 10:31
Couldn't set up Steam data - please contact technical support
mv ~/.steam/steam/* ~/.local/share/Steam/
rmdir ~/.steam/steam
ln -s ../.local/share/Steam ~/.steam/steam
rm -rf ~/.steam/bin
#!/bin/bash
mkdir /tmp/GitEye
sudo unzip -d /tmp/GitEye ~/Downloads/GitEye*.zip
sudo chown -R root:root /tmp/GitEye
sudo mv /tmp/GitEye /opt/GitEye
sudo ln -s /opt/GitEye/GitEye /usr/local/bin/GitEye
sudo rm -rf /tmp/GitEye
#Create a Desktop Entry
#!/bin/bash
# check m4 already installed
whereis m4
# install automake
sudo apt install automake
# install pkg-config
sudo apt install pkg-config
# install watchman
git clone https://github.com/facebook/watchman.git
@ikhsanalatsary
ikhsanalatsary / app.css
Last active January 28, 2020 18:55
Table template
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 40px;
margin-bottom: 60px;
max-width: 800px;
margin-left: auto;
@ikhsanalatsary
ikhsanalatsary / clean-node-modules.sh
Created May 9, 2020 20:55 — forked from cusspvz/clean-node-modules.sh
Delete all node_modules folders RECURSIVELY
#!/bin/bash
# this will find all node_modules above your path and will remove them
find . | grep /node_modules$ | grep -v /node_modules/ | xargs rm -fRv
@ikhsanalatsary
ikhsanalatsary / get.ts
Created July 8, 2020 13:16
Example generics type
// function declaration
function get<T>(options: string): T {
// do stuff
}
// invocation
get<Object>(options);
@ikhsanalatsary
ikhsanalatsary / refine.ts
Created July 17, 2020 23:35
Type Refinement example
function calculateSum(firstUserInput: unknown, secondUserInput: unknown) {
if (typeof firstUserInput !== "number") {
throw new TypeError("first provided value has a wrong type. Should be a number")
}
if (typeof secondUserInput !== "number") {
throw new TypeError("second provided value has a wrong type. Should be a number")
}
return firstUserInput + secondUserInput;
}
let calc1 = calculateSum('sa', 'dd')
@ikhsanalatsary
ikhsanalatsary / overloads.ts
Last active July 17, 2020 23:46
Overloading
class Utility {
collectionFor(name: string): Characters
collectionFor(name: string, type: 'removed'): number
collectionFor(name: string, type?: string | undefined): CharsOrNum {
if (typeof type === 'undefined') type = 'characters'
let constantName
const col1 = ['meny', 'men', 'mem', 'me']
const col2 = ['peny', 'pen', 'pem']
if (type === 'characters') {
constantName = `${name}_${type}`
@ikhsanalatsary
ikhsanalatsary / withOmit.ts
Created July 18, 2020 00:55
Utility Type Example
type Admin = { name: string, age: number, position: "admin" };
// Type of "admin" is "{ position: "admin" }"
const admin: Omit<Admin, "age" | "name"> = { position: "admin" }