public static int[] xxx(String filename) throws IOException{
	int[] f = new int[26];
	BufferedReader in = new BufferedReader(new FileReader(filename));
	String line;
	while((line = in.readLine()) != null){
		line = line.toUpperCase();
		for(char ch:line.toCharArray()){
			if(Character.isLetter(ch)){
				f[ch - 'A']++;
			}
		}
	}
	in.close();
	return f;
}
By Anonymous, 2017-12-15 16:08:38

def divide(a, b):
    try:
        return a / b
    except:
        x = 17

My smart exception handling before meeting "pass" :))

By mophix, 2017-12-15 18:13:07
if (argv[1][0]=='D'){
                demo=1;
                argv[1]++;
        }

        if (argv[1][0]=='P'){
                if (sscanf(argv[1], "P%ux%ux%ux%ux%lfx%ux%u"
                                ,&temporal_resample
                                ,&input_w, &input_h, &rate, &input_gamma
                                ,&output_w
                                ,&output_h)!=7){
                        fprintf(stderr,"%s: Invalid argument format\n", progname);
                        print_usage();
                        exit(3);
                }
                ppm=1; 
         }else{
                if (sscanf(argv[1], "%ux%ux%ux%ux%lfx%ux%u"
                                ,&temporal_resample
                                ,&input_w
                                ,&input_h
                                ,&rate
                                ,&input_gamma
                                ,&output_w
                                ,&output_h)!=7){
                        fprintf(stderr,"%s: Invalid argument format\n", progname);
                        print_usage();
                        exit(3);
                }

Found in a chroma subsampling algorithm.

By Anonymous, 2021-03-18 19:51:47
if (string.Compare(json["result"].ToString(), "OK", true) == 0)
{
    if (string.Compare(json["list"][0]["result"].ToString(), "OK", true) == 0)
        return null;
        
    //omitted
}
By J@k3R, 2022-08-09 08:51:55
let arr = []
if(arr[record.id]) {
    arr[record.id] = false
} else {
    arr[record.id] = false
}
this.setState({a: arr})
arr = []
By Anonymous, 2021-12-27 06:55:59
    @SuppressWarnings("unchecked")
    private void addEndpointsTags(JsonArray tagsArray) throws IOException {
        if (registeredHandlers == null || registeredHandlers.isEmpty()) {
            return;
        }
        TreeSet<String> handlerNamesSorted = new TreeSet<>(registeredHandlers.keySet());
        handlerNamesSorted.forEach(key -> {
            StringBuilder sb = new StringBuilder();
            sb.append("{\"name\":\"");
            sb.append(key);
            sb.append("\",\"request\":{\"name\":\"");
            try {
                ServiceMethodHandler handler = registeredHandlers.get(key);
                Class<? extends Message> requestClass = (Class<? extends Message>)
                        findSubClassParameterType(handler, 0);
                Class<? extends Message> responseClass = (Class<? extends Message>)
                        findSubClassParameterType(handler, 1);
                sb.append(requestClass.getSimpleName());
                sb.append("\",\"type\":\"");
                sb.append(requestClass.getSimpleName());
                sb.append("\",\"values\":[");
                sb.append(getProtobufClassFieldDescriptions(requestClass, new HashSet<>()));
                sb.append("]},\"response\":{\"name\":\"");
                sb.append(responseClass.getSimpleName());
                sb.append("\",\"type\":\"");
                sb.append(responseClass.getSimpleName());
                sb.append("\",\"values\":[");
                sb.append(getProtobufClassFieldDescriptions(responseClass, new HashSet<>()));
                sb.append("]},\"metadata\":{\"stream\":\"false\"}}");
            } catch (Exception e) {
                logger.error("Error inspecting handlers", e);
                return;
            }
            String tag = sb.toString();
            tagsArray.add(new JsonPrimitive("e-" + binaryEncode(tag)));
        });
    }
By Brian, 2019-08-13 15:13:37
if ((string)filtros[0] != "-1" && (string)filtros[0] != "0") 
    filtros[0] = (string)filtros[0] != "" ? filtros[0] : DBNull.Value;
    
else
    filtros[0] = DBNull.Value;  
By Anonymous, 2020-06-02 18:22:05
precision mediump float;
uniform float time;
uniform vec2 resolution;
#define equals =
#define divided /
#define plus +
#define minus -
#define times *
#define by
#define point .
#define zero 0.
#define one 1.
#define five 5.
#define output gl_FragColor
#define then {
#define end }
#define less <
#define than
#define increment ++
#define afterwards ;
#define comma ,
#define semi .5
#define hundred 100.
void main ( void ) then
	vec2 uv equals gl_FragCoord point xy divided by resolution point xy afterwards
	float number equals sin( time plus uv point y ) afterwards
	for ( float i equals zero afterwards i less than five afterwards increment i) then
		number equals mod ( uv point x comma number ) afterwards
	end
	output equals vec4 (uv point x comma uv point y comma number times hundred comma one ) afterwards
end
By Anonymous, 2017-12-14 17:39:23
/// <summary>
/// Method that checks if an object is not null
/// </summary>
/// <param name="obj">extend type of <see cref="Object"/></param>
/// <returns>true if object is not null</returns>
public static bool NotNull(this Object obj)
{
    return obj != null;
}


[TestMethod]
public void Test_Something()
{
    // test
    var result = DoSomething();
    
    // assert
    Assert.IsTrue(result.NotNull());
}
By Anonymous, 2017-12-21 15:42:20
try {
    User.ClaimToken();
} 
catch {
    User.ClaimToken();
}
By Anonymous, 2017-12-22 08:44:59
#59 PHP +30
function mysql_escape_string($str) {
    
    $pattern = [
        '/\x00/',
        '/\n/',
        '/\r/',
        '/\//',
        "/'/",
        '/"/',
        '/\x1a/',
    ];
    
    $replacement = [
        '\\x00',
        '\\n',
        '\\r',
        '\\',
        "\'",
        '\"',
        '\\x1a',
    ];
    
    $res = preg_replace($pattern, $replacement, $str);
    return $res;
}
By Anonymous, 2016-02-13 18:22:55
$('#userCheck').not(this).prop('checked', false);
By Anonymous, 2019-04-17 10:54:22
int file_exist(){
    FILE *file;
    if((file = fopen(SCORE_FILE_NAME, "r"))){
        fclose(file);
        return 1;
    }
    return 0;
}
By Anonymous, 2020-06-08 12:01:54
class {
    public State state;
    //enums cant take double values...
    public struct State
    {
        public const float IDLE = 0f;
        public const float WALKING = 0.5f;
        public const float RUNNING = 1f;
    }
    protected void Stop()
    {
        SetSpeed(State.IDLE);
    }
    protected void SetSpeed(float f)
    {
        agent.speed = f;
        if (agent.speed > 1f && agent.speed < 5f)
        {
            f = State.WALKING;
            agent.Resume();
        }
        else if (agent.speed > 5f)
        {
            f = State.RUNNING;
            agent.Resume();
        }
        else
        {
            f = State.IDLE;
            agent.Stop();
        }
    }
}

Who needs static float when you can have a constant in a nested struct, as a bonus State state has 0 references in the project

By SwagridOfficial, 2018-01-05 13:39:24
function uploadimg(file) {
    var ext = file.value.split('.').pop().toLowerCase();
    var size = document.getElementById("uploadpic").files.item(0).size;

    if (size > 3145728) {
        $.messager.alert({
            title: "Error",
            msg: " image to large",
            icon: "error"
        });
        return true;
    }

    return false;
}

var reader = new FileReader();
$("#uploadpic").change(function() {
    var pdfcheck = this;
    var ext = pdfcheck.value.split('.').pop().toLowerCase();
    if (!($.inArray(ext, ['pdf']) == -1)) {
        console.log('upload pdf start');
        if (uploadPdf(pdfcheck)) {
            $("#preview_img").attr("src", "");
            $("#preview_img2").attr("src", "");
            $("#uploadpic").prop("file", "");
            $("#uploadpic").val("");
        }
    } else {
        if (uploadimg(pdfcheck)) {//dude, I think the image you upload to check is your dick, only small enough you would rather keep going producing shitcode.
            return false;
        }
        var upload_file = $("#uploadpic")[0].files[0];
        if (upload_file != null) {
            var chimgarr = ["image/png", "image/PNG", "image/jpg", "image/JPG", "image/jpeg", "image/JPEG", "image/gif", "image/GIF", "image/bmp", "image/BMP"];
            if (chimgarr.indexOf(upload_file.type) != "-1") {
                reader.readAsDataURL(upload_file);
                reader.onload = function(e) {
                    $("#preview_img").attr("src", e.target.result);
                    $("#preview_img2").attr("src", e.target.result);
                    $("#pdf-contents").hide();
                    $("#pdf_name").val("");
                    $("#btn_pdf_view").hide();
                    $("#pic_name").val("");
                }
            } else {
                $.messager.alert("Image format does not match");
                $("#preview_img").attr("src", "");
                $("#preview_img2").attr("src", "");
                $("#uploadpic").prop("file", "");
                $("#uploadpic").val("");
            }
        } else {
            $("#preview_img").attr("src", "");
            $("#preview_img2").attr("src", "");
        }
    }
});

The moment an important image ready to be uploaded It's really important that should be checked again and again.

By shitcode master's friend, 2018-04-20 11:03:15