// Method put on each input component to unregister
  // itself from the form
  detachFromForm: function detachFromForm(component) {
    var componentPos = this.inputs.indexOf(component);

    if (componentPos !== -1) {
      this.inputs = this.inputs.slice(0, componentPos).concat(this.inputs.slice(componentPos + 1));
    }

    this.validateForm();
  },

oh boy

By Anonymous, 2017-12-21 10:48:00
/// <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
Entity veh = World->NewVehicle(type);
...
World->AddAnimal(veh); // insert vehicle to both landscape and world

Code for creating CAMERA object in one big AAA game engine.

By Anonymous, 2018-08-19 01:33:34
public array<P extends Path<NotNul<T>>, Key extends string>(
  name: P,
  ...args: NotNul<PathValue<NotNul<T>, P>> extends Array<infer Item> ? ('id' extends keyof Item ? [keyname: Key] : [keyName?: Key]) : []
): NotNul<PathValue<NotNul<T>, P>> extends Array<infer Item>
  ? Key extends keyof Item
    ? never
    : Field<Array<Item & (Key extends keyof Item ? {} : string extends Key ? {} : { [P in Key]?: string })>>
  : never {
  return this.createField(name as any, this.name, args[0]) as any
}
By Anonymous, 2022-01-10 03:36:55
def isBool(l):
    if l != True or l != False:
        return False
    return True
By mamadSiah, 2021-04-27 16:13:17
class vggNet(nn.Module):
    def __init__(self, pretrained=True):
        super(vggNet, self).__init__()
        self.net = models.vgg16(pretrained=True).features.eval()

    def forward(self, x):


        out = []
        for i in range(len(self.net)):
            #x = self.net[i](x)
            x = self.net[i](x)
            #if i in [3, 8, 15, 22, 29]:
            #if i in [15]: #提取1,1/2,1/4的特征图
            if i in [8,15,22]: #提取1,1/2,1/4,1/8,1/16
                # print(self.net[i])
                out.append(x)
        return out

Some creepy feature extraction code I found attached to a research paper.

Features:

  • the "pretrained" parameter it's not actually used.
  • Just works (not so sure about that) with a vgg16, what if I want to use any other model?
  • They provided a spare copy of line 12, in case you lose one.
  • You can select a custom combination of layers by uncommenting the right if statement. A chinese explanation follows. Sometimes.
  • Why use pytorch hooks when you can write a 20+ lines class each time you need it?
By Baichuan Huang, 2021-05-21 19:21:58
let True = true
let False = false

使用Python的 True 和 False 在javascript

By AD, 2023-01-31 10:16:17
.black {
    color: #000;
}

.not-black {
    color: #999;
}
By Anonymous, 2019-03-04 13:45:29
function IsAOrB(const p_Id: string): boolean;
begin
  if ((p_Id = 'A') or (p_Id = 'B')) then begin
    Result := true;
    Exit;
  end;
  Result := false;
end;

Result := ((p_Id = 'A') or (p_Id = 'B'));

That would have been enough. But this also features Exit and an asymmetrical if.

By Anonymous, 2017-12-12 15:42:14
@Pipe({ name: 'shortSex' })
export class SexPipe implements PipeTransform {
  public transform(value: any): 'M' | 'K' {
    switch (value?.code) {
      case SexCodes.MALE:
        return 'M';
      case SexCodes.FEMALE:
        return 'K';
      default:
        return null;
    }
  }
}

What can I say more?

By Anonymous, 2021-07-21 10:44:17
function getJSType(cppType: string) {
    let typeMap = new Map<string, string>([
        ["Bool", "boolean"],
        ["Int32", "number"],
        ["UInt32", "number"],
        ["Int64", "number"],
        ["UInt64", "number"],
        ["Double", "number"],
        ["String", "string"],
        ["Object", "any"]
    ]);

    if (typeMap.get(cppType) === undefined) {
        console.error("Invalid type in getJavascriptType: " + cppType);
        process.exit(1);
    }
    return typeMap.get(cppType);
}
By Anonymous, 2017-12-15 11:58:04
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
public event EventHandler<Cles_graph_doivent_etre_redessines> les_graph_doivent_etre_redessines;
public void remove_event()
{
    if (this.les_graph_doivent_etre_redessines != null)
    {
        foreach (EventHandler<Cles_graph_doivent_etre_redessines> F_les_graph_doivent_etre_redessines in this.les_graph_doivent_etre_redessines.GetInvocationList())
        {
            this.les_graph_doivent_etre_redessines -= F_les_graph_doivent_etre_redessines;
        }
    }
}
By Anonymous, 2015-09-14 05:52:20
#1344 PHP +35
$command = 'curl -X GET -H "application/json" -H "X-Api-Key: '.$key.'" https://some-api.com/resource';
exec($command, $output);
$array = json_decode($output[0], true);

Using curl in PHP is boring. Let execute a command for

By Anonymous, 2020-07-14 20:28:49