Skip to content

Instantly share code, notes, and snippets.

@stansidel
stansidel / activate_swap.sh
Last active August 29, 2015 13:56
Activate swap file on Ubuntu (based on the tutorial for DigitalOcean - https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04)
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0 " | sudo tee -a /etc/fstab
echo 0 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 0 | sudo tee -a /etc/sysctl.conf
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
swapon -s
@seyDoggy
seyDoggy / config for vim 7.4 with lua on ubuntu 13.04
Last active December 24, 2015 05:09
I was having trouble getting lua support while rolling my own vim 7.4 on ubuntu 13.04.
sudo apt-get install liblua5.1-dev
sudo mkdir /usr/include/lua5.1/include/
sudo cp /usr/include/lua5.1/* /usr/include/lua5.1/include/
sudo ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.so /usr/local/lib/liblua.so
hg clone https://code.google.com/p/vim/
cd vim
./configure --with-features=huge \
--enable-perlinterp \
--enable-rubyinterp \
--enable-pythoninterp=yes \
@jamband
jamband / _form.twig
Last active November 15, 2017 19:07
Yii Framework & Twig: layouts/column1.twig
<div class="form">
{% set form = this.beginWidget('CActiveForm', {
'id': 'hoge-form',
'enableAjaxValidation': false,
}) %}
<p class="note">Fields with <span class="required">*</span> are required.</p>
{{ form.errorSummary(model) }}
@lodestone
lodestone / install-macvim-with-lua.sh
Created January 25, 2014 09:17
brew install macvim with lua
brew install macvim --with-cscope --with-lua --override-system-vim
@andreynovikov
andreynovikov / OnItemSelectedListener.java
Last active June 14, 2020 17:43
Complete working solution for Android action bar tabs with fragments having separate back stack for each tab.
// Custom interface that enables communication between Fragment and its Activity
public interface OnItemSelectedListener
{
public void onItemSelected(String item);
}
@neilpa
neilpa / CStringArray.swift
Last active August 7, 2020 02:24
Swift wrappers for C functions taking char** arguments
// Usage
let argv = CStringArray(["ls", "/"])
posix_spawnp(nil, argv.pointers[0], nil, nil, argv.pointers, nil)
// Is this really the best way to extend the lifetime of C-style strings? The lifetime
// of those passed to the String.withCString closure are only guaranteed valid during
// that call. Tried cheating this by returning the same C string from the closure but it
// gets dealloc'd almost immediately after the closure returns. This isn't terrible when
// dealing with a small number of constant C strings since you can nest closures. But
@robcowie
robcowie / timestamp.py
Created October 28, 2011 19:13
Insert date and time stamps in Sublime Text 2
# -*- coding: utf-8 -*-
from datetime import datetime
import sublime_plugin
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date` and `time`
"""
@nruth
nruth / gist:1264245
Last active August 23, 2021 01:57
Shared Capybara (or model setup) helpers for RSpec and Cucumber
# Let's assume you're driving Capybara in both RSpec request specs & Cucumber,
# for example you're using Cucumber as a design/documentation tool, and RSpec
# for the more boring integration tests.
# You don't want to duplicate your click-this-click-that helpers to e.g.
# log_in(username, password).
# You may also have model state setup code which can be shared/reused.
# Where can it go? How can it be loaded? I've been using the following approach:
#
@ronanguilloux
ronanguilloux / script-bash-redmine-backups
Last active September 17, 2021 06:32 — forked from gabrielkfr/script-bash-redmine-backups
Backup script (daily & monthly) for Redmine (full instance + db sql snapshot)
#! /bin/bash
#
# backup_redmine.sh
# modified by ronan@lespolypodes.com
# Inspiration: https://gist.github.com/gabrielkfr/6432185
#
# Distributed under terms of the MIT license.
# -- VARS
DAY=`date +"%Y%m%d"`
@t2
t2 / application.rb
Created December 12, 2011 02:13
Formatting Rails form elements for Twitter Bootstrap error validation
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe