Skip to content

Instantly share code, notes, and snippets.

View bhuvidya's full-sized avatar
💭
Mainly working on Laravel packages.

bhu Boue vidya bhuvidya

💭
Mainly working on Laravel packages.
  • Freelance
  • Melbourne, Australia
View GitHub Profile
@bhuvidya
bhuvidya / git-handy-commands.md
Last active September 21, 2023 13:42
Some handy git commands / operations / workflows.

Git Handy Commands

Delete a local feature branch, the remote tracking branch, and the remote branch

$ git branch -d feature/blah
$ git branch -d -r origin/feature/blah
$ git push origin :feature/blah

Delete a branch on an upstream

$ git push origin :feature/blah

$ git push origin :b55bc88

@bhuvidya
bhuvidya / git-manual-rebase.md
Last active August 9, 2018 04:29
Manual rebasing of a feature branch, including update of origin.

Checkout the feature branch that needs rebasing:

$ git checkout feature/blah

Then rebase onto develop:

$ git rebase develop

Then force upstream feature branch to match local one:

@bhuvidya
bhuvidya / git-miscellany.md
Last active February 1, 2018 06:32
Miscellaneous Git Commands, Tricks etc

Reset head of local and remote master

I had a repo once where master had gone off on a tangent from develop, stuff another developer did, and I wanted to bring it back to the commit where it first forked off from develop. Even though the remote origin had been synced with local master, I knew that no other developer had worked on that branch, and I could safely revert. So just say the commit I wanted to revert to was 56b33e4:

# make sure we are on master
$ git checkout master
@bhuvidya
bhuvidya / css-snippets.sass
Last active May 2, 2017 10:29
Some useful css snippets
/*
* Apply a transparent gauze to the bottom of a truncated, "read-more" section.
*/
.comment-body-view.truncated:after {
background: linear-gradient(to top, #eee, rgba(238,238,238,0));
bottom: 0;
content: "";
height: 50px;
left: 0;
position: absolute;
@bhuvidya
bhuvidya / yiic_frontend.php
Last active May 14, 2016 08:40
Set environment for Craft CMS console application/plugin. The following php script is put in a directory like $WEBSITE_ROOT/utils.
<?php
/**
* a front end for yiic.php that looks for env on cmdline and sets CRAFT_ENVIRONMENT
* accordingly. I put this script in a folder called "utils" in the root of my website
* install. So instead of doing something like
* php $root/craft/app/etc/console/yiic.php plugin cmd
* you would call
* php $root/utils/yiic_frontend.php --env=envname plugin cmd
* where "envname" is the config environment you wish to use.
@bhuvidya
bhuvidya / cool-laravel-resources.md
Last active May 7, 2016 03:14
This gist lists all the best Laravel resources I've come across.

Cool Eloquent Query/Model Stuff

I use Eloquent ORM in Laravel apps. I am torn between raw SQL (where you have a lot of power) and using an ORM, but a lot of times you can kinda walk a tightrope between the two. This gist is a way of collecting cool, more unusual Eloquent query techniques and tips and tricks.

updateOrCreate()

insert a new row or update an existing one in one statement. updateOrCreate takes two params, an array of attributes to search table on, and then an array of values to set if an existing record is found

Model::updateOrCreate([ 'user_id' => $user->user_id ], [ 'name' => 'bob' ]);

Cool MySQL Query Stuff

This gist is a way of collecting cool, more unusual MySQL query techniques and tips and tricks.

ifnull()

use this to convert column values to more useful defaults if they are null. can be used in formulas, order by etc.

in this example, using ifnull() avoids sums using columns that have null values ending up as null

@bhuvidya
bhuvidya / diceware_passwd.sh
Created March 9, 2016 08:00
dice ware word generator
#!/bin/bash
# see https://blog.agilebits.com/2011/06/21/toward-better-master-passwords/
# and http://world.std.com/~reinhold/diceware.wordlist.asc
DICEWARE_STASH_FILE=~/tmp/diceware.txt
WORDS=$1
[[ "$WORDS" == "" ]] && WORDS=5