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
# 在服务器的nginx上添加配置 | |
upstream tunnel { | |
server 127.0.0.1:3000; | |
} | |
server { | |
listen 80; | |
server_name dev.example.com; | |
location / { |
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
def quick_sort(arr) | |
len = arr.length | |
return arr if len == 1 | |
old_index = 0 | |
x = arr[old_index] | |
if len == 2 | |
if arr[1] < x |
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
def bubble_sort(arr) | |
len = arr.length | |
(0..len).each do |i| | |
j = 0 | |
while j < len - i - 1 | |
if arr[j] > arr[j+1].to_i | |
x = arr[j] | |
arr[j] = arr[j+1] | |
arr[j+1] = x |
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
//Sprite mixin, works perfectly with standard defines | |
@mixin icons-sprite($sprite) { | |
background-image: sprite-url($icons); | |
background-position: sprite-position($icons, $sprite); | |
background-repeat: no-repeat; | |
overflow: hidden; | |
display: inline-block; | |
vertical-align: middle; | |
margin-right: 3px; | |
height: round(image-height(sprite-file($icons, $sprite))); |
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 Uploader < CarrierWave::Uploader::Base | |
version :full do | |
process resize_to_fit: [960, 640] | |
process :set_color | |
end | |
def set_color | |
color = 'gold' | |
# convert old.png -alpha off -fill gold -colorize 100% -alpha on new.png |
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
#!/bin/bash | |
db=$1 | |
uploads=$(dirname $0)/../public/uploads | |
if [ ! -d $uploads ]; then | |
echo "Error: directory 'public/uploads' does not exist" | |
exit 1 | |
fi |
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
# access_token = "abcdefg123456hijklmn" | |
# curl -H "Authorization: OAuth abcdefg123456hijklmn" "https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0" | |
# https://developers.google.com/google-apps/contacts/v3/ | |
# https://developers.google.com/google-apps/contacts/v3/reference | |
# OAuth 2.0 Playground: https://developers.google.com/oauthplayground/ | |
# Get a contact photo: http://stackoverflow.com/questions/5983484/google-api-getting-a-contacts-photo | |
def contact_list | |
url = "https://www.google.com/m8/feeds/contacts/default/full" | |
response = HTTParty.get(url, | |
:query => {:alt => "json", :"max-results" => "100000000"}, |
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
Geocoder.coordinates("Shanghai, China") | |
=> [31.230393, 121.473704] | |
results = Geocoder.search('31.230393, 121.473704') | |
r = results.first | |
r.postal_code |
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
# Here comments are embedded_in letters | |
$ mongo | |
> db.letters.aggregate( | |
{ $unwind : "$comments"}, | |
{ $match: { "comments.created_at": { $gt: new Date('01/01/2012') } } }, | |
{ $group: { | |
_id : "$_id", | |
comment_count: { $sum : 1 } | |
} }, | |
{ $sort : { comment_count : -1 }}, |
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
$ mongo | |
> db.view_logs.aggregate( | |
{$match : {created_at : {$gt : new Date( "12/01/2012" )}}}, | |
{ $group : { | |
_id : "$loggable_id", | |
cc : { $sum : 1 }, | |
}}, | |
{ $sort : { cc : -1 }}, | |
{ $limit : 5 } | |
); |
NewerOlder