Skip to content

Instantly share code, notes, and snippets.

View ntung's full-sized avatar
🏠
Working from home

Tung Nguyen ntung

🏠
Working from home
View GitHub Profile
@ntung
ntung / .gitconfig
Created September 3, 2018 15:30 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
username = pksunkara
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
@ntung
ntung / Javascript Variable Scoping.md
Created June 4, 2018 05:59 — forked from hartleybrody/Javascript Variable Scoping.md
Variable scoping in Javascript can be confusing so I set out to make notes of the basic rules so that I can reference them later. Hope these are useful to others, happy to talk pull requests for corrections.

Javascript has two kinds of scope:

  1. Local (inside a function)
  2. Global (outside a function)

The var Keyword

  • Using the var keywords creates the variable in the current scope
    • If the current scope is global, then var is unnecessary (see below)
    • If the current scope is local, then you’re creating a local variable in the current scope
  • If you don’t use var, then Javascript goes up the “scope chain” to see if it’s already been declared
@ntung
ntung / maven-deploy-sources.sh
Created April 9, 2018 13:37 — forked from Ladicek/maven-deploy-sources.sh
deploy *-sources.jar to internal Maven repository
#!/bin/bash
# successful "mvn clean install" or a variant thereof (e.g. -DskipTests)
# is typically required before running this script
REPOSITORY_ID=...
REPOSITORY_URL=...
mvn clean source:jar
@ntung
ntung / gist:635d3baf897baefb1dd124d01028697e
Created March 6, 2018 16:48 — forked from digitaljhelms/gist:3099010
Squash the first two commits in a git repository's history

The scenario

Your repository has two commits:

$ git log --oneline
957fbfb No, I am your father.
9bb71ff A long time ago in a galaxy far, far away....
@ntung
ntung / CI Detect Ajax
Created May 5, 2017 09:14 — forked from olivierobert/CI Detect Ajax
Code Igniter // Detect and return AJAX / JSON response
/** Within the controller method **/
// If this is an ajax request, then return a JSON string
if ( $this->input->is_ajax_request() ):
$this->output->set_content_type('application/json');
$this->output->set_output( json_encode($data) );
endif;
@ntung
ntung / CI Detect Ajax
Created May 5, 2017 09:14 — forked from olivierobert/CI Detect Ajax
Code Igniter // Detect and return AJAX / JSON response
/** Within the controller method **/
// If this is an ajax request, then return a JSON string
if ( $this->input->is_ajax_request() ):
$this->output->set_content_type('application/json');
$this->output->set_output( json_encode($data) );
endif;
@ntung
ntung / get_content.groovy
Created April 25, 2017 23:22 — forked from kdabir/get_content.groovy
get content from url and write to a file in groovy
// saving from url to a file (append)
new File("output.xml") << new URL ("http://some.url/some/path.xml").getText()
@ntung
ntung / write_file.groovy
Created January 27, 2017 11:04 — forked from js1972/write_file.groovy
How to write content to a new file (overwrite if already existing) in Groovy.
//
// Write the mock request payload to a file for checking later...
// newWrite() is the important it to ensure you get a *new* file each time.
//
def filename = "C:\\MyScratchFolder\\soapUI projects\\Testing\\procon\\mock_po_activity_request.xml"
def file = new File(filename)
def w = file.newWriter()
w << mockRequest.requestContent
w.close()
@ntung
ntung / parse_sbml_stoichiometry.py
Created January 25, 2017 16:21 — forked from lukauskas/parse_sbml_stoichiometry.py
Parse SBML stoichiometry matrix
from __future__ import print_function
import libsbml
import argparse
def _parser():
parser = argparse.ArgumentParser(description="Parse stoichiometry matrix of SBML file")
parser.add_argument('file', metavar="filename", type=argparse.FileType('r'),
help="Filename of SBML file to parse")
@ntung
ntung / doi2bib.py
Created February 26, 2016 13:34 — forked from jrsmith3/doi2bib.py
Python method to access crossref.org DOI bibtex metadata resolver
import requests
def doi2bib(doi):
"""
Return a bibTeX string of metadata for a given DOI.
"""
url = "http://dx.doi.org/" + doi
headers = {"accept": "application/x-bibtex"}