Skip to content

Instantly share code, notes, and snippets.

View tedhagos's full-sized avatar

Ted Hagos tedhagos

View GitHub Profile
@tedhagos
tedhagos / virtualbox-vagrant-nuclear-option.sh
Created March 23, 2021 08:31 — forked from tjbenton/virtualbox-vagrant-nuclear-option.sh
Completely uninstall VirtualBox and Vagrant and reinstall through brew
# update brew because `brew update` is broken after updating to El Capitan
cd `brew --prefix`
git fetch origin
git reset --hard origin/master
sudo shutdown -r now # restart the computer
# open terminal and run the following
brew update
brew cleanup
@tedhagos
tedhagos / README.md
Created December 6, 2019 09:36
Sample node server app for Angular training

Installation

On the same folder where you will download 'app.js', do these things

npm init -y
npm install --save express cors
npm install -g nodemon
@tedhagos
tedhagos / README.md
Created December 19, 2018 01:13
Angular Routing
  1. Create an angular project, when asked for Angular routing support, say "YES"
  2. Create routes in app.module.ts
  3. Write the [routerLinks] in app.component.html
  4. Writer the in app.component.html
  5. Make sure there is a line in the head section of app.component.html
@tedhagos
tedhagos / README.md
Created December 18, 2018 03:37
http observable sample
  1. On the root module (app.module.ts)

    • import the HttpClientModule
    • put it in the imports section
  2. On the app.service.ts

    • import the HttpClient from @angular/common/http
    • Inject it in the constructor of the service
  3. In angular.json

  • Under architect > build > options > assets, add "src/api"
@tedhagos
tedhagos / app.component.html
Created December 18, 2018 03:32
observable sample
<h1>{{ title }}</h1>
<button (click)="subscribe()">
Subscribe
</button>
@tedhagos
tedhagos / README
Last active December 18, 2018 01:50
book sample with parent and child component
To create the project
ng new parentchild
ng g c childone
cd parentchild
npm install --save bootstrap
@tedhagos
tedhagos / app.component.html
Last active December 17, 2018 02:07
Guessing game exercise in Angular
<h1>{{ title }}</h1>
<strong>Can you guess a number betwee 1 to 100?</strong>
<p>
<input placeholder="type an integer" [(ngModel)]="guess">
</p>
<button (click)="guessTheNumber()">
Guess the number
</button>
<p></p>
@tedhagos
tedhagos / UseOfWhenInAndroid.kt
Created September 28, 2018 14:58
Using when in an Android app
class MainActivity : AppCompatActivity() {
val Log = Logger.getLogger(MainActivity::class.java.name)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Log.info("onCreateOptionsMenu")
@tedhagos
tedhagos / TypeErasure.kt
Created September 28, 2018 08:28
TypeErasure.Kt
// Warning, this code won't compile in Kotlin
// it has problemss. Can you spot which line won't compile?
fun main(args: Array<String>) {
val mlist = listOf(Programmer("Ted"), Tester("Steph")) // (1)
val mprogs = mlist.typeOf<Programmer>() // (2)
mprogs.forEach { // (3)
println("${it.toString()} : ${it.javaClass.simpleName}")
}
@tedhagos
tedhagos / reified_generics_kotlin.md
Last active September 28, 2018 08:14
How to reify generic type parameters in Kotlin

Let’s deal with the meaning of reify first. It means to make something real, and the reason we’re using reify and generics on the same statement is because of Java’s type erasure.

Type erasure means exactly what you think it means. Java, and Kotlin as well, erases generic type information at runtime. There are good reasons for this, but unfortunately, we’re not going to discuss those reasons why the language design is like that — but we will discuss its effects. Because of type erasure, you can’t perform any reflection activity and you can’t do any runtime check on a type. So, the following code won't work.

fun checkInfo(items:List<Any>) { 
    if(items is List<String>) {   // (1)
      println("item is a list of Strings")
    }
 }