2014年12月30日火曜日

Python: Use MySQL

mysql.connector

↓mysql.connector
http://dev.mysql.com/downloads/connector/python/

$ python
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
c>>> cnx = mysql.connector.connect(user='☆☆☆' , password='☆☆☆', host='☆☆☆', database='☆☆☆' )
>>> cnx.close()



Python: Import to Rails DB.

wrote by python.

 81 d = datetime.datetime.today()
 82
 83 i = 0
 84 for data in line:
 85      if gi.record_by_name(data["IPADDRESS"]) != None:
 86         i = i+1
 87         ipaddress = data["IPADDRESS"]
 88         latitude = gi.record_by_name(data["IPADDRESS"])["latitude"]
 89         longitude =  gi.record_by_name(data["IPADDRESS"])["longitude"]
 90
 91         add_RemoteData = ( "INSERT INTO geoips "
 92                 "(created_at,updated_at,ipaddress,latitude,longitude) "
 93                 "VALUES(%s,%s,%s,%s,%s)")
 94         data_RemoteData = ( d, d, ipaddress, latitude, longitude )
 95         cursor.execute(add_RemoteData,data_RemoteData)

Tor Exit Node

Tor Exit Node .




https://hhoshina.info/map/index

Rails: Passenger ver.4.0.56

When running Passenger under Ruby 2.2, the following error occurs:
   passenger_native_support.so: undefined symbol: rb_thread_blocking_region
There have probably been large changes with regard to thread handling. 

https://github.com/phusion/passenger/issues/1314  

2014年12月28日日曜日

Ruby: version 2.2.0 Released !

 Ruby ver 2.2.0 installed.

$ sudo ☆☆☆ install libffi-devel
$ gem source --add https://tokyo-m.rubygems.org/

$ git clone https://github.com/rubygems/rubygems
$ cd rubygems
$ sudo ruby setup.rb
$ gem -v
2.4.5

$ cd /****/rbenv/plugins/ruby-build
$ git pull origin master

$ rbenv install --list
...
2.2.0
...
$ sudo  CONFIGURE_OPTS="--disable-install-rdoc --enable-shared" rbenv install 2.2.0
$ rbenv versions
$ sudo rbenv global 2.2.0
$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005)

$ sudo gem install bundler







2014年12月23日火曜日

Rails: rails_admin

rails_admin installed.





$ vim Gemfile
---
gem 'rails_admin'
---

$ bundle install
$ rails g rails_admin:install
$ rake db:migrate
$ vim config/routes.rb
 ----
  2   devise_for :admin_users
  3   mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
 ---

Japanese
https://gist.github.com/mshibuya/1662352#file-rails_admin-ja-yml

2014年12月21日日曜日

Rails: UpGrade

Ruby on Rails Upgrade.


$ gem install rails --no-ri --no-rdoc                                    

$ vim Gemfile

$ bundle update

$ bundle install

$ bundle exec rake rails:update

     overwrite...
   routes.rb [no]
      application.rb [no]
      secrets.yml [no]
      production.rb [no]
      bin/rails [Yes]
      bin/rake [Yes]

$bundle exec rspec spec/

Rails: ver.4.2.0 release

development server

$ rails s -b 0.0.0.0

2014年12月13日土曜日

2014年12月6日土曜日

Ruby On Rails: Basic Auth

    def basic_auth
             authenticate_or_request_with_http_basic do |user,pass|
                  user = "☆☆" && pass == "☆☆"
              end
     end


2014年12月2日火曜日

Ruby On Rails: API Create

API Created.

$ cat app/controllers/application_controller.rb
......
protect_from_forgery with: : null_session
......

$ cat  ☆☆_controller.rb
...... 
  def ☆☆_params
   #params.require(:☆☆).permit(:☆☆, :☆☆)
   params.permit(:☆☆, :☆☆)
  end
...... 



2014年11月29日土曜日

"Country of Tor ipaddress" takes time.

"Country of Tor ipaddresses" takes time.

$ time ./GeoIP-Tor-stdout
{"A1":3,"AE":4,"AR":9,"AT":91,"AU":37,"AX":1,"BA":2,"BE":20,"BG":20,"BR":22,"BY":2,"CA":115,"CH":86,"CL":5,"CO":4,"CR":1,"CY":1,"CZ":69,"DE":1272,"DK":39,"EC":1,"EE":8,"EG":3,"ES":26,"FI":61,"FR":342,"GB":222,"GR":17,"HK":21,"HR":7,"HU":35,"ID":1,"IE":14,"IL":17,"IN":10,"IR":6,"IS":24,"IT":54,"JE":1,"JP":66,"KH":1,"KR":12,"KY":1,"KZ":3,"LC":1,"LT":14,"LU":19,"LV":7,"MD":4,"MK":1,"MN":2,"MT":2,"MX":9,"MY":1,"NL":355,"NO":36,"NZ":11,"PA":5,"PL":50,"PT":10,"QA":1,"RO":37,"RS":4,"RU":208,"SA":5,"SE":177,"SG":11,"SI":1,"SK":20,"TH":5,"TN":1,"TR":6,"TW":10,"UA":61,"US":1383,"UY":1,"VE":1,"VN":3,"ZA":3}

real 0m41.711s


2014年11月28日金曜日

Tor Nodes

Communication Carrier of Tor "exit-address" Nodes.
at 2014/11/28

$ grep 'Edition' tor-ip.country | grep "AT&T" | wc
     28  
grep 'Edition' tor-ip.country | grep "NTT" | wc
     14  
$ grep 'Edition' tor-ip.country | grep "KDDI" | wc
     39  
$ grep 'Edition' tor-ip.country | grep "Softbank" | wc
      4    
$ grep 'Edition' tor-ip.country | grep "Google" | wc
      5  



2014年11月26日水曜日

GoLang: ssl client

 ssl client .
POST Method.

convert Integer to String and put Temper Data to https server.


 54 func PostData(Temp int) {
 55     tr := &http.Transport{
 56         TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
 57     }
 58     client := &http.Client{Transport: tr}
 59
 60     resp, err := client.PostForm(
 61         "https://☆☆☆☆.asp",
 62         url.Values{"☆☆": {strconv.Itoa(Temp)},
 63             "☆☆": {"☆☆"},
 64         })
 65     body, err := ioutil.ReadAll(resp.Body)
 66     resp.Body.Close()
 67
 68     fmt.Println(string(body), err)
 69 }




2014年11月25日火曜日

GoLang: GeoLocation Code


 41 func GeoIP_calc(ip string) string {
 42     var country string = ""
 43
 44 
 45     file := "GeoIP.dat"
 46 
 47     gi, err := geoip.Open(file)
 48     if err != nil {
 49         fmt.Printf("Could not open GeoIP database\n")
 50     }
 51 
 52     if gi != nil {
 53         country, _ = gi.GetCountry(ip)
 54     }
 55 
 56     return country
 57 }

GoLang: Alert

・funcに切り出した場合、関数の頭で定義(var, :=)しておく必要がある。
 しないと undefined: **** コンパイルエラーになる。

・連想配列には、MAPを使う。
      test := map[string]int{
          "a: 0,
       }



  

2014年11月24日月曜日

Go Lang Test

Go Lang  Test!


$ cat hello.go
package main

import "fmt"

func main() {
fmt.Printf("hello world\n")
fmt.Printf("hella.asdf\n")
fmt.Printf("hella.asdf\n")
}


$ go run hello.go
hello world
hella.asdf
hella.asdf

$ go bulid hello.go
$ ./hello
hello world
hella.asdf
hella.asdf

Spree Install

Rails EC Site / Spree Install Memo.

$ gem install spree_cmd
$ rails new ecsite
$ cd ecsite
$ spree install --auto-accept
$ rake db:migrate 
$ rake assets:clean 
$ rake assets:precompile

fd-find

 $ sudo apt install fd-find $ fdfind 石