Skip to content

Instantly share code, notes, and snippets.

View xenogew's full-sized avatar
😆
Working with motivation

Natta Wang xenogew

😆
Working with motivation
View GitHub Profile
@xenogew
xenogew / java-array-to-map-lambda
Created May 11, 2021 01:36
Java one line of code using lambda for converting array to map
private Map<String, String> getCookies(String cookieHeader) {
return Arrays.stream(cookieHeader.split(";"))
.map(String::trim)
.collect(Collectors.toMap(e -> e.split("=")[0], e -> e.split("=")[1]));
}
@xenogew
xenogew / Medium-dark-by-Stylus.css
Created October 1, 2019 02:35
Stylus - Medium.com dark theme, the extends from Medium Dark of 'ultimatetoast27'
@-moz-document url-prefix("https://medium.com"), url-prefix("https://posts.specterops.io"), url-prefix("https://hackernoon.com"), url-prefix("https://blog.0day.rocks"), url-prefix("https://blog.discordapp.com/"), url-prefix("https://blog.ettic.ca/"), url-prefix("https://arlogilbert.com"), url-prefix("https://medium.freecodecamp.org"), url-prefix("https://engineering.salesforce.com") {
/*Dark Stuff*/
/*dark-dark*/
.u-backgroundTransparentWhiteDarkest, .u-backgroundGrayLightest, .u-background--brandSageLighter,.metabar-block, .textInput, .metabar, .h {
background-color: #292929 !important;
color: #d5d5d5;
}
/*light-dark*/
body, html, article, .cardChromeless, .screenContent, .canvas-renderer, .u-backgroundColorWhite {
background-color: #2f2f2f !important;
@xenogew
xenogew / Dockerfile
Created October 30, 2018 06:32
Example of PHP 7.2.x Docker image install with MS SQL Server extensions
FROM php:7.2.11-fpm
WORKDIR /application
ENV ACCEPT_EULA=Y
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
@xenogew
xenogew / sql-server-merge-poc.sql
Created October 12, 2018 01:16
SQL Server - Merge clause example with description
-- Declare `@SummaryOfChanges` as variable table, disappear when DB connection session end.
-- Use for storing changes which persisted by transaction.
DECLARE @SummaryOfChanges TABLE(Change VARCHAR(20), id VARCHAR(5), date VARCHAR(8), val INT );
-- Target table is the initial resource of values comparison and changing target of decision of `ON` clauses.
MERGE dbo.[T_target_table] AS T
-- Source value is the input of ours, e.g. input from `user`, `form`, `service`.
USING (VALUES ('97', '2018-03-01')) AS S (src_id, src_date)
-- Condition to find out the fact of data, result of comparison will use for action decision.
ON T.id = S.src_id AND T.date = S.src_date
@xenogew
xenogew / git-remove-last-commit.md
Created June 20, 2018 07:07
How to remove last commit on remote

History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

git push origin +dd61ab32^:master

@xenogew
xenogew / syncing-with-forked-upstream.md
Last active March 22, 2018 01:56
The method on how-to update your forked repository with the master repository you forked from.

1. Add the remote called upstream to your own forked repository.

git remote add upstream https://the-git-repo-url.com/whoseever/whatever.git

2. Fetch all the branches from that upstream remote repository to remote-tracking.

git fetch upstream

3. Make sure that your local repository is checkout as the master branch.

@xenogew
xenogew / .gitignore
Created June 21, 2016 17:10
Common gitignore file for Android project
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
@xenogew
xenogew / readImage.java
Created March 23, 2016 04:41
method snippet for read and send image media file as byte array through REST api
public void getDashboardProfileImage(HttpServletRequest servletRequest,
@RequestParam(value = "username") final String username, HttpServletResponse response) {
try {
String theUsername = URLDecoder.decode(username, "UTF-8");
ProfileImageDetailsDto profileImageDetailsResponse = new ProfileImageDetailsDto();
profileImageDetailsResponse = profileImageDetailsService.getProfileImage(theUsername);
// retrieve mime type of the image
String mimeType = FormatUtils.retrieveMimeTypeBytes(profileImageDetailsResponse.getProfileImage());
IOUtils.write(profileImageDetailsResponse.getProfileImage(), response.getOutputStream());
response.flushBuffer();
@xenogew
xenogew / VarargStubbing.java
Created February 25, 2016 07:58
How to stub a method that have variable arguments
package blah.blah.blah;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;