Skip to content

Instantly share code, notes, and snippets.

View maciej's full-sized avatar

Maciej Biłas maciej

View GitHub Profile
class Picture < ActiveRecord::Base
def self.new_from_flickr_photo(photo)
picture = Picture.new
picture.set_attributes_from_flickr_photo(photo)
picture
end
def set_attributes_from_flickr_photo(photo)
# copy whichever attributes you might need
@maciej
maciej / reload_tuntap.sh
Created July 4, 2011 15:45
Reloads tun and tap kernel extensions on OSX
#!/bin/bash
# Reloads tun and tap kernel extensions on OSX
# Sometimes helps with VPN not being able to connect
kextunload -b foo.tun
kextunload -b foo.tap
kextload /Library/Extensions/tun.kext
kextload /Library/Extensions/tap.kext
@maciej
maciej / mysql_drop_create.sh
Created August 16, 2011 12:06
Re-create a database in MySQL
#!/usr/bin/env bash
# Author: Maciej Bilas (@maciejb)
# Based on http://david-burger.blogspot.com/2010/01/truncate-all-tables-in-mysql-database_31.html
# https://gist.github.com/290596
usage() {
echo "\
Usage: $0 -u username -d database [-h host] [-o port)] \\
@maciej
maciej / create_entries.sh
Created October 3, 2011 15:26
Transforms SQL Import script into Java-like entries enum content
# TODO replace the magic 57 with an actual match of the prefix
perl -pe 's/.{57}('.*')\);$/\1/' entries.txt | tr "[:lower:]" "[:upper:]" | sed "s/'//g" | sed -E 's/([^A-Z])+/_/g' | perl -e '$i = 1; while (<>) {chomp; printf("%s(\"%04d\"),\n", $_, $i); $i = $i + 1}'
@maciej
maciej / purge-svn.sh
Created October 27, 2011 14:14
Remove all .svn folders
find . -name ".svn" -exec rm -rf {} \;
@maciej
maciej / init-scala.sh
Last active November 20, 2021 19:54
Bootstrap a Scala project (with SBT + IDEA)
#!/bin/bash
PROJECT_NAME="$1"
SCALA_VERSION="2.9.1"
SCALATEST_VERSION="1.6.1"
MOCKITO_VERSION="1.8.5"
mkdir $PROJECT_NAME
cd $PROJECT_NAME
@maciej
maciej / A.java
Created October 16, 2012 09:18
@Alternative and producer method
/**
* @author Maciej Bilas
* @since 16/10/12 11:01
*/
public class A {
private final boolean produced;
public A() {
this.produced = false;
@maciej
maciej / multimodule_assets.rb
Created February 6, 2013 09:54
Capistrano and multimodule projects
load 'deploy' unless defined?(_cset)
_cset :asset_env, "RAILS_GROUPS=assets"
_cset :assets_prefix, "assets"
_cset :assets_role, [:web]
_cset :normalize_asset_timestamps, false
before 'deploy:finalize_update', 'deploy:mm_assets:symlink'
after 'deploy:update_code', 'deploy:mm_assets:precompile'
@maciej
maciej / tell_when_deployed.rb
Last active December 15, 2015 10:19
Tells me when my app is deployed.
#!/usr/bin/env ruby
require 'rest-client'
sleep 4
loop do
sleep 1
response = begin
RestClient.get("http://localhost:8080/app/diagnostics.json")
@maciej
maciej / git-set-committer-to-author.sh
Created June 27, 2013 11:40
git: Changes a commit's GIT_COMMITER_NAME|EMAIL to GIT_AUTHOR_NAME|EMAIL
#!/bin/sh
#
# Changes a commit's GIT_COMMITER_NAME|EMAIL to GIT_AUTHOR_NAME|EMAIL
#
# set-commiter-to-author [-f] commit-to-change
#
# If -f is supplied it is passed to "git filter-branch".
#
# If <branch-to-rewrite> is not provided or is empty HEAD will be used.
# Use "--all" or a space separated list (e.g. "master next") to rewrite