Skip to content

Instantly share code, notes, and snippets.

@raecoo
raecoo / controller
Last active December 11, 2015 07:19
How to use PubSub(https://gist.github.com/661855) with Spine
class App.TaskItemController extends Spine.Controller
className: 'task-entry'
events:
'submit form.new-todo' : 'createTodo'
constructor: ->
super
@item.bind("destroy", @destroy)
@raecoo
raecoo / mongo-commands
Created January 31, 2013 12:24
Mongo commands
mongo <dbname> --eval "db.dropDatabase()"
/*
This script is for updating the auto_increment field by an offset. The logic applied is
max(AUTO_INCREMENT) + current value in the table.
*/
SET @db:='id_new';
select @max_id:=max(AUTO_INCREMENT) from information_schema.tables;
select concat('update ',table_name,' set ', column_name,' = ',column_name,'+',@max_id,' ; ') from information_schema.columns where table_schema=@db and column_name like '%id' into outfile 'update_ids.sql';
@raecoo
raecoo / all-channels.xml
Last active December 12, 2015 02:48
sample xml template
<!-- all channels(approved) of the platform -->
<?xml version="1.1" encoding="UTF-8"?>
<channels>
<channel>
<name>网星电视</name>
<icon></icon>
<url>http://rokucndev.s3.amazonaws.com/channel-v.xml</url>
</channel>
</channels>
@raecoo
raecoo / monit-example.txt
Last active October 26, 2022 06:24
Monit (http://mmonit.com/monit/) script example
set daemon 20
set logfile syslog facility log_daemon
set mailserver smtp.gmail.com port 587
username "ERROR-EMAIL-ADDRESS" password "PASSWORD"
using tlsv1
with timeout 30 seconds
set alert ERROR-EMAIL-ADDRESS
set httpd port 2812 and
@raecoo
raecoo / Guardfile.rb
Created April 2, 2013 02:18
JavaScript test suites for Rails project based on Jasmine with Sinon.JS.
guard 'jasmine', :timeout => 30000 do
watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js|coffee)$}) { |m| puts m.inspect; "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/spec(_helper)?\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
watch(%r{spec/javascripts/support}) { "spec/javascripts" }
end
@raecoo
raecoo / chinese-chars-regex.rb
Last active December 18, 2015 11:58
Chinese chars via Regex
str =~ /\p{Han}+/u
@raecoo
raecoo / email-available.coffee
Last active December 20, 2015 04:08
Email Available directive for AngularJS
angular.directive "emailAvailable", ($http, $timeout) ->
require: 'ngModel'
link: (scope, elem, attrs, ctrl) ->
console.log ctrl
# push the validator on so it runs last.
ctrl.$parsers.push (viewValue) ->
# set it to true here, otherwise it will not
# clear out when previous validators fail.
ctrl.$setValidity "emailAvailable", true
if ctrl.$valid
@raecoo
raecoo / dailymotion_parser.rb
Last active December 25, 2015 01:19
Dailymotion Url parser
class DailymotionParser
URLS = [
/^.+dailymotion.com\/(video|hub)\/([^_]+)([^#|^?]*)(#video=([^_&]+))?/
]
def self.parse url
case url
when URLS[0]
match_data = url.match(URLS[0])
@raecoo
raecoo / facet.rb
Last active December 25, 2015 04:19
Elasticsearch response
facets: {
"brand_id" :{
"_type"=>"terms",
"missing"=>46573,
"total"=>63247,
"other"=>1027,
"terms"=>[
{"term"=>"14", "count"=>33889},
{"term"=>"10", "count"=>23961},
{"term"=>"37", "count"=>1044},