Skip to content

Instantly share code, notes, and snippets.

View daihuaye's full-sized avatar

Daihua Ye daihuaye

View GitHub Profile
@daihuaye
daihuaye / tryViewChild.js
Last active May 25, 2017 22:33
Use ViewChild directly in JavaScript
import { Component, ViewChild } from '@angular/core';
import { MyComponent } from './my-component.js';
const componentAnnotation = new Component({
selector: "try-view-child-js",
template: `<div><my-component #myComponent></my-component></div>`
});
export class TryViewChildComponent {
@ViewChild('myComponent') _myComp; // QUESTION: How can I use the ViewChild component which reference my component from template in ES6 class?
@daihuaye
daihuaye / findEleIndex.js
Last active March 15, 2017 23:45
Get the index of element from circular sorted array
// 13, 14, 22, -3, -1, 4, 5, 6, 11
// target: 5
// mid: -1, start: 13, end: 11
// -1 -> 11
// mid: 5, start: -1, end: 11
// return index: 6
// target: 14
// mid: -1, s: 13, e: 11
@daihuaye
daihuaye / static_server.js
Created June 15, 2016 19:08 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);

#credit - @dhavalpowar #Explain how Lets encrypt works

  • Install lets encrypt sudo apt-get install letsencrypt

  • Workflow: lets-encrypt will generate a pair of RSA private key/public key and contact the CA with your public key.

      The CA will register your public key
    

The program will then ask the CA to verify your domain.

# Auto loading file rules in Ruby on Rails
# the following class need to be under this file path: app/models/contract/document/uploader.rb
class Contract::Document::Uploader < CarrierWave::Uploader::Base
...
end
# This is an issue for us to relocate Mailer::Base(app/mailers/mailer) to app/mailers folder
# I have read online resource I can't find a way to break this.
# let me know if you find anything, if not, I think we should keep it under app/mailers/mailer for now
function isPrime(number) {
if(typeof number !== 'number' || !Number.isInterger(number)) {
return false;
}
if(number < 2) {
return false;
}
if(number === 2) {
return true;
} else if(number % 2 === 0) {
/*
* "Myself" v1.0.3
* Robot rights protected under BOT License
* Authored by pen#PwLXXP
*/
body {
background-color: #1a1c24; color: #fff;
font-size: 13px; line-height: 1.4;
-webkit-font-smoothing: subpixel-antialiased;
@daihuaye
daihuaye / ie9issueInClickEvent.markdown
Last active August 29, 2015 14:17
IE 9 issue in bubbling event

IE9 issue on click event

<div class="test">
  <span>Click Me</span>
  <i class="icon-shopping-cart"></i>
  <div class="overlay-div"></div>
</div>
{
"name": "kss",
"version": "2.0.2",
"dependencies": {
"glob": {
"version": "4.4.1",
"from": "glob@^4.0.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-4.4.1.tgz",
"dependencies": {
"inflight": {
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution