Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / gem-reset
Last active October 5, 2020 15:21
Remove all non default gems. For ruby 2.0.0
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
@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
@nixpulvis
nixpulvis / term_size.rb
Last active October 18, 2017 11:50
Get the terminal window size. Not in a bullshit ENV dependent manor.
# From the tty_ioctl man page in Linux.
#
# TIOCGWINSZ struct winsize *argp
# Get window size.
#
# TIOCSWINSZ const struct winsize *argp
# Set window size.
#
# The struct used by these ioctls is defined as
#
#include <SPI.h>
#define CHIP_SELECT_PIN 10
void setup() {
// Setup SPI communication for the MAX7221.
pinMode(CHIP_SELECT_PIN, OUTPUT);
SPI.begin();
// Test for 1 second.
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 / fullscreen.c
Created December 4, 2013 19:12
Fullscreen OpenGL with GLUT
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <GLUT/glut.h>
#include <stdio.h>