Skip to content

Instantly share code, notes, and snippets.

View pzp1997's full-sized avatar

Palmer Paul pzp1997

View GitHub Profile
@pzp1997
pzp1997 / UniqueBenchmark.elm
Last active June 15, 2017 15:48
Benchmarking List.Extra.unique in Elm. https://ellie-app.com/3tWkXFK8pHfa1/2
module Main exposing (..)
{- import Html exposing (Html, text) -}
import Benchmark exposing (Benchmark, describe, compare, benchmark1)
import Benchmark.Runner exposing (BenchmarkProgram, program)
import List.Extra as List
import Set
@pzp1997
pzp1997 / splitAtRewrite.elm
Created June 12, 2017 23:50
Faster(?) implementation of List.Extra.splitAt
splitAtHybrid : Int -> List a -> ( List a, List a )
splitAtHybrid index list =
if index < 0 then
( [], list )
else
splitAtFast 1 index list
|> Maybe.withDefault ( list, [] )
splitAtFast : Int -> Int -> List a -> Maybe ( List a, List a )
@pzp1997
pzp1997 / DefaultConstructor.java
Last active November 10, 2016 15:46
Demonstration and explanation of some of the intricacies of using the default constructor in Java.
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
// Bar does not declare a constructor, so the default will be used.
Bar b = new Bar();
System.out.println(b.getX());
// Foo has a constructor that accepts one argument.
Foo f1 = new Foo(2);
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input id="addmediaFileSelector" type="file" onchange="chooseFile()">
@pzp1997
pzp1997 / intobject.c
Created June 6, 2016 17:00
Excerpt from source code for Python int objects about caching "small" int values.
#ifndef NSMALLPOSINTS
#define NSMALLPOSINTS 257
#endif
#ifndef NSMALLNEGINTS
#define NSMALLNEGINTS 5
#endif
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* References to small integers are saved in this array so that they
can be shared.
The integers that are saved are those in the range
@pzp1997
pzp1997 / languageCodes.js
Created April 1, 2016 21:51
Gets the dictionary of languages to language codes that Yandex supports.
var KEY = '';
var getRequestSync = function(url) {
var xhr = new XMLHttpRequest();
var responseText;
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE)
responseText = xhr.status === 200 ? xhr.responseText : null;
};
@pzp1997
pzp1997 / translate.js
Created April 1, 2016 21:48
Translates word between two languages using Yandex.
var KEY = '';
var word = 'Thank you';
var langOne = 'English';
var langTwo = 'German';
var getRequest = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
@pzp1997
pzp1997 / getRequest.js
Created April 1, 2016 20:08
Uses XMLHttpRequest to make an AJAX get request.
var getRequest = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE)
callback(xhr.status === 200 ? xhr.responseText : null);
};
xhr.open('GET', url, true);
xhr.send();
@pzp1997
pzp1997 / ClosestPoints.java
Last active February 28, 2016 23:21
Finds the two closest points from a list of points. — http://ideone.com/NaB5Gb
import java.util.ArrayList;
class ClosestPoints
{
public static void main (String[] args) throws java.lang.Exception
{
CoordSystem coords = new CoordSystem();
coords.addPoint(new Point(3, 4));
coords.addPoint(new Point(1, 2));
@pzp1997
pzp1997 / cat-clicker.css
Last active January 25, 2016 02:10
Cat Clicker (part of JS Design Patterns Udacity Course) - http://jsbin.com/kohilo
.text-center {
text-align: center;
}
.cat-img {
width: 60%;
max-width: 480px;
min-width: 320px;
}
#cats-list {
text-align: center;