Skip to content

Instantly share code, notes, and snippets.

@cppxor2arr
cppxor2arr / gravity.cpp
Created August 26, 2017 05:25
SFML gravity simulator
#include <SFML/Graphics.hpp>
#include <cmath>
class prog
{
public:
prog();
prog(const float&, const float&, const sf::String&);
void open(const float&, const float&, const sf::String&);
@cppxor2arr
cppxor2arr / rainbow.py
Created January 26, 2018 16:07
Python IRC Extended Color Code Gradient Rainbow Script
#!/usr/bin/env python3
import random, itertools
from sys import argv
def main():
num_color_hue, num_brightness, min_color, max_color = 12, 6, 16, 76
color_hue, brightness = random.randint(0, num_color_hue - 1), random.randint(0, num_brightness - 1)
direction1, direction2 = random.choice([ -1, 1 ]), random.choice([-1, 1])
color = next(itertools.islice(range(min_color + color_hue, max_color + 1 + color_hue, num_color_hue),
@cppxor2arr
cppxor2arr / particle.cpp
Last active March 20, 2018 14:38
SFML Partice Pulsation
#include <SFML/Graphics.hpp>
#include <cmath>
#include <utility>
#include <vector>
#include <functional>
class prog
{
public:
#!/usr/bin/env python3
import sys, requests
from bs4 import BeautifulSoup
from random import choice
def main(argv):
if len(argv) < 2:
sys.exit("Invalid argument(s)\nSyntax: [optional: -n [n definition/examples]] [search term]")
if len(argv) > 3:
@cppxor2arr
cppxor2arr / seq_dif.hs
Last active June 19, 2018 12:01
sequence difference
f :: Num a => [a] -> [a]
f [] = []
f [x] = []
f [x1,x2] = [x2-x1]
f (x1:x2:xs) = x2-x1:f (x2:xs)
@cppxor2arr
cppxor2arr / mean_normalization.hs
Created June 14, 2018 12:23
mean normalization
average :: Fractional a => [a] -> a
average xs = sum xs / fromIntegral (length xs)
range :: (Num a, Ord a) => [a] -> a
range xs = maximum xs - minimum xs
meanNormalize :: (Fractional a, Ord a) => [a] -> a -> a
meanNormalize xs = (/ range xs) . subtract (average xs)
-- GHCI
module Main where
import Data.List (genericTake)
{-
let p(i) be the i(th) prime number starting from 2
[p1,p2,p3,p4,p5...]
[(p2-p1),(p3-p2),(p4-p3),(p5-p4)...]
[{(p3-p2)-(p2-p1)},{(p4-p3)-(p3-p2)},{(p5-p4)-(p4-p3)}...]
... etc. applied n times
@cppxor2arr
cppxor2arr / rock_paper_scissors.cpp
Last active June 23, 2018 15:18
rock paper scissors
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <cctype>
#include <map>
#include <random>
#include <chrono>
#include <stdexcept>
@cppxor2arr
cppxor2arr / nickMsgCnt.hs
Last active June 29, 2018 15:55
weechat log get sent msg count for each nick
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
module Main where
import Data.Map (fromListWith, toList)
main :: IO ()
main = do
let log = "date time Zerock henlo\n\
@cppxor2arr
cppxor2arr / formattedSeqDiff.hs
Last active July 8, 2018 05:16
formatted sequence difference
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.List as L (intersperse)
import Data.List (maximumBy)
import Data.Ord (comparing)