Skip to content

Instantly share code, notes, and snippets.

@MBahamondes
MBahamondes / ExitPageJS
Created March 5, 2015 12:48
Verificar que realmente quiere salir de la pagina
<script type="text/javascript" language="javascript">
var goodexit = false;
window.onbeforeunload = confirmRegisterExit;
function confirmRegisterExit(evt){
if(!goodexit){
return "Si vas Abandonar el sistema haz Click en Cerrar Sesion!!";
}
}
</script>
@MBahamondes
MBahamondes / ReplaceAccents
Created March 3, 2015 20:38
Reemplaza los carácteres con acentos a sin acentos
public static String ReplaceAccents(string str)
{
String normalizedString = str.Normalize(NormalizationForm.FormD);
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < normalizedString.Length; i++)
{
Char c = normalizedString[i];
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
{
strBuilder.Append(c);
@MBahamondes
MBahamondes / ParametersOpt
Created February 20, 2015 19:35
Parametros opcionales
// Método con los parámetros named y optional
public static void Search(string name, int age = 21, string city = "Pueblo")
{
Console.WriteLine("Name = {0} - Age = {1} - City = {2}", name, age, city);
}
static void Main(string[] args)
{
// Llamada estándar
Search("Sue", 22, "New York");
@MBahamondes
MBahamondes / SearchGoogle
Created February 4, 2015 18:01
Search In Google
private void btnSearchGoogle_Click(object sender, RoutedEventArgs e)
{
try
{
string page = "http://www.google.com/search?q=";
string query = "";
if (txtSearchGoogle.Text.Length > 0)
{
string[] buscar = txtSearchGoogle.Text.Split(' ');
foreach (string word in buscar)
public void ExpanderGrow(object sender, RoutedEventArgs e)
{
//expander principal del evento.
Expander expander = (Expander)sender;
Grid gridControl = (Grid)expander.Parent;
Controls.Control control = (Controls.Control)gridControl.Parent;
Grid gridMain = (Grid)VisualTreeHelper.GetParent((UIElement)control);
int index = Grid.GetRow((UIElement)control);
RowDefinition rowdef = gridMain.RowDefinitions[index];
@MBahamondes
MBahamondes / FunctionLetterByNumber
Created December 26, 2014 14:58
Function for determine what letter is the column by number.
'Function for determine what letter is the column by number.
Function Col_Letter(lngCol As Long) As String
Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function
@MBahamondes
MBahamondes / FilterListNumber
Created July 21, 2014 15:04
Filter List with numbers into string
//using LINQ filter list with string contains numbers.
listWords = listWords.Where(w => w.Any(c => Char.IsDigit(c))).ToList();
@MBahamondes
MBahamondes / TrendLine
Created July 18, 2014 14:13
Calculate Trend Line/ Tendencia
public class TrendLineController
{
// Metodo para Calcular la Linea de regresión, con un array de valores int.
public TrendLine CalculateLinearRegression(int[] values)
{
var yAxisValues = new List<int>();
var xAxisValues = new List<int>();
for (int i = 0; i < values.Length; i++)
{
@MBahamondes
MBahamondes / ListStringToDouble
Created July 14, 2014 20:42
List String To List Double
// Sentencia para transformar una lista de string, a una lista de Double.
List<double> lista = listaStrings.Select(x => double.Parse(x)).ToList();
@MBahamondes
MBahamondes / ChangeDataTypeDT
Last active August 29, 2015 14:03
Change DataType to DataTable With Data
// Con esto principalmente, formateamos el DataTable, para luego en un gridview darle formato numerico, fecha, porcentaje, etc.
protected DataTable CopyToDataTable (DataTable datatable, Type type)
{
DataTable dtCloned = null;
// Copiamos la Estructura de la tabla incluidos los esquemas y restricciones.
dtCloned = datatable.Clone();
// En este caso con un for, a partir de la tercera columna, cambiamos el tipo de data al que deseamos
for (int i = 3; i < dtCloned.Columns.Count; i++)
{