Skip to content

Instantly share code, notes, and snippets.

View l0gicpath's full-sized avatar

Hady Mahmoud l0gicpath

View GitHub Profile
@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 / 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 / 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 / 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 / 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).
(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 / 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]
@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 / problem_2.erl
Last active August 29, 2015 13:55
Project Euler Problem #2
-module(problem_2).
-export([solve/1]).
-define(LIMIT, 4000000).
%% Normalizing the start value, need to start with an odd value and enter tail recursion
solve(Start) when Start rem 2 == 0, Start > 0 -> solve(Start - 1, Start, 0);
solve(Start) -> solve(Start, Start + 1, 0).
%% guard against the limit and drop out of recursion if we hit it
solve(Prev, Next, Sum) when Prev >= ?LIMIT; Next >= ?LIMIT -> Sum;
%% Sum even values
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'