Skip to content

Instantly share code, notes, and snippets.

View gkhays's full-sized avatar

Garve Hays gkhays

View GitHub Profile
@gkhays
gkhays / body.html
Created March 18, 2016 00:50 — forked from mattborn/body.html
Relative gist files
<h1>Hello world!</h1>
@gkhays
gkhays / Pubnub.py
Created March 21, 2016 15:01 — forked from stephenlb/Pubnub.py
Python Echo Server - Example of Publish / Subscribe Python Echo Server without IP address binding.
## www.pubnub.com - PubNub Real-time push service in the cloud.
# coding=utf8
## PubNub Real-time Push APIs and Notifications Framework
## Copyright (c) 2014-15 Stephen Blum
## http://www.pubnub.com/
## -----------------------------------
## PubNub 3.5.3 Real-time Push Cloud API
## -----------------------------------
@gkhays
gkhays / recursion.java
Created March 26, 2016 23:43 — forked from rahulaga/recursion.java
Recursion
public static void recurse(int n) {
if (n <= 0)
return;
else {
n=n-1;
recurse(n);
System.out.println(n);
return;
}
}
@gkhays
gkhays / Access Private Member Hack.md
Last active March 27, 2016 16:51
Get around encapsulation in C++ or how to smash the coding interview! 😄

How to Access a Private Member in C++

Wikipedia defines encapsulation as:

In programming languages, encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination[1][2] thereof:

  • A language mechanism for restricting access to some of the object's components.[3][4]
  • A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.[5][6]

The following is a clever hack (which is by definition, but I digress...). As the author admits, you probably shouldn't do this, but it definitely shows spirit! If you have people like this on your team, they may break something once in awhile, but they will also be indomitable at solving problems.

ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@gkhays
gkhays / Java Singleton.md
Created March 27, 2016 16:46
Singleton pattern in Java

Classic Singleton in Java

public class Product
{
  private Product() { }
  
  public static Product Instance() {
    return instance;
 }
@gkhays
gkhays / Eclipse Tips.md
Last active August 19, 2024 13:05
Eclipse Tricks

Eclipse Tips and Tricks

My collection of Eclipse tips and tricks. I also have an Eclipse Cheat Sheet.

Change Context Root

Change the context root in an Eclipse Dynamic Web project.

@gkhays
gkhays / ListResources.java
Last active September 25, 2024 14:31
How to load resources and files in Java
package org.gkh;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Scanner;

Insert a date before the suffix of all JSON files in a directory

Improved by flatcap

for i in *.json; do mv "$i" "${i%.json}_$(date '+%Y%m%d').json"; done

Original

@gkhays
gkhays / JSON-Remove.md
Last active July 18, 2018 12:03
Remove an attribute or element from a JSON array during enumeration

Remove a JSON Key While Iterating

I want to remove any JSON key/value pairs wherein the value is the empty string "" or is the string literal null. However Java enumerations don't like that and will throw a ConcurrentModificationException if you attempt to remove the key and value.

JSONArray ja = loadJSONArray();
JSONObject firstJSON = ja.getJSONObject(0);
Iterator<?> iter = firstJSON.keys();
for (int i = 0; i < ja.length(); i++) {
	JSONObject json = ja.getJSONObject(i);