Skip to content

Instantly share code, notes, and snippets.

View l0gicpath's full-sized avatar

Hady Mahmoud l0gicpath

View GitHub Profile
@l0gicpath
l0gicpath / problem_2.erl
Created January 31, 2014 13:35
Because my other 5 line Erlang solution was too long.
-module(problem_2).
-export([s/0]).
-define(L, 4000000).
s() -> s(1, 2, 0).
s(P, N, S) when P >= ?L; N >= ?L -> S;
s(P, N, S) -> S1 = case N rem 2 of 0 -> N + S; _ -> S end, s(N, P + N, S1).
@l0gicpath
l0gicpath / one_liner.rb
Last active August 29, 2015 13:55
One liner ruby solution for project euler problem #2 because ruby is hardcore
(l ,ss = 4000000, proc {|p, n, s| p >= l || n >= l ? s : n.even?? ss[n, n + p, s + n] : ss[n, n + p, s] })[1][1, 2, 0]
(f=->*a{a[2]+=a[1]%2==0?a[1]:0;a[0],a[1]=a[1],a[1]+a[0];a[0]>=a[3]||a[1]>=a[-1]?a[2]: f[*a]})[1,2,0,4000000]
@l0gicpath
l0gicpath / problem_4.erl
Last active August 29, 2015 13:56
Project Euler problem #4 solution in Erlang
-module(problem_4).
-export([solve/0]).
solve() ->
List = lists:seq(100, 999),
[H | L] = [X * Y || X <- List,
Y <- List,
integer_to_list(X * Y) =:= lists:reverse(integer_to_list(X * Y))],
solve(L, H).
@l0gicpath
l0gicpath / problem_4.rb
Last active August 29, 2015 13:56
Project Euler problem #4 solution in Ruby
(100..999).to_a.repeated_permutation(2).collect{|x| x[0] * x[1] if "#{x[0] * x[1]}" == "#{x[0] * x[1]}".reverse }.compact.max
@l0gicpath
l0gicpath / euler53.ml
Created February 22, 2014 04:39
Euler problem #53 in OCaml
(* taking out the big guns, yes... size matters *)
open Num
open Printf
(* a throw away helper function just like pred but works with Nums, ought to give it a better name *)
let pred' n = Int (pred (int_of_num n))
(* field test *)
let rec fact x = if x =/ Int 0 then Int 1 else x */ fact (pred' x)
@l0gicpath
l0gicpath / screensharing.rb
Created February 22, 2014 22:00
Streaming your screen over http using screenshots. Uses 'screencapture' for mac systems, you'll need to find another screen capturing utility to be used from the terminal on your system of choice. An enhanced code over https://gist.github.com/blazeeboy/9151757
#! /usr/bin/env ruby
require 'socket' # needed for creating tcp servers
require 'base64' # we'll use base64 for encoding images and embedding them in the response
require 'cgi' # has a lovely helper method for generating rfc1123 compliant dates for http headers
refresh_rate = 1 # in seconds, interval between each screen capture
server = TCPServer.open 3005 # start our server at port 3005
# the html page template we'll be sending over to the browser
page_tmpl = %Q[
@l0gicpath
l0gicpath / all_users.csv
Last active November 11, 2017 13:59
Subtract data of one CSV file from another using fast grep. Dummy data generated by http://dummydata.me/
[email protected] Stefanie House
[email protected] Dinah Erickson
[email protected] Melisa Reynolds
[email protected] Lily Carson
[email protected] Millard Rubio
[email protected] Octavia Santana
[email protected] Royal Bender
[email protected] Laverne Hutchins
[email protected] Sherman Wilder
[email protected] Thelma Burris
@l0gicpath
l0gicpath / age.rb
Last active August 29, 2015 13:56 — forked from emad-elsaid/age.rb
An age ticker, forked to clean up, more ruby-like and properly styled
#! /usr/bin/env ruby
date_of_birth = Time.new(1988, 8, 31)
# Credit: http://stackoverflow.com/a/4136485
def humanize seconds
[[60, :seconds],
[60, :minutes],
[24, :hours],
[365, :days],
@l0gicpath
l0gicpath / kill_braincells.exs
Last active August 29, 2015 13:59
Consuming arabic tech content workflow
# Fun exercise with Elixir.
# The joke's on arabic tech news and yes it's that bad I had to write this.
# That's an elixir script hence .exs so run it with
# > elixir kill_braincells.exs
defmodule Content do
@moduledoc """
Content is responsible for consuming different types of content
"""