sugi1119
On the way to become a WEB Developer
78 posts
This is my journey to become a Web Developer.
Don't wanna be here? Send us removal request.
sugi1119 · 6 years ago
Text
Swift - Day 6
Today, I learned: get & set
import UIKit class NamedShape {     var numberOfSides: Int = 0     var name: String
    init(name: String) {
       self.name = name
   }
   func simpleDescription() -> String {
       return "A shape with \(name) sides."
   }
}
class Square: NamedShape{
   var sideLength: Double
   init(sideLength: Double, name: String){
       self.sideLength = sideLength
       super.init(name: name)
           numberOfSides = 4
   }
   func area() -> Double {
       return sideLength * sideLength
   }
   override func simpleDescription() -> String {
       return "A square with sides of length \(sideLength)."
   }
}
class EquilateralTriangle: NamedShape{
   var sideLength: Double = 0.0
   init(sideLength: Double, name: String) {
       self.sideLength = sideLength
       super.init(name: name)
           numberOfSides = 3
   }
   var perimeter: Double {
       get {
           print("this is inside of get perimeter \(3.0 * sideLength) and \(name)")
           return 3.0 * sideLength
       }
       set {
           print("this is after get and inside of set perimeter \(sideLength)")
           sideLength = newValue / 3.0
       }
   }
   var getOnlyPerimeter: Double {
       print(3.0 * sideLength)
       return 3.0 * sideLength
   }
   func testComputedProperty() {
       // Set the perimeter        perimeter = 12.0
       // Get perimeter       print("perimeter getter: ", perimeter)
   }
   override func simpleDescription() -> String {
       return "An equilateral triangle with sides of length \(sideLength)"
   }
}
class TriangleAndSquare {
   var triangle: EquilateralTriangle {
       willSet {
           square.sideLength = newValue.sideLength
       }
   }
   var square: Square {
       willSet {
           triangle.sideLength = newValue.sideLength
       }
   }
   init(size: Double, name: String) {
       square = Square(sideLength: size, name: name)
       triangle = EquilateralTriangle(sideLength: size, name: name)
   }
}
var triangleAndSquare = TriangleAndSquare(size: 5, name: "another test shape")
print(triangleAndSquare.square.sideLength)
//output is 5
triangleAndSquare.triangle.testComputedProperty()
//call get and set
<output> 5.0 this is after get and inside of set perimeter 5.0 this is inside of get perimeter 12.0 and another test shape perimeter getter:  12.0
0 notes
sugi1119 · 6 years ago
Text
Swift Day 5
What is “let”
EXPERIMENT
Add a constant property with let, and add another method that takes an argument.
class Shape {
   var numberOfSides = 0
   func simpleDescription() -> String {
       return "A shape with \(numberOfSides) sides."
   }
}
I added a constant property like this: 
class Shape {    var numberOfSides = 0    let mynumber = 2    func sumpleDescription() -> String {      return "A shape with \(numberOfSides) sides."  }
   func anotherMethod() -> String { // Swift does not accept “var”.  x var check, ok let check
       let check = numberOfSides * mynumber         return "Also, you can see \(check) sides."    }
}
var shape = Shape() shape.numberOfSides = 7 var shapeDescription = shape.sumpleDescription() var anotherOne = shape.anotherMethod()
So, what is “let”...
ref: https://stackoverflow.com/questions/24002092/what-is-the-difference-between-let-and-var-in-swift
“let” is const in C++, C.  The compiler does not check the value of let. Once, assign the value on let, the value does not change. (We cannot change). 
0 notes
sugi1119 · 6 years ago
Text
Swift  Day 4
Keep continuing docs.swift.org according to the instruction of Stanford Uni’s swift course. 
Today, I learned - functions and closures
To check the number is odd or even, I use % (module).  number % 2 == 0 is even, number % 2 == 1 is odd.
Tumblr media
0 notes
sugi1119 · 6 years ago
Text
Swift  Day 3
I am still reading docs.swift.org/ A swift tour. 
Today I learned... yes, still “string”! 
Tumblr media
import UIKit var optionalString: String? = "Hello"
//boolean print(optionalString == "Hello") var optionalName: String? = "John" var greeting = "Hello!" var greeting2 = "Hi!"
if optionalName != nil { greeting = "Hello, \(String(describing: optionalName))" greeting2 = "Hi! \(optionalName ?? "") print(greeting) print(greeting2) print("Name is \(optionalName as String?)") }
<output> true Hello, Optional("John") Hi! John Name is Optional("John")
“If the optional value is nil, the conditional is false and the code in braces is skipped. Otherwise, the optional value is unwrapped and assigned to the constant after let, which makes the unwrapped value available inside the block of code. Another way to handle optional values is to provide a default value using the ?? operator. If the optional value is missing, the default value is used instead.“ (Reference:  docs.swift.org)
Another thing, I learned today is: whitespace is important. 
when I wrote like this: 
Tumblr media
Swift requests to write consistent whitespace. So, this codes, just need to adjust the whitespace. (Wao, no error!)
Tumblr media
0 notes
sugi1119 · 6 years ago
Text
Swift Day 2
Still, continue to follow Stanford uni’s course. 
Today, I follow up the Reading Assignment 1: Intro to Swift and 1 of the reading: https://docs.swift.org/swift-book/index.html
I like this one!  Multiline string!! 
import UIKit
let apples = 3 let oranges = 5 let quotation = """
Even though there's whitespace to the left, the actual lines aren't intended. Except for this line. Double quotes (") can appear without being escaped. I still have \(apples + oranges) pieces of fruit.
"""
print(quotation)
<print> 
Even thogh there's whiteshapce to the left, the acutual lines aren't intended. Except for this line. Double quotes (") can appear without being escaped. I still have 8 pieces of fruit.
0 notes
sugi1119 · 6 years ago
Text
Swift - Day1
I wanted to learn something new!  So I picked up Swift. 
Swift meetup members are recommended me to follow the iTunes course:  Developing iOS11 app with Swift.  Any person if they have iPhone or iPad, they can access the course via iTunes U (http://itunes.stanford.edu/).  I only can access to my MacBook, so I picked up the course using iTunes (https://itunes.apple.com/us/course/developing-ios-11-apps-with-swift/id1309275316)
I started from 0: install Xcode and open it.  Xcode has test code function called Playground.  But, in this tutorial, we will create an Xcode project. 
Firstly, I am so impressed with how nice Xcode has UI view called Storyboard. So, I do not need to open localhost.  Storyboard let us add objects such as buttons, texts, labels, slider, and more. 
I really like the Xcode. For example, we can easily assign function: a code to UI interface: such as a button.  Use control key, easy to connect those two. (Amazing...) 
What I learned today: 
iOS consists of 4 layers:  iOS is Unix. 
<top - user interface>
Cocoa Touch  - UI layer 
Media - iPhone comes from iPad (I forgot it! Yes, iPad was there before.)
Core Services - focus on this course.
Core OS   - Most in C / because iOS is Unix
<bottom>
I do not have iPhone, iPad, but there is a tool called Instruments. So, I can see the interface using the simulator.  (Cool!)
Language: Swift / Object C 
iOS Frameworks: a collection of objects. 
The biggest one is UIKit: Button, sliders and so on. 
Foundation: services
more: core data, core motion, map kit
The design strategy is MVC (Model, View, Control) - this is a kind of familiar, Ruby on Rails is also using MVC. 
Object = Button inheritance of Control, Control inheritance of  View. 
//Import UIKit - iOS's framework
//Declaration of class
//ViewController is class name
//: UIViewController is super class.
//UIViewController is from UIKit
import UIKit
class ViewController: UIViewController {
   var flipCount = 0 {
       didSet {
           flipCountLabel.text = "Flips: \(flipCount)"
       }
   }
}
//method, instance variables are here //@IBAction is not swift method. this is special directive Xcode created.    //Type of the argument comes with the end with collon:, every auguments has name of parameter (: UIButton)     // sender is the name of parameter (_ shows no argument)     //Every argument has name that is include which called method. External name, internal name     //Allow function -> Return value
// \( ) means interpret inside of () as string// right click on UI to show which one connects to which one
//const is let
0 notes
sugi1119 · 7 years ago
Text
How to open Sublime Text 3 from terminal
I have upgraded Sublime Text version from 2 to 3 and lost the function to open Sublime text from the command line (subl .). 
Reference: 
https://www.sublimetext.com/docs/3/osx_command_line.html
https://stackoverflow.com/questions/16199581/open-sublime-text-from-terminal-in-macos
In my case, I already created ~/.profile before.  So, simply open it with open ~/.bash_profile and paste & saved. 
export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH export EDITOR='subl -w'
After that execute the lines with source ~/.bash_profile
Thank you, stackoverflow!
0 notes
sugi1119 · 7 years ago
Text
Today’s feeling
Tumblr media
0 notes
sugi1119 · 7 years ago
Text
How to fix the anchor link position with fixed header
When a fixed header has used on the website, some anchor link position may not be correctly linked.
In this case, we just simply need CSS hack. 
For example: 
fixed header height: 100px; 
html
<header>
----fixed header contents
</header>
<div class=“contents1”>     <p>ABC<a href=“#def_link”>DEF</a>for something.</p> </div>
<div class=“contents2″ id=“#def_link”>    <p> link from DEF.</p> </div>
css
#def_link{       margin-top: -100px;       padding-top: 100px;  }
0 notes
sugi1119 · 8 years ago
Text
Another way to manage node.js and npm: use nodebrew
I changed the way to manage node.js and npm with nodebrew. 
reference: https://github.com/hokaccha/nodebrew
Will see how it goes...
0 notes
sugi1119 · 8 years ago
Text
npm install npm@latest -g
Clean up and update for new year!  This is a magical input to update npm to fix up of “WARN deprecated” ones 
For this holiday season, I want to make a small app. 
After downloaded the zip file from github and installed gulp, then I faced the warning messages as below:
$ npm install -g gulp npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
I updated minimatch & graceful with below commands: 
$ npm install -g npm@3 /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js [email protected] /usr/local/lib/node_modules/npm
$ npm -v minimatch 3.10.10
Same things had done to update graceful.  However, when re-installed gulp, the same error messages were appeared again. 
npm is still using old version of minimatch & graceful. 
So, it needs to update npm itself. 
$ npm install npm@latest -g
Then, re-do the comand for install gulp with $ npm install -g gulp, successfully installed gulp. 
/usr/local/lib └─┬ [email protected]  ├── [email protected]  ├── [email protected]  ├── [email protected]  ├─┬ [email protected]  │ ├── [email protected]  │ └── [email protected]  ├─┬ [email protected]  │ ├─┬ [email protected]  │ │ ├─┬ [email protected]  │ │ │ ├── [email protected]  │ │ │ ├── [email protected]  │ │ │ ├── [email protected]  │ │ │ ├── [email protected]  │ │ │ └── [email protected]  │ │ └── [email protected]  │ ├─┬ [email protected]  │ │ ├─┬ [email protected]  │ │ │ └── [email protected]  │ │ └── [email protected]  │ ├─┬ [email protected]  │ │ └── [email protected]  │ ├── [email protected]  │ ├── [email protected]  │ ├── [email protected]  │ ├── [email protected]  │ ├── [email protected]  │ └─┬ [email protected]  │   ├─┬ [email protected]  │   │ ├── [email protected]  │   │ ├── [email protected]  │   │ ├── [email protected]  │   │ ├── [email protected]  │   │ └── [email protected]  │   └── [email protected]  ├─┬ [email protected]  │ └─┬ [email protected]  │   └─┬ [email protected]  │     └── [email protected]  ├─┬ [email protected]  │ └─┬ [email protected]  │   └─┬ [email protected]  │     ├── [email protected]  │     └─┬ [email protected]  │       ├─┬ [email protected]  │       │ └── [email protected]  │       └─┬ [email protected]  │         └── [email protected]  ├─┬ [email protected]  │ └─┬ [email protected]  │   ├── [email protected]  │   └─┬ [email protected]  │     ├── [email protected]  │     └─┬ [email protected]  │       └── [email protected]  ├── [email protected]  ├─┬ [email protected]  │ ├── [email protected]  │ ├── [email protected]  │ ├─┬ [email protected]  │ │ └─┬ [email protected]  │ │   └── [email protected]  │ ├─┬ [email protected]  │ │ └── [email protected]  │ ├── [email protected]  │ ├─┬ [email protected]  │ │ └── [email protected]  │ └── [email protected]  ├─┬ [email protected]  │ ├─┬ [email protected]  │ │ └─┬ [email protected]  │ │   ├── [email protected]  │ │   ├── [email protected]  │ │   └── [email protected]  │ └── [email protected]  └── [email protected]
0 notes
sugi1119 · 8 years ago
Text
MAMP -how to update mySQL version
I user WooCommerce for my client site and the plug-in require mySQL version from 5.6 
mySQL version is kept updating, but still the version is remained as 5.5.42 in MAMP environment. 
As per MAMP official blog: 
“Although MySQL 5.6 has been available since 2011 its market share is still much smaller than that of its older brother MySQL 5.5. That is why MAMP 3 and MAMP PRO 3 still bundle v5.5.”
But, this article is 2015 JUL, and still MAMP has default SQL version 5.5.42 I tried to several way to update mySQL version, but the most simple way is: just follow the steps of MAMP official blog link in below. 
reference: http://blog-en.mamp.info/2015/07/how-to-use-mysql-5-6-with-mamp-and-mamp.html
0 notes
sugi1119 · 9 years ago
Text
Today’s comment
Once you update Xcode... Don’t forget click “Agree”! 
0 notes
sugi1119 · 9 years ago
Text
Marketing tactics from Bidsketch
Received the first tactics from Ruben / Bidsketch. 
I agreed to him for: "Don’t waste time -- get straight to the point!” 
0 notes
sugi1119 · 9 years ago
Text
web design / think, talk, think and  talk
An opportunity is coming which make a web-site for a jewellery seller. 
This is the first time to create an official website for their business. I asked my friend to be my mentor who works as web designer for a long time. I respect her a lot. 
From my mentor advise: I need to find out the clients requirements. 
How they want to develop their business in future  What they want to do with their business Target users / customers Marketing  The selling items - characters/ price range  More and more...
From the above, find out website functions / interface design/ Logo/ theme colours/ font-face/ images ... etc. etc.
I had 2 long meeting with the clients and had a session with my mentor.  Now, the time to create, a proposal plan to submit the clients. 
0 notes
sugi1119 · 9 years ago
Text
Keep getting warning: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777
After rbenv installed, I tried to create my rails app. This warning keep turning up. 
When I type the command:    $rails g controller controllerName method_name
/Users/mypc/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/app_rails_loader.rb:39: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777 /Users/mypc/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/run.rb:68: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777 /Users/mypc/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777 /Users/mypc/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777
Also, this warning is appeared when type the command: $rails server
To resolve this issue: stackoverflow  (yes, always!) helped me! http://stackoverflow.com/questions/3952243/warning-insecure-world-writable-dir-usr-local-bin-in-path-mode-040777?lq=1
0 notes
sugi1119 · 9 years ago
Text
A Way to Keep update Ruby version  2) install rbenv
To update Ruby version, firstly I update RVM and then, found some article about rbenv. https://github.com/sstephenson/rbenv
With rbenv, change ruby version easily. Sounds nice. Since I always check the other people’s code to learn. 
Before install rbenv, need to uninstall RVM.  1.  $ rvm implode (some article says: $ rvm seppuku)   Seppuku!? 
2. rvm asks for re-confirm for uninstall. type “yes”
3. Then, below comment is appeared: 
“Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
Also make sure to remove `rvm` group if this was a system installation.
Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).”
Open text editor (I use sublime text to delete all .bashrc .bash_profile .profile and .zshrc for RVM source lines). 
Also, do:  $ rm -rf .rvm    $ rm -rf ./etc/rvmrc to remove RVM files. 
Now, all RVM related files, lines were removed. 
4. Install rbenv using brew  $ brew update (just in case. I already update/upgrade all brew before)  $ brew install rbenv ruby-build $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile (this command create path.)  $ rbenv install -l (check ruby install list)  $ rbenv install 2.2.3 (this is the current stable version)  5. To set default ruby version   $ rbenv global 2.2.3 (set version 2.2.3 as default version) 
6. To back system default to default   $ rbenv global system (back to system default 2.0.0) 
7. To set a specific version to the local directory  Under the local directory:  $ rbenv local 1.9.3-p448 
To unset local setting:  $ rbenv local --unset 
8. Uninstall ruby  $ rbenv uninstall 1.9.3-p448 
9. rehash plug-in  When instal new version of Ruby or gem package, rbenv require the command of “$ rbenv rehash”. This is too much to do every time. 
$ gem install rbenv-rehash  $ rbenv rehash (after install gem, only 1 time to do rehash)
or install plug-in  $ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash This plug in automatically do “rbenv rehash”! 
Reference: 
https://github.com/sstephenson/ruby-build#readme https://mattbrictson.com/rails-osx-setup-guide
http://niwatako.tips/20140819/article128.html (Japanese)  http://easyramble.com/change-ruby-manager-from-rvm-to-rbenv.html(Japanese) http://niwatako.tips/20140819/article128.html(Japanese)
0 notes