This file contains hidden or 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 CommentsController < ApplicationController | |
before_filter :find_user, :find_entry, only: :create | |
def create | |
@comment = @user.comments.new(params[:comment]) | |
@comment.entry = @entry | |
@comment.save | |
respond_with @comment | |
end |
This file contains hidden or 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 'net/ftp' | |
threads = [] | |
# creating threads | |
4.times { |i| | |
threads << Thread.new(i) { | |
while path = paths.shift | |
puts "uploading: #{path}" | |
ftp = Net::FTP.new("{host}") | |
ftp.passive = true; ftp.binary = true | |
ftp.login("{username}", "{password}") |
This file contains hidden or 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
# references_and_referenced_in_many :players, :class_name => 'User' | |
a.players = User.limit(5).to_a; a.save! # validation failed | |
a.player_ids = User.limit(5).map(&:id); a.save! # saves |
This file contains hidden or 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
app.get '/', (req, res) -> | |
if req.session.user_id | |
User.findById req.session.user_id, (err, user) -> | |
res.render 'dashboard.ejs', {user: user} | |
else if session_user = req.session.user | |
if twitter = session_user.twitter | |
User.findOne {twitter: twitter.id}, (err, user) -> | |
unless user | |
user = new User({realname: twitter.name, nickname: twitter.screen_name, twitter: twitter.id}) | |
user.save() |
This file contains hidden or 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
# | |
# (c) 2008 you_katan | |
# | |
class Brainfuck | |
SIZE = 100 | |
def initialize(src, data = '') | |
@src = src | |
@table = Array.new(SIZE, 0) |
This file contains hidden or 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 Timeline | |
attr_reader :data | |
def initialize(order) | |
@order = order | |
@dt = @[email protected]_to | |
end | |
def create_reports! | |
load_data(:channel_id => @order.channel_id, :video_id => @order.video_id) |
This file contains hidden or 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
# display duration with ffmpeg | |
ffmpeg -i $1 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// |
This file contains hidden or 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
function serialize_form(formid) | |
{ | |
arr = $('#' + formid).serializeArray(); | |
obj = {} | |
for (var i = 0; i < arr.length; i++) | |
{ | |
attr = arr[i] | |
obj[attr['name']] = attr['value'] | |
} | |
return obj |
This file contains hidden or 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
# grab video cache | |
cd ~/.cache/google-chrome/Cache | |
for file in $(ls) | |
do | |
if head $file | grep 'FLV' | |
then | |
cp $file ~/Video | |
fi | |
done |
This file contains hidden or 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
# export diff | |
export_dir="../export" | |
mkdir -p $export_dir | |
for file in $(svn diff --summarize -r$1:$2) | |
do | |
if [ -f $file ] | |
then | |
dirname=${file%/*} |