Skip to content

Instantly share code, notes, and snippets.

View anshdivu's full-sized avatar

Diviyansh Bhatnagar anshdivu

View GitHub Profile
@anshdivu
anshdivu / gist:5455562
Created April 24, 2013 21:04
My Zsh Theme
PROMPT='%{$fg_bold[red]%}╭─ %{$fg_bold[green]%}%p%{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}
%{$fg_bold[red]%}╰→ %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[blue]%})%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}✓"
@anshdivu
anshdivu / Nodes.java
Last active September 20, 2016 14:02
package com.cerner.discovere.xml;
import java.util.Iterator;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This class is very lightweight wrapper for {@link NodeList} to make it {@link Iterable} so that it can be used with
@anshdivu
anshdivu / gist:618e0ee575480362045c
Created June 10, 2014 17:33
Get all commits for a branch
git rev-list origin..BRANCH-NAME
screen_width = `stty size`.scan(/\d+/)[1].to_i;
snow_char = ["2743".to_i(16)].pack("U*");
# clear screen
puts "\033[2J";
screen = {}; # screen as a 2D array
loop {
# select random column in first row of screen
screen[rand(screen_width)] = 0;
// promise handles user not found by returning `null`
// advantage - don't have to write a reject handler
// disadvantage - requires developer to know the implementation detail of the facade function
// that it returns `null` or not. Higher possibility of forgeting to write `null`
// check and cause null pointer exception
function checkEmail(emailAddress) {
return facade.user.getUserByEmailAddress(emailAddress).chain(function (user) {
if (!user) {
return {available: true};
}
@anshdivu
anshdivu / watch_to_observer.md
Created April 20, 2016 19:05
`$scope.$watch` to an Observer
References:
  • RxJS api
  • ReactiveX - main website which explains what are observables/observers.
  • RxMarbles - super cool website which visually explains all the observable operators/api functions.
$scope.$watch to rxjs.observer:

Angular $watch and rxjs observers are basically the same thing. They just have different semantics. This is why angular 2 will completely remove $watch and directly use rxjs.

core@core-01 ~ $ docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.3
Git commit: 9894698
Built:
OS/Arch: linux/amd64
Server:
▶ vagrant destroy
core-01: Are you sure you want to destroy the 'core-01' VM? [y/N] y
==> core-01: Forcing shutdown of VM...
==> core-01: Destroying VM and associated drives...
==> core-01: Pruning invalid NFS exports. Administrator privileges will be required...
==> core-01: Running cleanup tasks for 'file' provisioner...
==> core-01: Running cleanup tasks for 'shell' provisioner...
==> core-01: Running cleanup tasks for 'file' provisioner...
==> core-01: Running cleanup tasks for 'shell' provisioner...
==> core-01: Running cleanup tasks for 'shell' provisioner...
package com.diviyansh.solid.openclose.step4;
class EmployeeFactory {
private String type;
public EmployeeFactory(String type) {
this.type = type;
}
public Employee create(int id, float hours) {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Text;