Skip to content

Instantly share code, notes, and snippets.

@AlienKevin
AlienKevin / addSimultaneousEventListeners.js
Created April 9, 2019 21:02
Add same event listener to multiple simultaneous events that are fired at about the same time.
function addSimultaneousEventListeners(eventNames, callback, options) {
const defaultOptions = {
inOrder: true, // the events should be fired in the order specified in eventNames array or not
tolerance: 500, // the tolerance time between the first and the last event in milliseconds,
// you can rarely fire two events at the exact moment
}
// merge default options with user options
const mergedOptions = {
...defaultOptions,
...options
type VectorAng2 = {
mag: number,
dir: number,
dim: 2
}
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
from tkinter import *
window = Tk()
window.title("Welcome to LikeGeeks app")
lbl = Label(window, text="Hello")
lbl.grid(column=0, row=0)
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<!DOCTYPE html>
<html>
<head>
<title>First Web Page</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
@AlienKevin
AlienKevin / topological-sort.elm
Last active May 8, 2020 22:04
Sort dependency graphs in Elm. Run this in Ellie: https://ellie-app.com/8NWh6CWDn3Sa1. Algorithm based on StackOverflow Answer: https://stackoverflow.com/a/54346588/6798201
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, h2, text)
import Html.Events exposing (onClick)
import Dict exposing (Dict)
import Set exposing (Set)
type alias Model =
@AlienKevin
AlienKevin / onClickNoProp.elm
Created May 28, 2020 12:12
Detect onClick event without propagation
onClickNoProp : Msg -> Html.Attribute Msg
onClickNoProp msg =
Html.Events.custom "click"
(Decode.succeed
{ message = msg
, stopPropagation = True
, preventDefault = False
}
)