Skip to content

Instantly share code, notes, and snippets.

@AlienKevin
AlienKevin / onClickNoProp.elm
Created May 28, 2020
Detect onClick event without propagation
View onClickNoProp.elm
onClickNoProp : Msg -> Html.Attribute Msg
onClickNoProp msg =
Html.Events.custom "click"
(Decode.succeed
{ message = msg
, stopPropagation = True
, preventDefault = False
}
)
@AlienKevin
AlienKevin / topological-sort.elm
Last active May 8, 2020
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
View topological-sort.elm
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 =
View html-demo.html
<!DOCTYPE html>
<html>
<head>
<title>First Web Page</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
View android-main-demo.java
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);
View android-layout-demo.xml
<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"
View swing-demo.java
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.
View java-swing-demo
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.
View tkinter-demo.py
from tkinter import *
window = Tk()
window.title("Welcome to LikeGeeks app")
lbl = Label(window, text="Hello")
lbl.grid(column=0, row=0)
View VectorAng2.ts
type VectorAng2 = {
mag: number,
dir: number,
dim: 2
}
@AlienKevin
AlienKevin / addSimultaneousEventListeners.js
Created Apr 9, 2019
Add same event listener to multiple simultaneous events that are fired at about the same time.
View addSimultaneousEventListeners.js
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