Skip to content

Instantly share code, notes, and snippets.

View girasquid's full-sized avatar
🦐

Luke Hutscal girasquid

🦐
View GitHub Profile
@girasquid
girasquid / striped_box.rb
Last active October 13, 2023 00:20
This is a helper method that makes you a box filled with diagonal stripes. You can pass in the spacing between stripes, as well as any extras you want applied to the border or lines (ex. colors)
def striped_box(x, y, w, h, spacing=10, border_extra={}, line_extra={})
primitives = []
border_box = {
x: x,
y: y,
w: w,
h: h,
}
primitives << border_box.merge(primitive_marker: :border).merge(border_extra)
top_corner_x = x
@girasquid
girasquid / gist:1453265
Created December 9, 2011 20:59
How to save a file to a FileField in Django without writing the entire row.
instance.file_field.save(the_filename, file_content, save=False)
MyModel.objects.filter(id=instance.id).update(file_field=instance.file_field)
context "making sure we don't accidentally take the site down" do
EXPECTED_NUMBER_OF_WORKERS = 10 # copy this value from the other place it's defined; this shouldn't be dynamic, repeating yourself is better
it "reminds the user of side effects" do
begin
expect(MySystem::NUMBER_OF_WORKERS).to eq(EXPECTED_NUMBER_OF_WORKERS)
rescue RSpec::Expectations::ExpectationNotMetError => error
error.message << "\n"
error.message << <<~HEREDOC
📎 Oh hi there! It looks like you changed the value of MySystem::NUMBER_OF_WORKERS.
@girasquid
girasquid / s3store.py
Created February 9, 2010 19:46
Turn S3 into a key/value store for JSON objects.
import simplejson
from boto.s3.connection import S3Connection
from boto.s3.key import Key
class S3KeyStore(object):
def __init__(self, access_key, secret_key, bucket):
self.conn = S3Connection(access_key, secret_key)
self.bucket = self.conn.create_bucket(bucket)
def get(self, key):
@girasquid
girasquid / Timer.cs
Created July 14, 2018 17:49
Simple countdown timer for Unity projects that updates a Text (you supply the Text and how many seconds to start at)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class CountdownTimer : MonoBehaviour {
public Text timerText;
public int startingSeconds;
package {
import starling.core.Starling;
import starling.animation.Transitions;
import starling.animation.Tween;
public class Utils {
// This function accepts an originalX and originalY so that you can shake things that
// are on screen but not necessarily originally located at 0, 0 (compared to the original
// implementation which only ever moved things back to 0, 0)
public static function screenShake(drawable:Shakeable, shakeDuration:Number, intensity:Number, originalX:Number, originalY:Number):void {
@girasquid
girasquid / dictionary_words.sh
Created November 26, 2016 16:04
Get all words that are between 3 and 6 characters long from your system's dictionary, and then format them so that you can drop them into an array.
cat /usr/share/dict/words | grep '.\{3\}' | grep -v '.\{6\}' | sed 's/^/"/;s/$/",/' | pbcopy
@girasquid
girasquid / project-age.sh
Created July 19, 2016 00:28
Bash script that calculates age of each folder in a directory, based on git commits
#!/usr/bin/env bash
# http://www.daveeddy.com/2014/06/29/human-readable-duration-in-bash/
human() {
local seconds=$1
if ((seconds < 0)); then
((seconds *= -1))
fi
local times=(
@girasquid
girasquid / log.as
Last active January 3, 2016 19:59
AS3 logging helper
// util/log.as
package util {
import flash.system.Security;
import flash.external.ExternalInterface;
public function log(message:String):void {
flash.system.Security.allowDomain('*');
flash.system.Security.allowInsecureDomain('*');
ExternalInterface.call('console.log', message);
}
}

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash