Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
/// <summary>
/// Sort files
/// <code> string folder = "c:\\windows\\";
/// string[] files = Directory.GetFiles(folder);
/// IComparer comp = new FileComparer(FileComparer.CompareBy.FileSize);
/// Array.Sort(files, comp);
/// foreach(string file in files)
/// {
/// Console.WriteLine(file);
/// } </code>
private static int[] SelectionSort(int[] value)
{
if (value != null && value.Length > 1)
{
for (var targetIndex = 0; targetIndex < value.Length - 1; ++targetIndex)
{
var minIndex = targetIndex;
for (var index = targetIndex + 1; index < value.Length; ++index)
{
if (value[index] < value[minIndex])
using System.Configuration;
namespace CustomConfigurationSection
{
public class SmtpSettings : ConfigurationSection
{
[ConfigurationProperty("Url", DefaultValue = "smtp.returngis.com", IsRequired = true)]
public string Url
{
get
@huobazi
huobazi / for_win7
Created August 7, 2014 03:06
Map caps lock to escape in Windows
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,46,00,01,00,3a,00,00,00,00,00
@huobazi
huobazi / README.md
Last active August 29, 2015 14:06 — forked from chrisbloom7/README.md

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@huobazi
huobazi / csrf.js
Created November 18, 2014 06:24
csrf token utility file
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
var token;
if (!options.crossDomain) {
token = $('meta[name="csrf-token"]').attr('content');
if (token) {
return jqXHR.setRequestHeader('X-CSRF-Token', token);
}
}
});
@huobazi
huobazi / google_analytics.js.erb
Created November 18, 2014 06:46
app/assets/javascripts/google_analytics.js.erb:
<% if Rails.env == 'production' %>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-XX']);
_gaq.push(['_trackPageview']);
ga_src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
$.externalScript(ga_src).done(function(script, textStatus) {
console.log('Script loading: ' + textStatus );
if (typeof _gat != 'undefined') {
console.log('Okay. GA file loaded.');
}
@huobazi
huobazi / gist:b9e335523ea5602a367d
Created November 20, 2014 07:54
bootstrap modal center
var setCenterModal = function () {
$(this).css('display', 'block');
var $dialog = $(this).find(".modal-dialog");
var offset = ($(window).height() - $dialog.height()) / 2;
$dialog.css("margin-top", offset);
};
$('.modal').on('show.bs.modal', setCenterModal);
$(window).on("resize", function () {
@huobazi
huobazi / random.rb
Last active August 29, 2015 14:10 — forked from adambird/random.rb
def random_string
(0...24).map{ ('a'..'z').to_a[rand(26)] }.join
end
def random_symbol
random_string.to_sym
end
def random_integer
rand(9999)
@huobazi
huobazi / gist:f5ac253e8446230b2dd3
Last active August 29, 2015 14:10
Automatic redirect from HTTP to HTTPS
if(window.location.protocol != 'https:') {
window.location.href = window.location.href.replace("http://", "https://");
}
// or
if (window.location.protocol != "https:"){
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
}