Skip to content

Instantly share code, notes, and snippets.

@kevinclcn
kevinclcn / gist:2b5895f7f1910a2c180f
Last active August 29, 2015 14:13
Dockerfile for rails on ubuntu 14.04 rvm
FROM ubuntu:14.04
MAINTAINER kevinclcn@gmail.com
ENV https_proxy <https proxy>
ENV http_proxy <http proxy>
ENV LANG en_US.UTF-8
RUN apt-get -qy install git curl
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 && curl -sSL https://get.rvm.io | bash -s stable
@kevinclcn
kevinclcn / docker.md
Last active September 4, 2015 06:50
docker introduction

Install docker on Ubuntu 14.04

$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh

source

Set http proxy for docker

# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
class Fixnum
@kevinclcn
kevinclcn / scope gate.md
Last active August 29, 2015 14:26
Ruby作用域

局部变量,实例变量,self都是绑定在对象上的名字,我们简称为绑定(binding)。所有绑定都有一个寄居场所,我们称为作用域(scope)。假设你是一个调试器,你时刻都处于一个作用域中,上下左右都是绑定: 局部变量,实例变量,全局变量,常亮,还有当前对象self。只有当你遇到三个关键字时,才会进入一个新作用域。

这三个改变作用域的关键字, 分别是module,classdef。我们称为作用域的门(scope gate)。

在Java等其他语言里,一个作用域内可以看到外围作用域内的变量,但Ruby不同,一个作用域内只能看到当前作用域内的变量。也就是说,变量不能跨作用域查找。

比如:

@kevinclcn
kevinclcn / ruby variables.md
Last active August 25, 2022 08:21
global variable, class variable, class instance variable, instance variable, local variable

Global variable

全局变量以$开头,它是全局可见的。Ruby内建的全局变量如$:$LOAD_PATH表示require读取文件时寻找的目录数组。

Class variable

类变量以@@开头,可被定义它的类以及其子类访问,也可被定义它的类和子类的实例访问。

class Example
 @@cls_var = "defined in Example"
@kevinclcn
kevinclcn / README.md
Last active August 26, 2015 14:02 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default and default-ssl to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@kevinclcn
kevinclcn / gist:d9855da3fb8368f02800
Last active September 14, 2015 14:01 — forked from javiervidal/gist:1433880
To access url helpers (url_for, etc) from Rails console (Rails 3)
include Rails.application.routes.url_helpers
default_url_options[:host] = "localhost"
@kevinclcn
kevinclcn / curl.md
Last active September 18, 2015 01:36 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@kevinclcn
kevinclcn / CacheConfig.java
Created February 16, 2016 14:37 — forked from anataliocs/CacheConfig.java
Guava cache with spring boot and clear cache method
import com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
@kevinclcn
kevinclcn / CacheConfig.java
Created February 16, 2016 14:45 — forked from snicoll/CacheConfig.java
Guava cache with spring boot and clear cache method
import com.google.common.cache.CacheBuilder;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
@Configuration