Skip to content

Instantly share code, notes, and snippets.

View jizhang's full-sized avatar

Jerry jizhang

View GitHub Profile
@shankarshastri
shankarshastri / LearnXInYMinProtocolBuffer.proto
Last active September 29, 2024 15:14
Self-Explanatory Protocol Buffer Lang Guide (CheatSheet)
/*
* Self-Explanatory Protocol Buffer Lang Guide
*/
/*
* Why Protocol Buffers?
* Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
* You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
* Protocol Buffers are Schema Of Messages. They are language agnostic.
@tansuaksan
tansuaksan / CustomUsernamePasswordAuthenticationFilter.java
Last active January 12, 2023 07:58
Custom Authentication Via JSON login request in Spring Security
@Slf4j
public class CustomUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException(
"Authentication method not supported: " + request.getMethod());
}
@yiichou
yiichou / kcptund
Last active August 20, 2018 01:07
Management tool of kcptun server with ssh -D socks
#!/bin/sh
### BEGIN INIT INFO
# Provides: kcptun
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fast kcp tunnel proxy that helps you bypass firewalls
# Description: A secure socks5 proxy, designed to protect your Internet traffic via
# KCPTUN. KCPTUN is a simple UDP tunnel based on KCP.
@nrollr
nrollr / MySQL_macOS_Sierra.md
Last active September 19, 2024 08:26
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

@gaoyifan
gaoyifan / google-fonts-proxy
Last active August 29, 2024 08:50
google-fonts-proxy
server {
listen 80;
listen 443;
listen [::]:80;
listen [::]:443;
server_name fonts.lug.ustc.edu.cn;
access_log /var/log/nginx/revproxy_access.log;
error_log /var/log/nginx/revproxy_error.log;
@staltz
staltz / introrx.md
Last active November 14, 2024 11:27
The introduction to Reactive Programming you've been missing
@ionelmc
ionelmc / vbox-shutdown.py
Last active October 18, 2024 08:09
VirtualBox automatic shutdown cleaner. Runs in the "notification icon area". When closed by windows it waits for VMs to shutdown (acpi) and if it doesn't work it tries to suspend the VMs.
import logging
import subprocess
import time
import sys
import win32con
import win32gui_struct
import os
try:
import winxpgui as win32gui
except ImportError:
@raphw
raphw / UnsafeTest.java
Last active January 10, 2023 20:12
A demonstration of sun.misc.Unsafe
import org.junit.Before;
import org.junit.Test;
import sun.misc.Unsafe;
import sun.reflect.ReflectionFactory;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import static org.junit.Assert.assertEquals;
@laurilehmijoki
laurilehmijoki / StaticFileServlet.scala
Last active December 12, 2018 04:59
Static file servlet with Scalatra
package coolcode
import java.io.File
import java.util.Properties
import org.scalatra.ScalatraServlet
class StaticFileServlet extends ScalatraServlet {
get("/*") {
val resourcePath = getResourcePath
@extraordinaire
extraordinaire / reconnecting_pdo.php
Last active August 2, 2024 22:48
Reconnectable PDO
<?php
class ReconnectingPDO
{
protected $dsn, $username, $password, $pdo, $driver_options;
public function __construct($dsn, $username = "", $password = "", $driver_options = array())
{
$this->dsn = $dsn;
$this->username = $username;
$this->password = $password;