Skip to content

Instantly share code, notes, and snippets.

View rmariuzzo's full-sized avatar
🤒
Fighting a cancer.

Rubens Mariuzzo rmariuzzo

🤒
Fighting a cancer.
View GitHub Profile
@rmariuzzo
rmariuzzo / hex2int
Created January 26, 2012 13:09
A simple JavaScript function to convert an hexadecimal value into its integer base-10 equivalent.
/**
* Convert an hexadecimal value in a integer base-10.
* @param hex An hexadecimal value to convert.
* @return An integer base-10 equivalent to the given hexadecimal value.
*/
function hex2int(hex) {
return parseInt(hex, 16);
}
@rmariuzzo
rmariuzzo / palindrome.js
Created March 16, 2012 05:20
Contest: 1 line of JS: Smallest Palindrome Checker
/**
* Check if a word or phrase is a palindrome in 106 characters of JavaScript.
*/
function isPalindrome(s) {
return s.match(/[a-zA-Z]/g).join('').toLowerCase()==s.match(/[a-zA-Z]/g).reverse().join('').toLowerCase();
}
@rmariuzzo
rmariuzzo / GetExpressionText.cs
Last active December 12, 2015 04:48
A better `ExpressionHelper.GetExpressionText` that handles Convert Expression.
/// <summary>
/// Return the expression text
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="expression"></param>
/// <returns></returns>
public static string GetExpressionText<TModel>(Expression<Func<TModel, object>> expression)
{
var expr = (LambdaExpression)expression;
if (expr.Body.NodeType == ExpressionType.Convert)
@rmariuzzo
rmariuzzo / TwitterBootstrapColumnsInRazor.cs
Created February 25, 2013 13:12
Create columns using Twitter Bootstrap in Razor with C#.
for (var i = 0; i < list.Count; i++)
{
var first = i == 0;
var last = i == list.Count - 1;
var current = i + 1;
var previous = i;
if (first || previous % 3 == 0)
{
@Html.Raw("<div class=\"row\">");
/// <summary>
/// Return the full name of an entity.
/// </summary>
public String FullName()
{
get
{
return String.Join(" ", new String[] { this.FirstName, this.MiddleName, this.LastName, this.SecondLastName });
}
}
@rmariuzzo
rmariuzzo / Preferences.sublime-settings.json
Created March 8, 2013 13:36
Personal `Preferences.sublime-settings` file for Sublime Text 2.
{
"color_scheme": "Packages/Color Scheme - Default/Cobalt.tmTheme",
"detect_slow_plugins": false,
"dictionary": "Packages/Language - English/en_US.dic",
"font_size": 11,
"ignored_packages":
[
"Vintage"
],
"ignored_words":
@rmariuzzo
rmariuzzo / chrome.css
Created July 13, 2013 17:07
Google Chrome button styles when "webpage is not available".
button {
border: 1px solid rgba(0, 0, 0, 0.25);
border-radius: 2px;
color: #444;
margin: 0px 5px;
min-height: 29px;
min-width: 65px;
-webkit-user-select: none;
padding: 8px 13px;
/* iOS does not support linear-gradient without a prefix. */
@rmariuzzo
rmariuzzo / listen-illuminate-query.xml
Created July 28, 2013 23:27
Sublime Text 2 snippet to listen for illuminate query on Laravel 4. Useful for profiling generated SQL queries.
<snippet>
<content><![CDATA[
Event::listen('illuminate.query', function($sql) {dd($sql);});
]]></content>
<tabTrigger>sql</tabTrigger>
<scope>source.php</scope>
</snippet>
@rmariuzzo
rmariuzzo / compile-js.sh
Last active December 21, 2015 14:39
A simple NodeJS script to watch for changes in a specific less and js file. When changes detected then bash script will be executed for to compile less files and to uglify js scripts.
clear
curdir="${0%/*}"
uglifyjs -v \
$curdir/jquery/jquery.js \
$curdir/twbs/js/bootstrap.js \
$curdir/superfish/superfish.js \
$curdir/site/js/site.js \
-o $curdir/../../js/app.js \
-m
echo 'JS files compiled successfully!'
@rmariuzzo
rmariuzzo / CustomValidator.php
Created October 8, 2013 04:38
A simple Laravel 4 validator that ensure the field under validation must match the format defined according to the `Carbon\Carbon::createFromFormat` method.
<?php
use Carbon\Carbon;
use Illuminate\Validation\Validator;
class CustomValidator extends Validator {
# carbon_date_format #
public function validateCarbonDateFormat($attribute, $value, $parameters)