This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.base.Preconditions; | |
import com.google.common.collect.ImmutableList; | |
import com.google.common.collect.ImmutableListMultimap; | |
import com.google.common.collect.ListMultimap; | |
import java.lang.reflect.Method; | |
import java.util.List; | |
import java.util.Optional; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
import org.junit.platform.commons.util.ReflectionUtils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static List<String> parseOptions(String testBridgeTestOnly) { | |
// transform env.TESTBRIDGE_TEST_ONLY | |
List<String> methodNames = new ArrayList<>(); | |
List<String> classNames = new ArrayList<>(); | |
List<String> packageNames = new ArrayList<>(); | |
ArrayList<String> tests = new ArrayList<>(); | |
// Tests are separated by | But so are methods so we can't blindly split on the | character. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example: | |
// | |
// cout << hashString("hello world") << endl; // prints: 1128946856 | |
#include <boost/functional/hash.hpp> | |
int hashString(const string& input) { | |
boost::hash<string> string_hash; | |
return string_hash(input); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example: | |
// | |
// System.out.println(Hasher.sha1("hello world")); // prints: 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed | |
// System.out.println(Hasher.sha1AsInt("hello world")); // prints: 896314922 | |
import java.nio.charset.*; | |
import com.google.common.hash.*; | |
class Hasher { | |
public static String sha1(String input) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a degenerate PKCS#7 certificate only in ruby (SCEP application/x-x509-ca-ra-cert) | |
# Inspiration: https://github.com/AppBlade/TestHub/blob/master/app/controllers/scep_controller.rb#L92-L112 | |
# | |
# Tested Ruby 2.2.0 OSX 10.10, OpenSSL 1.0.1l | |
require 'openssl' | |
cert = OpenSSL::X509::Certificate.new File.read('some_cert.crt') | |
# Fails ruby 2.2, OpenSSL 1.0.1l!! | |
p7certs = OpenSSL::PKCS7.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Automatically updates ghost per instructions at: | |
# | |
# http://support.ghost.org/how-to-upgrade/ | |
# | |
# Make sure to back up your files before proceeding (i.e. git repo)! | |
# | |
require 'tempfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApiController | |
def create | |
@post = current_user.posts.create!(params.require(:post)) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiController < ActionController::Base | |
rescue_from ActionController::ParameterMissing do |e| | |
# You can even render a jbuilder template too! | |
render json: {error: e.message }, status: :unprocessable_entity | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApiController | |
def update | |
@post = current_user.posts.find(params[:id]) | |
@post.update_attributes!(params[:post]) | |
end | |
def create | |
@post = current_user.posts.create!(params[:post]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiController < ApplicationController::Base | |
rescue_from ActiveRecord::RecordNotFound do |e| | |
render json: { error: e.message }, status: :not_found | |
end | |
rescue_from ActiveRecord::RecordInvalid do |invalid| | |
# You can even use jbuilder templates to make this cleaner! | |
render 'shared/record_invalid', locals: { exception: invalid }, | |
status: :unprocessable_entity |
NewerOlder