Skip to content

Instantly share code, notes, and snippets.

@jtryan
jtryan / git-branch-to-master.md
Created February 22, 2017 15:41
Moving branch to master in git

The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge

If you want your history to be a little clearer, I'd recommend adding some information to the merge commit message to make it clear what you've done. Change the second line to:

@jtryan
jtryan / vidcap_ex.py
Created February 21, 2017 00:59
Capture video Frame
vidcap = cv2.VideoCapture('test_video.mp4')
vidcap.set(cv2.CAP_PROP_POS_MSEC,38000) # just cue to 38 sec. position
success, image = vidcap.read()
if success:
cv2.imwrite("capture.jpg", image) # save frame as JPEG file
cv2.imshow("final_frame",image)
cv2.waitKey()
@jtryan
jtryan / docker-container-clean.md
Created November 7, 2016 20:17
Clean up those containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@jtryan
jtryan / ValidatingHttpRequest.java
Last active October 18, 2016 14:43
Validation headers
package com.sigilius.utility;
import sun.text.Normalizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.validation.ValidationException;
import java.util.regex.Pattern;
// Return HTML Entity code equivalents for any special characters
public static String HTMLEntityEncode( String input ) {
StringBuffer sb = new StringBuffer();
for ( int i = 0; i < input.length(); ++i ) {
char ch = input.charAt( i );
if ( ch>='a' && ch<='z' || ch>='A' && ch<='Z' || ch>='0' && ch<='9' ) {
@jtryan
jtryan / uuid.md
Created August 15, 2016 17:29
UUID base 64 Java
@jtryan
jtryan / StateSavingArrayAdapter.java
Created August 14, 2016 02:18 — forked from curioustechizen/StateSavingArrayAdapter.java
StateSavingArrayAdapter: An ArrayAdapter that knows how to save/restore its own state.
/**
* <p>
* An {@code ArrayAdapter} that also knows how to save and restore its state.
* Basically all it does is save/restore the array of objects being managed by
* the Adapter.
* </p>
*
* <p>
* Note that this only saves the items and not things like checked item
* positions. Those belong to the {@link ListView} itself. Consider using
@jtryan
jtryan / adapterCLickListener.md
Last active August 10, 2016 13:45
Android Set click listener in adapter
@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Context mContext = getContext();
        final ViewHolder holder;
        final Earthquake currentEarthquake = (Earthquake) getItem(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(
                    R.layout.earthquake_list_item, parent, false);
@jtryan
jtryan / onclickEmailIntent.md
Created July 24, 2016 20:44
Android email Intent
// Find the View that shows the ContactUs  category
        TextView contactUs = (TextView) findViewById(R.id.contact);

        // Set a click listener on view
        if (contactUs != null) {
            contactUs.setOnClickListener(new View.OnClickListener() {
@jtryan
jtryan / android_onCick.md
Last active July 24, 2016 12:51
Android OnClick for layout

#Add onClick for layout

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rv_layout);
layout.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
 // Do Actions