This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SwapElts where | |
-- If you have to use this function, arrays may be a better choice. | |
swapElts i j ls = [get k x | (k, x) <- zip [0..length ls - 1] ls] | |
where get k x | k == i = ls !! j | |
| k == j = ls !! i | |
| otherwise = x | |
-- This is a nice example of how to efficiently generate test cases. | |
-- A naive approach would have been to take separate arguments for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! The stringsim program prints out the trigram similarity of two strings | |
//! using what appears to be the same algorithm used by Postgres. | |
//! https://www.postgresql.org/docs/9.1/pgtrgm.html | |
use std::collections::HashSet; | |
use std::hash::Hash; | |
fn main() { | |
let args: Vec<String> = ::std::env::args().collect(); | |
if args.len() != 1+2 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
-- Synopsis: | |
-- $ cabal install QuickCheck | |
-- $ runhaskell io_quickcheck_example.hs | |
-- | |
-- Author: Issac Trotts <issac.trotts@gmail.com> | |
import Directory | |
import System.Environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap(object): | |
def __init__(self, size): | |
self.num = 0 | |
self.size = size | |
self.data = [None] * size | |
def __repr__(self): | |
return '<Thing: %s>' % (self.data,) | |
def insert(arr, x): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head></head> | |
<body> | |
<my-element></my-element> | |
<script type="module"> | |
import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module'; | |
class MyElement extends LitElement { | |
render() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="module"> | |
import {html, render} from 'https://unpkg.com/lit-html?module'; | |
const myTemplate = (name) => html`<p>Hello ${name}</p>`; | |
render(myTemplate('World'), document.body); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<div id="d">nothing here yet</div> | |
<script> | |
var send = XMLHttpRequest.prototype.send; | |
XMLHttpRequest.prototype.send = function(body) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
-- This example uses the hslogger library. | |
-- For debugging it may be more convenient to use Debug.Trace instead since that | |
-- allows you to log debugging output from otherwise pure functions. | |
import System.IO (stderr, Handle) | |
import System.Log.Logger (rootLoggerName, setHandlers, updateGlobalLogger, | |
Priority(INFO), Priority(WARNING), infoM, debugM, | |
warningM, errorM, setLevel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface #-} | |
-- Simple example of calling C from Haskell. | |
-- | |
-- $ ghci | |
-- > :load FfiExample.hs | |
-- > c_sin pi | |
-- 1.2246467991473532e-16 | |
-- | |
-- $ ghc --make FfiExample.hs |
NewerOlder