Skip to content

Instantly share code, notes, and snippets.

@gmanley
gmanley / 1_parsing_numeral_dates.rb
Last active December 16, 2015 18:39
Ruby code snippets from my work in progress media file parser/renamer.
year = /(?<year>(20)?(07|08|09|10|11|12|13))/
month = /(?<month>0[1-9]|1[012])/
day = /(?<day>0[1-9]|\.[1-9]|[12][0-9]|3[01])/
NUMERAL_DATE_REGEX = /#{year}(?<separator>\.|\-|\/|_)?#{month}(\k<separator>)?#{day}/
NUMERAL_DATE_FORMAT = '[%y.%m.%d]'
# ...
def parse_numeral_date
if match = NUMERAL_DATE_REGEX.match(file_name)
@gmanley
gmanley / sphinx.rb
Last active December 15, 2015 17:18
Same as: https://raw.github.com/mxcl/homebrew/82cf700/Library/Formula/sphinx.rb but for sphinx 0.9.9 which some things require.
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@gmanley
gmanley / reimplement_group_by.rb
Created March 15, 2013 21:08
Just to illustrate how you would go about reimplementing group_by.
require 'rspec'
class Array
def custom_group_by(&block)
results = {}
each do |e|
(results[block.call(e)] ||= []) << e
end
@gmanley
gmanley / gist:5102114
Last active December 14, 2015 14:39
Quickly Host a Git Repository
# **Quickly Host a Git Repository**
REPO_ROOT='~/source/repos' # Can be anywhere
GIT_PROJECT_PATH='~/projects/my_cool_git_project' # Your local project using git
GIT_PROJECT_NAME=$(basename $GIT_PROJECT)
mkdir -p $REPO_ROOT
cd $REPO_ROOT
git clone --bare $GIT_PROJECT_PATH
cd $GIT_PROJECT_NAME.git
class Person
# extend and include go first
extend SomeModule
include AnotherModule
# constants are next
SOME_CONSTANT = 20
# afterwards we have attribute macros
attr_reader :name
@gmanley
gmanley / backtrace.log
Created February 14, 2013 09:39
sidekiq & zipruby segmentation fault info
2013-02-12T06:24:41Z 32462 TID-efyw0 AlbumArchiver JID-c3214393a6220b454bd095a9 INFO: start
/u/apps/example.com/releases/20130212062332/app/models/archive.rb:20: [BUG] Segmentation fault
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0033 p:---- s:0124 b:0124 l:000123 d:000123 CFUNC :open
c:0032 p:0182 s:0119 b:0119 l:0018d8 d:0018d8 METHOD /u/apps/example.com/releases/20130212062332/app/models/archive.rb:20
c:0031 p:0113 s:0114 b:0114 l:000113 d:000113 METHOD /u/apps/example.com/releases/20130212062332/app/workers/album_archiver.rb:14
c:0030 p:0025 s:0107 b:0107 l:000e30 d:000106 BLOCK /u/apps/example.com/shared/bundle/ruby/1.9.1/gems/sidekiq-2.7.2/lib/sidekiq/processor.rb:45
c:0029 p:---- s:0105 b:0105 l:000104 d:000104 FINISH
@gmanley
gmanley / gist:4657954
Last active December 20, 2016 17:10
Random avatar in plug.dj every 5 seconds.
(function randomAvatar() {
var userPoints = parseInt($('#user-points-value').text().replace(',', ''));
var avatars = [];
$.each(AvatarOverlay.avatarSets[0], function(i, value) {
if (value.required <= userPoints) {
avatars = avatars.concat(value.avatars);
};
});
<?php
/*
* jQuery File Upload Plugin PHP Class 6.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
---
libmpcodecs/vf_lavc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libmpcodecs/vf_lavc.c b/libmpcodecs/vf_lavc.c
index b2c1dd7..0ce98c0 100644
--- a/libmpcodecs/vf_lavc.c
+++ b/libmpcodecs/vf_lavc.c
@@ -76,7 +76,7 @@ static int config(struct vf_instance *vf,
return 0;