Skip to content

Instantly share code, notes, and snippets.

rails console
user = User.new
user.orders << Order.create!
user.save
#will create a User with a single new Order
@vannell
vannell / loc.bash
Last active December 21, 2015 01:39
Count LOC in files without taking commented or empty lines
#!/bin/bash
#Description count LOC in files without taking commented or empty lines
if [[ $# < 1 ]]
then
echo Give me some folder to count into
echo Add some options that will be passed to find after
echo "loc <folder> [options]"
exit 0
fi
@vannell
vannell / mark.bash
Last active December 21, 2015 06:08
Jump around your folders
#!/bin/bash
#This is free adaptation of an idea exposed at http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
#Include this directly in your .bashrc or source it
#Examples:
# [very/deep/path] $ mark deep
# [other/location] $ jmp deep
# $ mark list #will list all your marks
# $ unmark deep
@vannell
vannell / Listener.h
Created August 18, 2013 16:12
C++ dummy Observer
#ifndef LISTENABLE_H
#define LISTENABLE_H
class Listener {
};
#endif
@vannell
vannell / gen_model.rb
Last active December 31, 2015 03:09
Q_PROPERTY script generator. Generate getter/setter/notifier based on property type/name
#!/usr/bin/env ruby
#
# generate property based QObject with common getter/setter
# Just implement for my naming conventions :
# Ex: for a new class MyGeneratedObject
# => header file my_generated_object.h
# => source file my_generated_object.cpp
# A property double value
# => member variable: double m_value
# => getter: double value() const;
@vannell
vannell / setup.py
Created December 13, 2013 08:51
py2exe bundling
#!/usr/bin/env python
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'dll_excludes': ['w9xpopen.exe']}},
console=['foobar.py'],
zipfile = None
)
#As readlink is not available on all distro or OSX, provide a portable way to get an
#absolute path from a relative one.
make_absolute() {
local ret=false
local rel_path=$1
if [[ ! -z $rel_path ]]; then
#strip eventual last slash
rel_path=${rel_path%/}
@vannell
vannell / gist:58ef3d4d2bde4aa6e584
Created June 17, 2014 12:15
C++ Static initialization
class A {
static T a;
static T initStaticA() {
T t;
//do some stuff on t
return t;
}
};
@vannell
vannell / downloader.cpp
Created June 29, 2014 16:12
Qt download test
#include "downloader.hpp"
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QVariant>
#include <QDebug>
Downloader::Downloader(QObject *parent) :
QObject(parent)
{
@vannell
vannell / .bashrc
Created October 15, 2014 10:16
Bash PS1 git aware
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset