Git: development Git gitignore productivity rm source control workflow
by bseanvt
leave a comment
Git Untrack Already Tracked Files
To remove files that are currently being tracked by git, you have to remove them from the “cache”. Note, doing this will NOT delete the file on your local machine. It will still be there but not be tracked.
git rm -r --cached supersecretpasswords.txt
You then need to add the file to the .gitignore file in the root of the project so that it isn’t tracked again on your next commit.
vim .gitignore supersecretpasswords.txt
.gitignore files are tracked so remember to check in these changes.
git commit -am'my super secret passwords are safe!'
If you want to completely delete the file, on your local machine and from git
git rm supersecretpasswords.txt
If you’re working with a directory remember to add the -r flag for recursive removal!
Ruby on Rails: active record activerecord birthdays cache counter datetime how to scopes timestamp
by bseanvt
leave a comment
Rails Find All by Birthday: How to Find Upcoming Birthdays with ActiveRecord
There are a few ways to solve this problem. However, I think the easiest is to cache the day of the year that the user is born on as an integer. If stored alongside the timestamp we can quickly get a list but properly handle the full birthday elsewhere, such as in the view. You don’t want to rely on just the cached day of year because leap year is not accounted for.
The model will need both born_at and birthday columns.
create_table :users do |t| t.timestamp :born_at # full timestamp t.integer :birthday # just the day of year end
The user model also needs a callback (before_save) to set and or update the cached birthday column based on the full timestamp. For convenience, a named scope can be added to the model which will let you call User.birthdays.
class User
# User.birthdays
scope :birthdays, lambda { where('birthday in(?)', 7.times.map{|i| Time.now.yday + i}) }
def before_save
self.birthday = born_at.yday
end
end
You could also use the week in year (1 – 52) for the cache. Using the day you can look an arbitrary number of days ahead.
Git: branching errors fixes Git how to invalid workflow
by bseanvt
leave a comment
Git: How to Delete a Branch with an Invalid Name
If you’ve named a branch beginning with two dashes “–”, you’re sort of in trouble because git interprets your branch name as a switch/flag. You can skip switches all together
by supplying two dashes before your branch name
git branch -d -- --index_for_suppliers
and your branch will be deleted!
Git: commit Git hard head reset source control workflow
by bseanvt
leave a comment
How to Remove Your Last Git Commit
Remove your last commit (if you haven’t pushed yet)
git reset --hard HEAD~1
To see changes that have been committed and their position in HEAD
git reflog
And to undo your previous reset and advance the cursor to the reference immediately behind the current state
git reset --hard HEAD@{1}
If you have already pushed you can
git revert HEAD
which will reverse your last commit by creating a new commit
Databases Linux mysql: backups bash cron data MySQL mysqldump scripting shell
by bseanvt
leave a comment
Backup and Rotate MySQL Databases Simple Bash Script
Make a directory ( it can anywhere ) called baks/mysql
mkdir -p /baks/mysql
Create a file (it can be anywhere) called /root/mysql_backups.sh and put this script in it
#!/bin/bash # modify the following to suit your environment export DB_BACKUP="/baks/mysql" export DB_USER="root" export DB_PASSWD="your-mysql-password-goes-here" # title and version echo "" echo "Backup and rotate all mysql databases" echo "--------------------------" rm -rf $DB_BACKUP/04 mv $DB_BACKUP/03 $DB_BACKUP/04 mv $DB_BACKUP/02 $DB_BACKUP/03 mv $DB_BACKUP/01 $DB_BACKUP/02 mkdir $DB_BACKUP/01 echo "* Creating backup..." mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2 echo "----------------------" echo "Done" exit 0
Install it via cron and have it run at 3:10 am every morning.
crontab -e 10 3 * * * /root/mysql_backups.sh > /baks/status.log
This script will save the last 4 days of data.
Ruby Rand Range
I assumed that rand would take a range as an argument. Something like rand(10..20), generating a random number between 10 and 20. Seems like you’d do this fairly often when working with random numbers and therefore, included. However, it doesn’t work. But the solution is almost as easy.
10 + rand(11) #=> produces a random number between 10 and 20
Since rand starts at 0 (like array indexes), we need to add an extra 1 to get what we’re expecting.
Design Front End Development: color design prototyping resources ux wireframing xdd
by bseanvt
leave a comment
Free Online Design Tools and Resources for Programmers
I’m a programmer. At least I want to be. But the reality of web development requires wearing multiple hats. This includes from time to time, working on design. After all what is a web app if it is poorly designed? Both UI and aesthetics are important from customer/user perspective.
Fortunately, there are many great designers who are also developers (or who have developer friends) and they release cool tools to help out. So here is a list of resources I’ve found useful when wearing the designer hat.
http://0to255.com/ – when working with color
http://framebox.org/ – rapid prototyping and sharing
http://subtlepatterns.com/ – spice up the background with some subtle patterns
http://www.html-ipsum.com/ – lorem ipsum text wrapped in different html elements
http://placehold.it/ – placeholder image spaces
http://flickholdr.com/ – placeholder images from flickr
http://placekitten.com/ – turns any project into a success
http://www.copypastecharacter.com/ – copy and paste special characters/lookup
http://www.cssbuttongenerator.com/ – make nice css buttons
http://www.colorzilla.com/gradient-editor/ – css gradients
http://www.red-root.com/sandbox/holmes/ – clean up, css debugger
http://gridulator.com/ - make a grid layout
http://warpspire.com/talks/designhacks/ Not necessarily a tool, but a great presentation on design geared at developers


