This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init_num=0 | |
init() { | |
init_num=$(expr $init_num + 1) | |
if [[ "$init_num" -le "9" ]]; then | |
read -p "Uni:00$init_num> " input | |
elif [[ "$init_num" -ge "10" ]] && [[ "$init_num" -le "99" ]]; then | |
read -p "Uni:0$init_num> " input | |
elif [[ "$init_num" -ge "100" ]] && [[ "$init_num" -le "999" ]]; then | |
read -p "Uni:$init_num> " input | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Gemfile | |
gem "redis" | |
gem "redis-rails", "~> 3.2.1.rc" | |
### app/controllers/sessions_controller.rb | |
def create | |
user = User.where(email: params[:email]).first | |
# 'authenticate' comes from the 'has_secure_password' method in the User model | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id # Set a session from the id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
time = Time.new(2012,5,1,10,30) | |
date = DateTime.parse(time.to_s) | |
puts date | |
#=> 2012-03-02T10:30:00-05:00 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###I'm trying to get Ajax working for my sign in forms, but I can't get it work. It literally does nothing! | |
###Here's my controller | |
def create | |
session[:user_id] = nil if session[:user_id] # Destroy any current sessions | |
user = User.where(email: params[:email]).first | |
respond_to do |format| | |
if !params[:bot].blank? | |
# If the bot hidden field has a value, assume it's a bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before role inheritance | |
class User < ActiveRecord::Base | |
attr_accessible :fname, :lname, :email, :password, :password_digest | |
attr_accessible :fname, :lname, :email, :password, :password_digest, :admin, :as => :admin | |
end | |
# After role inheritance | |
class User < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Original | |
attr_accessible :name, :email | |
attr_accessible :name, :email, :location, :as => :location | |
attr_accessible :name, :email, :location, :admin, :as => :admin | |
# OR | |
# Tenderlove style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Options for ZSH | |
HISTFIL=~/.zshhist | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
setopt autocd | |
setopt appendhistory | |
unsetopt beep | |
bindkey -e # eval "$(sed -n 's/^/bindkey /; s/: / /p' /etc/inputrc)" | |
zstyle :compinstall filename '/home/larz/.zshrc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MemePoster is the fastest way to get Hungry Academy Memes out to the world! | |
// | |
// post <image url> - puts an image on hungryacademymemes.com | |
var http = require('http') | |
, response | |
, options | |
, request; | |
module.exports = function(robot) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class DateTime | |
def to_human(opts = {}) | |
date = self | |
today = opts[:today] || DateTime.now | |
# Difference between `today` and `date` | |
diff = (date.to_date - today.to_date).to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
find . | grep "\[" | while read file; do | |
oldfile=$(readlink -f "$file") | |
echo "$oldfile" | |
newfile=$(echo "$oldfile" | sed 's/[^/A-Za-z0-9_ ]//g') | |
newfile=$(echo "$newfile" | sed 's/[ *]/_/g') | |
echo "$newfile" | |
mv "$oldfile" "$newfile" | |
done |
OlderNewer