Skip to content

Instantly share code, notes, and snippets.

View benwilson512's full-sized avatar

Ben Wilson benwilson512

  • CargoSense
  • Fairfax, VA
View GitHub Profile
mutation do
field :submit_comment, :comment do
arg :repo_fullname, non_null(:string)
arg :content, non_null(:string)
resolve fn args, _ ->
comment = # create comment
{:ok, comment}
end
end
defmodule PuzzledPintScriptElixir do
@base_string "http://www.puzzledpint.com/puzzles/august-2015/semaphore/"
defp get_file_strings do
File.read! "/usr/share/dict/cracklib-small"
end
def list_of_urls do
get_file_strings
|> String.split("\n", trim: true)
FROM fedora:22
ENV LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.UTF-8"
RUN dnf groupinstall -y "Development Tools" "Development Libraries" && dnf install -y wget git tar bzip2 && dnf clean all
RUN \
wget http://www.erlang.org/download/otp_src_18.1.tar.gz && \
tar -zxf otp_src_18.1.tar.gz && \
cd otp_src_18.1 && \
export ERL_TOP=`pwd` && \
#![feature(simd)]
#![allow(experimental)]
extern crate test;
extern crate time;
use std::simd::f64x2;
use std::sync::{Arc,Future};
static CHUNKS: uint = 4;
static POINTS: uint = 10000000;
#[bench]
fn test_overflow(b: &mut Bencher) {
let nums = [0i, ..1000000];
b.iter(|| {
let mut x = 0i;
for i in range(0, nums.len()) {
x = nums[i];
}
});
}
-- File "seemingly-impossible.hs",
-- automatically extracted from literate Haskell
-- file http://www.cs.bham.ac.uk/~mhe/papers/seemingly-impossible.html
--
-- Martin Escardo, September 2007
-- School of Computer Science, University of Birmingham, UK
--
-- These algorithms have been published and hence are in the
-- public domain.
--
#!/bin/bash
#Initial wifi interface configuration
ifconfig $1 up 10.0.0.1 netmask 255.255.255.0
sleep 2
###########Start dnsmasq, modify if required##########
if [ -z "$(ps -e | grep dnsmasq)" ]
then
dnsmasq
fi
defmodule Generator do
# Generates a method like the following
# def to_word(n) when n >= 1_000 do
# [to_word(div(n, 1_000)), "thousand,", to_word(rem n, 1_000)]
# end
defmacro gen_method(input) do
quote bind_quoted: [input: input] do
def to_word(n) when n >= unquote(input[:num]) do
[to_word(div(n, unquote(input[:num]))), "#{unquote(input[:text])},", to_word(rem n, unquote(input[:num]))]
end
# http://en.wikipedia.org/wiki/Simple_linear_regression
# Exchange.Calc.Regression.run(self, [{1,1},{2,2},{3,3}])
defmodule Exchange.Calc.Regression do
def run(recipient, points) do
n = length(points)
fn_builder = spawn(Exchange.Calc.Regression, :build_function, [recipient, []])
spawn(Exchange.Calc.Regression, :sum_products_avg, [fn_builder, points, n])
@benwilson512
benwilson512 / linear regression
Last active December 22, 2015 22:59
Linear regression for a set of points. of the form [{x1, y1}, {x2, y2}] etc. I iterate through the point array several times which is unfortunate. The alternative was to try to iterate once and build several different states simultaneously, but this was at least prima facie easier.
# http://en.wikipedia.org/wiki/Simple_linear_regression
defmodule Exchange.Calc do
def linear_regression(points) do
n = length(points)
# Average of sum of products
sop_bar = sum_of_products(points) / n
# Average of sum of x and y respectively