Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / logging.sh
Last active December 12, 2015 06:49
shell logging
# Color escapes
RESET="\e[0m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
LOGFILE_DIR="$HOME"
DATETIME=`date "+%m_%d_%Y_%H.%M.%S"`
LOGFILE="$LOGFILE_DIR/build_$DATETIME.log"
touch $LOGFILE
@nixpulvis
nixpulvis / description_printer.rb
Last active December 14, 2015 15:09
Automatically print tasks description wrapping the execution of the task.
# Automatically print tasks description wrapping the execution of
# the task.
module Capistrano::Configuration::Namespaces
alias_method :_task, :task
def task(name, options = {}, &block)
desc = next_description
full_task_name = [fully_qualified_name, name].compact.join(':')
$column = 0
$last_was_after = true
@nixpulvis
nixpulvis / class_generator.rb
Last active December 14, 2015 19:59
Generate ruby classes from text files.
data = File.read('classes.txt')
classes = data.split(/^$\n/)
classes.each do |klass|
name, *methods = klass.split(/:?\n/)
Object.const_set(name, Class.new do
methods.each do |method|
parse = method.match(/(?<name>\w+) \(?(?<arguments>[\w\, ]*)\)? ?-> {(?<body>.*)}/)
if parse[:arguments].empty?
define_method(parse[:name]) { eval parse[:body] }
else
@nixpulvis
nixpulvis / Custom.css
Last active December 15, 2015 13:59
Fuck with chrome <3 - Thanks to: https://github.com/wesbos/aprilFools.css for the css.
body{-webkit-animation: spin 30s linear infinite;}
p:before {content: "Code in Ruby! ";}
body, p, body p, body div p {font-family: 'Comic Sans MS', cursive !important;}
html {-webkit-animation: rainbow 8s infinite;}
@-webkit-keyframes blur {
0% { -webkit-filter: blur(0px); }
49% { -webkit-filter: blur(0px); }
50% { -webkit-filter: blur(1px); }
51% { -webkit-filter: blur(0px); }
100% { -webkit-filter: blur(0px); }
@nixpulvis
nixpulvis / alias_methodizer.rb
Last active December 18, 2015 16:29
Dynamically alias methods and add functionality onto the end of them. Great for creating methods in rails that call `save!`.
module AliasMethodizer
private
def alias_method(alias_name, name, &function)
define_method alias_name, -> (*args, &block) do
value = method(name)[*args, &block]
instance_exec &function if block_given?
value
end
end
void mempack(void **restrict dst, const void *restrict src, size_t n) {
memcpy(*dst, src, n);
*dst = (char *) *dst + n;
}
@nixpulvis
nixpulvis / roll.c
Last active December 30, 2015 02:29
d&d dice rolling.
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int roll_dice(int, int);
int main(int argc, char const *argv[]) {
@nixpulvis
nixpulvis / file.c
Created December 9, 2013 01:17
files
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char const **argv) {
@nixpulvis
nixpulvis / de_iter.rs
Created February 5, 2016 21:41
Deserialize Iterator
use std::marker::PhantomData;
use std::iter::Peekable;
use std::io::{Read, Bytes};
use serde::Deserialize;
use serde_json as json;
use serde_json::error::Error as JsonError;
/// Iterator over parsed Messages.
pub struct DeserializeIter<T: Deserialize, R: Read> {
bytes: Peekable<Bytes<R>>,
#[derive(Debug)]
struct Recur(u32);
impl Recur {
pub fn call(n: u32) -> u32 {
let r = Recur(n);
let r = r.recur();
r.0
}