Skip to content

Instantly share code, notes, and snippets.

@Usse
Usse / scrape.js
Created November 24, 2012 11:26
Web scraping in node.js
var request = require("request");
request({
uri: "http://www.google.com",
}, function(error, response, body) {
console.log(body);
});
@Usse
Usse / crawl.rb
Created November 27, 2012 13:12
Web crawler examples with ruby and Nokogiri
#
# Web crawler examples
#
require 'rubygems'
require 'nokogiri'
require 'open-uri'
@Usse
Usse / backward.js
Created December 3, 2012 13:19
jQuery backward each
jQuery.fn.reverse = [].reverse;
$(elements).reverse().each(function(index,item) {
//...some awesome code
});
@Usse
Usse / cookies.js
Created December 6, 2012 09:32
Gets or sets cookies
/**
* Gets or sets cookies
* @param name
* @param value (null to delete or undefined to get)
* @param options (domain, expire (in days))
* @return value or true
*/
_.cookie = function(name, value, options)
{
if (typeof value === "undefined") {
@Usse
Usse / pngFix.js
Created January 18, 2013 10:42
Fix for PNG transparency issue in IE when fading images
var i;
for (i in document.images) {
if (document.images[i].src) {
var imgSrc = document.images[i].src;
if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
}
}
}
@Usse
Usse / mediaQuery.css
Created January 24, 2013 13:02
Usefull Mediaquery to target the mobile world
/* Smartphones (portrait and landscape) */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {}
/* Smartphones (landscape) */
@media only screen and (min-width : 321px) {}
/* Smartphones (portrait) */
@media only screen and (max-width : 320px) {}
/* iPads (portrait and landscape) */
@Usse
Usse / clearfix.scss
Created February 3, 2013 16:03
Sass version of clearfix
.cf {
zoom: 1;
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
}
@Usse
Usse / server.js
Created February 27, 2013 09:20
Node.js server file that redirect all the paths without extension to the index. Usefull for AngularJS development.
var serverPort = 3000;
var express = require("express"),
app = express(),
port = serverPort;
app.use(express.methodOverride());
app.use(express.bodyParser());
@Usse
Usse / test_if_hashtag.js
Created April 29, 2013 16:36
Wrap with an <a> element all the '#tag' occurrences in a string. Usefull for twitter json.
function test_if_hashtag(string) {
var thestring=string;
var pattern = /#([a-zA-Z0-9]+)/g;
return thestring.replace(pattern, "<a href='https://twitter.com/search?q=%23$1' target='_blank'>#$1</a>");
}
@Usse
Usse / test_if_link.js
Created April 29, 2013 16:37
Wrap with an <a> element all the link occurrences in a string.