Skip to content

Instantly share code, notes, and snippets.

View rhaseven7h's full-sized avatar
🙊

Gabriel Medina rhaseven7h

🙊
View GitHub Profile
generator = require('utf8-fdf-generator').generator;
generator({ myField01: "Gabriel Medina", myField02: "Ciudad Juárez, Chihuahua, México" }, "output.fdf");
// Do whatever you need with file output.fdf here.
params = "token=palomitas";
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("mydiv").innerHTML = xmlhttp.responseText;
}
};
@rhaseven7h
rhaseven7h / hkp-api.js
Last active August 29, 2015 14:26
Hook.io Microservice to Interact with HKP Servers (PGP Key Server)
// A simple hello world microservice
// Click "Deploy Service" to deploy this code
// Service will respond to HTTP requests with a string
module['exports'] = function helloWorld (hook) {
// hook.req is a Node.js http.IncomingMessage
var host = hook.req.host;
// hook.res is a Node.js httpServer.ServerResponse
// Respond to the request with a simple string
hook.res.end(host + ' says, "Hello world, papanatas!"');
};
@rhaseven7h
rhaseven7h / Main.java
Created June 10, 2016 20:59
Get single character in java console (terminal, blocking call)
import java.io.Console;
import java.io.IOException;
import java.io.Reader;
import java.lang.Runtime;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("Press the \"z\" key to exit!");
String[] cmd = {"/bin/sh", "-c", "stty raw </dev/tty"};
@rhaseven7h
rhaseven7h / mingle.hs
Created July 20, 2016 08:16
Haskell : Mingle strings
-- Mingles two strings
--
-- INPUT "abcd\n1234\n"
-- OUTPUT "a1b2c3d4\n"
solve :: String -> String -> String
solve [] [] = []
solve (x:xs) (y:ys) = x : y : solve xs ys
main :: IO ()
@rhaseven7h
rhaseven7h / perimeter.hs
Created July 20, 2016 22:39
HackerRank Calculate Perimeter - Functional Programming - Ad hoc
-- Calculate the perimeter delineated by the list of points
--
-- Input from standard in is as follows:
--
-- 4
-- 0 0
-- 0 1
-- 1 1
-- 1 0
--
@rhaseven7h
rhaseven7h / a_string_rotate.hs
Last active July 21, 2016 05:39
HackerRank.com - Functional Programming - Haskell - Return all rotations of a string
-- Rotate Strings
import Data.List
rotate s r = drop r s ++ take r s
solve s = intercalate " " (tail rss ++ [ head rss ])
where rss = [ rs | r <- [ 0 .. (length s - 1) ], let rs = rotate s r ]
main = do
@rhaseven7h
rhaseven7h / a_remove_duplicates.hs
Created July 21, 2016 06:03
HackerRank - Functional Programming - Haskell - Remove Duplicate Characters From String
---- Remove Duplicates and return characters in the order they were found
import Data.List
solve :: String -> String -> String
solve b "" = b
solve b (s:st)
| isInfixOf (s : "") b = solve b st
| otherwise = solve (s : b) st
@rhaseven7h
rhaseven7h / a_kundu_and_bubble_wrap.hs
Created July 21, 2016 08:43
HackerRank.com - Functional Programming - Haskell - Kundu And Bubble Wrap
solve n m = sum times
where oSize = fromIntegral $ n * m
oIndices = [ 1 .. oSize ]
singleProb = (\x -> x / oSize)
singleTime = (\n -> 1 / (singleProb n))
times = map singleTime oIndices
main = do
raw <- readFile "input.txt"
let inStrArr = words $ head $ lines raw
@rhaseven7h
rhaseven7h / a_functions_or_not.hs
Created July 23, 2016 05:53
HackerRank.com - Functional Programming - Functions or Not? - Haskell
import qualified Data.Map.Strict as MS
import Data.List
-- Basically a valid function is that which
-- always return the same output for a given input,
-- that is, a function that one time returns 3 for f(1)
-- and the next returns 5 for the same f(1) is NOT
-- a valid function
--
-- This algorithm checks we have unique outputs for