Skip to content

Instantly share code, notes, and snippets.

@raymondberg
raymondberg / gist:a0845ba4b4de2cdd0f9d
Created April 4, 2015 22:06
WHAT THE FFFFF Ruby?!?
# Taken from http://rubykoans.com/
# about_array_assignments.rb
def test_default_value_is_the_same_object
hash = Hash.new([])
hash[:one] << "uno"
hash[:two] << "dos"
assert_equal ["uno","dos"], hash[:one]
require 'json/stream'
class MonsterParser
FILE_BUFFER_SIZE = 1024
def initialize(file_path,xpath)
@file_obj = File.open(file_path,'r')
@element_stack = []
@raymondberg
raymondberg / README.md
Last active October 23, 2015 03:19
Quick Setup of PSEUDO-RANDOM Record sorting with Grouping

Problem

Group rows with a certain record value together but randomize the rest.

SQLITE Setup Commands

.open newdb.sqlite
.load ./digest.so
@raymondberg
raymondberg / setup.md
Last active December 27, 2016 00:52
First-time developer station setup to not go insane

All

  • Install RVM
  • Install Ruby
  • Install Dotfiles
  • Install Anaconda

Mac

  • Set Terminal interface to Pro
  • Set Terminal->Advanced->Allow VT100 application Keypad mode to True
@raymondberg
raymondberg / README.md
Last active July 17, 2017 17:46
SQLITE Problem in Python

Project 6 - Basic SQL Querying

This project covers the basic concepts behind querying with Python.

Problem

We have a movie database that's fairly comprehensive. We'd like to explore it a bit with Python. Here are the columns:

movie_title color num_critic_for_reviews movie_facebook_likes duration director_name director_facebook_likes actor_3_name actor_3_facebook_likes actor_2_name actor_2_facebook_likes actor_1_name actor_1_facebook_likes gross genres num_voted_users

@raymondberg
raymondberg / 1_basic.rb
Last active January 29, 2018 15:32
Advisory Lock Sample - Try running in Rails Consoles in separate processes
## Run alongside self
count=0
while true
Rails.logger.tagged(Process.pid) do
Dispute.with_advisory_lock("hamster_dance") do
Rails.logger.info "Doing hamster dance #{count}!"
@raymondberg
raymondberg / example.py
Created June 13, 2018 04:26
What happens to context managed resources in a return
class Thing():
def __init__(self):
self.name = 'thing'
print('setup')
def __enter__(self):
print('enter')
return self
def __exit__(self, *args):
@raymondberg
raymondberg / game.py
Created July 23, 2018 23:44
Tucker's Snake Game
import pygame, sys
from pygame.locals import *
pygame.init()
board_color = (168, 173, 181)
line_color = (100, 100, 100)
DISPLAYSURF = pygame.display.set_mode((1000, 500))
pygame.display.set_caption('G R A P H G A M E !')
@raymondberg
raymondberg / example.txt
Created October 2, 2018 16:26
Explaining module imports in python
- bin
- theirmod
- __init__.py/
- mymod/
- __init__.py
- more/
- __init__.py
- other.py
- magic.py
@raymondberg
raymondberg / column_collapser
Created October 5, 2018 12:35
Collumn-Collapser - Simple tool for removing extra commas
#!/usr/bin/python
import sys, csv, re
class ColumnCollapser:
@classmethod
def _safe_print(cls, content):
print(re.sub(r"[0-9]{13,16}","[COLLAPSERFILTERED]", str(content)))
@classmethod
def _handle(cls, header, index, row):