Skip to content

Instantly share code, notes, and snippets.

@sadmansh
sadmansh / commit.md
Created September 27, 2020 07:07
Modify a specific commit
  1. Get commit hash (eg. 8fd8s97fcd)
  2. $ git rebase --interactive '8fd8s97fcd^'
  3. In the editor, change 8fd8s97fcd from pick to edit and save, exit
  4. At this point, 8fd8s97fcd is your last commit
  5. Make changes
  6. $ git add
  7. $ git commit --all --amend --no-edit
  8. $ git rebase --continue

Credits: https://stackoverflow.com/a/1186549

@sadmansh
sadmansh / text.css
Last active September 27, 2020 07:03
Limit text lines using CSS
.text {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2; /* number of lines to show */
-webkit-box-orient: vertical;
}
@sadmansh
sadmansh / rsync.txt
Created November 4, 2019 05:49
Rsync remote to local excluding node_modules
rsync -rP --exclude node_modules/ <remote-path> <local-path>
@sadmansh
sadmansh / scroll-indicator.html
Created February 25, 2019 07:12
Scroll indicator using jQuery
<header>
<div id="scroll-indicator"></div>
</header>
<script>
$(window).scroll(function() {
let $scrollHeight = $(window).scrollTop();
let $docHeight = $(document).height() - $(window).height();
let $percentage = ($scrollHeight / $docHeight) * 100;
$('#scroll-indicator').css('width', $percentage + '%');
@sadmansh
sadmansh / dominant-color.js
Created February 7, 2019 05:15
Get the dominant color of an image using JS
function getAverageRGB(img) {
var block = 10;
var defaultRgb = {
r: 0,
g: 0,
b: 0
};
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var data, width, height, length;
@sadmansh
sadmansh / psql.txt
Created September 22, 2018 13:24
PostgreSQL snippets
# Create database
CREATE DATABASE databasename;
# Create user
CREATE USER username WITH ENCRYPTED PASSWORD 'password';
# Add/Change password to existing user
ALTER USER username WITH ENCRYPTED PASSWORD 'password';
# Grant database privileges to user
@sadmansh
sadmansh / github-cli.txt
Last active May 22, 2018 15:54
GitHub CLI commands cheatsheet
# Clone into existing directory
git init
git remote add origin PATH/TO/REPO
git fetch
git reset origin/master # this is required if files in the non-empty directory are in the repo
git checkout -t origin/master
# Add all files
git add .
@sadmansh
sadmansh / wordpress-bulma-walker.php
Created May 20, 2018 18:32
WordPress navigation walker customized for Bulma
class Bulmaa_Nav_Walker extends Walker_Nav_Menu {
public function start_lvl(&$output, $depth = 0, $args = array()) {
$output .= '';
}
public function end_lvl(&$output, $depth = 0, $args = array()) {
$output .= '';
}