Skip to content

Instantly share code, notes, and snippets.

@CUXIDUMDUM
CUXIDUMDUM / ruby_meta.md
Created June 21, 2016 19:47 — forked from jamesyang124/ruby_meta.md
Ruby meta programming

#!/bin/ruby --verion => 2.0.0-p353

Self

In Ruby, self is a special variable that always references the current object.

  • Inside class or module definition, self refer to the Class or Module object.
  • Inside instance method, self refer to future instance object.
  • Inside class method, self refer to the class.i
@CUXIDUMDUM
CUXIDUMDUM / snake.py
Created March 21, 2016 11:20 — forked from sanchitgangwar/snake.py
Snakes Game using Python
# SNAKES GAME
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
curses.initscr()
win = curses.newwin(20, 60, 0, 0)
@CUXIDUMDUM
CUXIDUMDUM / VirtualBoxKickstart.md
Created December 26, 2015 18:51 — forked from jtyr/VirtualBoxKickstart.md
How to use kickstart in VirtualBox

How to use kickstart in VirtualBox

This short howto describes how to install VMs via kickstart in VirtualBox. It's using PXE functionality built into the NAT network mode of the VirtualBox. The following instructions apply to CentOS installation but it should work for any RedHat-based distro.

Prepare directory structure

@CUXIDUMDUM
CUXIDUMDUM / ruby logging
Created September 5, 2015 18:50
ruby logging both class and instance level
module Log
def Log.included cls
cls.extend Log #also works by passing self, but Log is less confusing
end
def log str
p str
end
end
class Thing
@CUXIDUMDUM
CUXIDUMDUM / gist:91c4482ef486aee20bb6
Last active August 29, 2015 14:21
python logging
#https://github.com/timwarnock/daemonize/blob/master/Log.py
#https://github.com/search?l=python&p=4&q=class+threading.Thread+multiprocessing+python+logging&ref=searchresults&type=Code&utf8=%E2%9C%93
# vim: set tabstop=4 shiftwidth=4 autoindent smartindent:
'''
simple thread-safe logging adapter
Assigns log handlers to the logging module, you can use logging module methods directly or
create additional loggers that will inherit these handlers, e.g.,
import Log, logging
@CUXIDUMDUM
CUXIDUMDUM / gist:a38410ea1b23aed6431a
Last active August 29, 2015 14:21
non blocking thread stdout
import threading
import subprocess
import logging
import os
import fcntl
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
import logging
from multiprocessing.dummy import Pool
import threading
import random
import time
import Queue
class Foo(object):
def __init__(self):
!/usr/bin/python
import Queue
import threading
import time
class workerthread(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
while installing puppet on vagrant ubuntu
vagrant@puppetmaster:~$ sudo service apache2 start
* Starting web server apache2 Syntax error on line 19 of /etc/apache2/sites-enabled/puppetmaster:
SSLCertificateKeyFile: file '/var/lib/puppet/ssl/private_keys/puppetmaster.example.com.pem' does not exist or is empty
Action 'start' failed.
The Apache error log may have more information.
vagrant@puppetmaster:~$ sudo puppet cert revoke puppetmaster.example.com
err: Could not call revoke: Could not find a serial number for puppetmaster.example.com
vagrant@puppetmaster:~$ sudo puppet cert revoke puppet
#!/usr/bin/env python
import logging
import multiprocessing as mp
import os
import okaara
import subprocess
import sys
import signal
import textwrap