Skip to content

Instantly share code, notes, and snippets.

View cristianrasch's full-sized avatar
💭
I may be slow to respond.

Cristian Rasch cristianrasch

💭
I may be slow to respond.
View GitHub Profile
module ArrayUtils
def self.flatten(array)
array.inject([]) { |accu, elem|
if elem.kind_of?(Array)
accu.concat(flatten(elem))
else
accu << elem
end
}
end
#!/usr/bin/env ruby
# sed 's/https:\/\/www.twitter.com\///' -i ~/Downloads/twitter_accounts.csv
require "csv"
require "English"
require "logger"
require "pathname"
require "set"
require "English"
require "logger"
require "pathname"
# kill me with kill -INT PID
script_path = Pathname(__FILE__)
pid_file = script_path.sub_ext(".pid")
pid_file.write(String(Process.pid))
from itertools import cycle, chain, islice, repeat
fizzes = cycle(chain(islice(repeat(''), 2), ('fizz' for _ in range(1))))
buzzes = cycle(chain(islice(repeat(''), 4), ('buzz' for _ in range(1))))
fizzes_buzzes = zip(range(1, 101), fizzes, buzzes)
fizz_buzz = (str(i) if not(fizz) and not(buzz) else f'{fizz}{buzz}' for i, fizz, buzz in fizzes_buzzes)
for line in fizz_buzz:
print(line)
use std::iter::{once, repeat};
fn main() {
let fizzes = repeat("").take(2).chain(once("fizz")).cycle();
let buzzes = repeat("").take(4).chain(once("buzz")).cycle();
let fizzes_buzzes = fizzes.zip(buzzes);
let fizz_buzz = (1..=100).zip(fizzes_buzzes).map(|tuple| match tuple {
(i, ("", "")) => i.to_string(),
(_, (fizz, buzz)) => format!("{}{}", fizz, buzz),
@cristianrasch
cristianrasch / convert.py
Last active January 27, 2019 11:20
Recursively optimize your photo collection using all your machine's cores
#!/usr/bin/env python3
"""
Requires: imagemagick
Usage: convert.py [DIR] (defaults to ~/Pictures)
"""
from concurrent import futures
import fnmatch
import os
@cristianrasch
cristianrasch / whitelist-ip-4-squid.sh
Last active September 11, 2018 18:59
Whitelist IP for Squid
#!/bin/bash
# USAGE: ssh REMOTE_HOST "~/bin/whitelist-ip-4-squid ROSALES $(public-ip)"
SQUID_CONFIG=/etc/squid/squid.conf
LABEL="$1"
NEW_IP="$2"
# echo "LABEL: $LABEL, NEW IP: $NEW_IP"
# find out the previous IP associated with LABEL
*********************
Streaming Replication
*********************
++++++
Master
++++++
postgresql.conf
---------------
#!/usr/bin/env ruby
# RBENV_VERSION=jruby-9.1.16.0 JRUBY_OPTS="--server -J-Xms2048m -J-Xmx2048m" N=12 ./dict-gen -o ~/Downloads/dicts
require "optparse"
require "fileutils"
require "unique_permutation"
SYMBOLS = ("A".."Z").to_a.freeze
N = Integer(ENV.fetch("N", 12))
# This class provides a collection of class methods to manipulate Arrays
class ArrayUtils
class << self
# Recursively flattens its arbitrarily nested array arguement
# Warning: passing in very big arrays WILL BLOW UP THE STACK!
def flatten(arr)
_flatten(arr, [])
end
private