Skip to content

Instantly share code, notes, and snippets.

View DrBrad's full-sized avatar
💭
Learning Rust

Brad DrBrad

💭
Learning Rust
View GitHub Profile
@DrBrad
DrBrad / SyntaxHighlight-HTML.js
Created March 3, 2017 21:38
A very simple way to highlight HTML syntax with JavaScript.
//SET AN ON UP-PRESS TO GO TO THE FUNCTION colorText(this)
function colorText(ele){
var caret = getCaretPos(ele);
var text = ele.textContent.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/=/g, '&#61;');
text = text.replace(/&lt;(.*?)(|(\s)\b(.*?)(|(&#61;)((".*?")|(\'.*?\')))(|(\s)\b(.*?)(|(&#61;)((".*?")|(\'.*?\')))))&gt;/g, '&lt;<span class="tag">$1</span>$3<span class="att">$4</span>$6<span class="par">$7</span>$11<span class="att">$12</span>$14<span class="par">$15</span>&gt;');
@DrBrad
DrBrad / Add_to_Files.java
Last active September 8, 2022 02:06
Android Media WebView Notifications
//-------- add this to webview ----------
wv.setWebChromeClient(new webChromeClient());
wv.addJavascriptInterface(new JSInterface(), "JSOUT");
//----- add this to manifest under </activity> -----
<receiver android:name=".NotificationPausePlay" />
@DrBrad
DrBrad / Socket - Example
Created January 18, 2018 00:09
Simple how2 Sockets Server & Client Java
//SERVER
public static void main(String args[]){
new Thread(new Runnable(){
@Override
public void run(){
try{
ServerSocket serverSocket = new ServerSocket(2020);
Socket socket;
while((socket = serverSocket.accept()) != null){
startSocket(socket);
@DrBrad
DrBrad / Javascript AdBlocker
Last active February 21, 2018 15:41
Simple javascript adblock
requestCheck();
window.onclick = function(){
requestCheck();
};
function requestCheck(){
console.log('asdawidahwudhawd');
var adele = document.getElementsByTagName('script');
@DrBrad
DrBrad / AES Example
Created February 9, 2019 08:56
AES Encryption
import android.util.Base64;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
@DrBrad
DrBrad / SRServerSocket.java
Last active April 13, 2020 07:17
Secure Socket RSA/AES with Sessions
package org.theanarch.secure_socket;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.SocketException;
public class SRServerSocket extends ServerSocket {
public SRServerSocket(int port)throws IOException {
super(port);
@DrBrad
DrBrad / Block.java
Last active May 27, 2020 02:25
Quick and Easy BlockChain
import java.security.MessageDigest;
import java.util.Date;
import static *.BlockHandler.*;
import static java.nio.charset.StandardCharsets.UTF_8;
public class Block {
public String hash;
public String previousHash;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.DocumentTraversal;
import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.traversal.NodeIterator;
import javax.xml.parsers.DocumentBuilderFactory;
import java.net.*;
import java.util.Enumeration;
@DrBrad
DrBrad / SRI.java
Last active September 20, 2020 18:35
Socket Cipher Data Input / Output Stream for AES
import javax.crypto.Cipher;
import javax.crypto.NullCipher;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class SRI extends FilterInputStream {
@DrBrad
DrBrad / README.md
Last active July 12, 2021 19:25
Java Swing Relative Layout Manager

I tried to make the layout as similar as possible to androids relative layout, as feel that it is the superior layout.

Heres an example:

pane.add(mjlabel, new RelativeConstraints().alignParentRight().toRightOf(mjlabel1).setHeight(RelativeConstraints.MATCH_PARENT));