Skip to content

Instantly share code, notes, and snippets.

View victorbstan's full-sized avatar

Victor Stan victorbstan

  • Toronto & Remote
View GitHub Profile
@victorbstan
victorbstan / profile_photop.rb
Created June 14, 2013 02:49
A module for defaulting to a gravatar image when your profile's own paperclip image isn't available.
require 'digest/md5'
module ProfilePhoto
def profile_photo(profile)
profile.avatar.url(:thumb).present? ? profile.avatar.url(:thumb) : "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(profile.owner.email)}?d=mm"
end
end
# in your application_helper use:
# module ApplicationHelper
@victorbstan
victorbstan / webScraperTest.st
Created March 20, 2013 02:57
Quick and dirty test web scraper in Smalltalk (Pharo2). Simply put it in a "workspace" and "do it". The response output is sent to a "Transcript" window.
| myHost myPath |
"setup"
myHost := 'rmod.lille.inria.fr'.
myPath := '/pbe2'.
ZnClient new
systemPolicy;
accept: ZnMimeType textHtml;
http;
@victorbstan
victorbstan / application.css.scss
Last active December 14, 2015 10:38
Overriding will_paginate gem to provide a drop-down select html tag list for all the page.
.pagination {
display:inline-block;
form {
display: inline-block;
margin:0;
select {
width:100px;
}
}
}
@victorbstan
victorbstan / clips.html
Created August 25, 2012 20:34
Angular JS and Rails 3 Infinite Scroll Pagination
<!--
This is the HTML portion of the infinite scroll/pagination with Rails and AngularJS tutorial
Required libraries for the tutorial and indicated as "Important",
together with implementation specific libraries marked as "Optional"
-->
<!DOCTYPE html>
<html>
<title>Clips</title>
<!-- Important -->
@victorbstan
victorbstan / angular_vs_jquery.js
Created July 8, 2012 02:36
AngularJS vs JQuery for basic GET POST AJAX API
var DOMAIN = 'http://localhost'
var PORT = 3000;
var DATA_SOURCE = '/clips.json';
// ANGULAR
function clips_controller($scope, $http) {
$scope.clips = [];
// get the data from the API backend
$http.get(DOMAIN+":"+PORT+DATA_SOURCE).success(function(data) {
var html5rocks = {};
var indexedDB = window.indexedDB || window.webkitIndexedDB ||
window.mozIndexedDB;
if ('webkitIndexedDB' in window) {
window.IDBTransaction = window.webkitIDBTransaction;
window.IDBKeyRange = window.webkitIDBKeyRange;
}
html5rocks.indexedDB = {};
@victorbstan
victorbstan / flotr2_defaults.js
Created April 26, 2012 15:57
Flotr2 Defaults
(/**
* Flotr Defaults
*/
Flotr.defaultOptions = {
colors: ['#00A8F0', '#C0D800', '#CB4B4B', '#4DA74D', '#9440ED'], //=> The default colorscheme. When there are > 5 series, additional colors are generated.
ieBackgroundColor: '#FFFFFF', // Background color for excanvas clipping
title: null, // => The graph's title
subtitle: null, // => The graph's subtitle
shadowSize: 4, // => size of the 'fake' shadow
defaultType: null, // => default series type
@victorbstan
victorbstan / created_at_yesterday.rb
Created March 20, 2012 19:27
Get items created yesterday from a Rails app using AR
FieldUpdate.where("created_at < ?", Date.today)
@victorbstan
victorbstan / video_pyopencv.py
Created March 20, 2012 02:07 — forked from kriben/video_pyopencv.py
Python opencv feed from webcam
import opencv
#this is important for capturing/displaying images
from opencv import highgui
import pygame
import sys
camera = highgui.cvCreateCameraCapture(0)
def get_image():
im = highgui.cvQueryFrame(camera)
# Add the line below if you need it (Ubuntu 8.04+)
@victorbstan
victorbstan / paperclip_image_dimensions_validation.rb
Created November 23, 2011 01:21
Paperclip Validate minimum image dimensions
validate :check_dimensions
def check_dimensions
temp_file = background_image.queued_for_write[:original]
unless temp_file.nil?
dimensions = Paperclip::Geometry.from_file(temp_file)
width = dimensions.width
height = dimensions.height
if width < 800 && height < 600