Skip to content

Instantly share code, notes, and snippets.

View trescenzi's full-sized avatar

Thomas Crescenzi trescenzi

View GitHub Profile
function get_random_id()
{
$random = '';
for ($i = 1; $i <= 8; $i++)
{
$random.= mt_rand(0, 9);
}
return $random;
if($a123 > 3)
{
$a123=0;
}
if($a123 == 0)
function parseGetResponse(response){
var splitUrl = response.split("?")[1].split("&");
var variables = {};
for(var i=0; i<splitUrl.length; i += 1){
var broken = splitUrl[i].split("=");
var key=broken[0];
var value = broken[1];
variables[key] = value;
}
return variables;
import Token
import Text.Regex.Posix
import Data.List
lexer :: String -> [Token]
lexer input lineNumber
| input =~ endline :: Bool =
let token = input =~ endline :: String
in lexer (delete (contents token) input) lineNumber + 1
|input =~ whitespace :: Bool =
<section class="slide" id="declarative">
<h2>Declarative</h2>
<blockquote>A programming paradigm that expresses the logic of a computation without describing its control flow</blockquote>
<section class="slide"><center><h3>Lets make a list of numbers 1-5</h3></center></section>
<section class="slide">
<h3>Declarative</h3>
<pre class="prettyprint"><code>
let x = take 5 [1..]
</code></pre>
<h3>Imperative</h3>
def fibonacci_stream do
Stream.unfold( [1], fn
[prev, curr] ->
next = prev + curr
{next, [curr, next]}
([1]) ->
{1, [1,1]}
end)
end
# provides a stream of primes below n
# where range is a list from 2 to n
Stream.unfold(range,fn [head|tail] -> {head, tail |> Enum.filter(fn x -> rem(x,head) != 0 end)}; [] -> nil end)
# Parallelized version ~20% speed increase
def eliminate_factors(workers, prime_number) do
Enum.map(workers, fn worker ->
send(worker, {:factor, prime_number})
end)
Enum.map(workers, fn worker ->
def interest_calc(initial_amount, interest, monthly_addition, months) do
Stream.unfold(initial_amount, fn x ->
month_end_principle = x + monthly_addition
new_principle = month_end_principle * (1 + (interest/12))
{new_principle, new_principle}
end) |> Enum.take(months)
end
@trescenzi
trescenzi / server-vue.js
Last active December 11, 2016 01:17
Vue 2 rendering an RSS Feed
const Vue = require('vue');
const renderer = require('vue-server-renderer').createRenderer();
const rssData = {
title: 'Test Feed',
link: 'www.test.com',
desc: 'A test rss feed',
items: [
{

Keybase proof

I hereby claim:

  • I am trescenzi on github.
  • I am trescenzi (https://keybase.io/trescenzi) on keybase.
  • I have a public key ASCOqDo6R32CB5hOOsOsNTcbeFrrTS-gT62G73_oiXzqpwo

To claim this, I am signing this object: