Skip to content

Instantly share code, notes, and snippets.

# grab video cache
cd ~/.cache/google-chrome/Cache
for file in $(ls)
do
if head $file | grep 'FLV'
then
cp $file ~/Video
fi
done
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
# display duration with ffmpeg
ffmpeg -i $1 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//
class Timeline
attr_reader :data
def initialize(order)
@order = order
@dt = @order.track_from..@order.track_to
end
def create_reports!
load_data(:channel_id => @order.channel_id, :video_id => @order.video_id)
@maliqq
maliqq / brainfuck.rb
Last active September 23, 2015 14:48
#
# (c) 2008 you_katan
#
class Brainfuck
SIZE = 100
def initialize(src, data = '')
@src = src
@table = Array.new(SIZE, 0)
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()
# 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
@maliqq
maliqq / gist:1616495
Created January 15, 2012 17:18
multithread FTP upload
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}")
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
#!/usr/bin/ruby
require 'webrick'
server = WEBrick::HTTPServer.new(
:Port => 10080,
:BindAddress => '0.0.0.0',
:DocumentRoot => "#{File.dirname(__FILE__)}/../"
)
trap 'INT' do server.shutdown end
server.start