Skip to content

Instantly share code, notes, and snippets.

View jrgcubano's full-sized avatar

Jorge Rodríguez Galán jrgcubano

View GitHub Profile
@jrgcubano
jrgcubano / TypeFinderDomain.cs
Created January 28, 2015 11:07
Type discovery in Assemblies using Attributes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace AssemblyDiscoveryConsole
{
// The attribute class you are looking for within external assemblies
public class SomeAttribute : Attribute
@jrgcubano
jrgcubano / II7Administration.cs
Created January 28, 2015 11:09
IIS7 Administration from code
// Add a reference to the Microsoft.Web.Administration assembly.
// Note:
// 1) Make sure you have IIS7 Features turned on for this library to be available (Windows features).
// 2) Ensure that you have a reference to System.ServiceModel.
// 3) Ensure that your target framework is .Net Framework 4.
// Location:
// C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll
// Resources:
// http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx
@jrgcubano
jrgcubano / HotkeysExample.cs
Created January 29, 2015 10:49
WPF Window System-wide hotkeys
// Xaml window example code
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+Alt+Add" Command="{Binding IncrementCommand}" />
<KeyBinding Gesture="Ctrl+Alt+Subtract" Command="{Binding DecrementCommand}" />
</Window.InputBindings>
// use globally with NHotkey (https://github.com/thomaslevesque/NHotkey)
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+Alt+Add" Command="{Binding IncrementCommand}"
HotkeyManager.RegisterGlobalHotkey="True" />
@jrgcubano
jrgcubano / ConfigHelper
Created February 3, 2015 11:54
Snippet to get AppSettings from ConfigurationManager
SNIPPETS: GET APPSETTINGS FROM XXX.CONFIG IN A GENERIC WAY
This snippet can be used in all web projects where there is a need to get settings from the AppSettings section in web.config.
INITIAL SNIPPET:
?
public static T GetAppSetting<T>(string key, T defaultValue)
{
if (!string.IsNullOrEmpty(key))
{
string value = ConfigurationManager.AppSettings[key];
@jrgcubano
jrgcubano / SchemaValidator.js
Created February 16, 2015 02:25
Schema Validation using jayschema
var ErrorMapper = require('./ErrorMapper');
var formConverter = require('./formConverter');
var JaySchema = require('jayschema');
var util = require('util');
var js = new JaySchema();
function SchemaValidator (schema) {
return function SchemaValidator (req, res, next) {
js.validate(req.body, schema, function (errors) { //REVIEW
if (errors) {
@jrgcubano
jrgcubano / gist:e30d36c2306c91de17f5
Last active August 29, 2015 14:15
Running Express.js in Production Mode
// First export vars
echo export NODE_ENV=production >> ~/.bash_profile
$ source ~/.bash_profile
// then start the serverin some mode (production default)
NODE_ENV=testing node app.js
Load the environment config in ./config/index.js
@jrgcubano
jrgcubano / ClickSelectedTextBox.cs
Last active August 29, 2015 14:15
WPF ClickSelectableTextBox for tablets
//
// Deriving from TextBox
//
public class ClickSelectTextBox : TextBox
{
public ClickSelectTextBox()
{
AddHandler(PreviewMouseLeftButtonDownEvent,
new MouseButtonEventHandler(SelectivelyIgnoreMouseButton), true);
AddHandler(GotKeyboardFocusEvent,
@jrgcubano
jrgcubano / ReadOnlyTextBox.xaml
Created February 23, 2015 10:15
TextBox that's Read Only which just looks like a TextBlock
<Style x:Key="ReadOnlyTextBox" TargetType="TextBox">
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Padding" Value="5"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="VerticalScrollBarVisibility" Value="Disabled"/>
Steps:
0. Checkout your git repo from the server (I use /var/www/carbonite)
1. Upload both of these files to the same directory on your server
2. chmod +x restart_node.sh
3. nohup node github_post_commit.js 2>&1 >> github_post_commit.log &
4. In the github admin for your repo, set a post commit hook to the url http://<your host>:8080/
5. Make a commit to your repo
6. Point a browser at http://<your host>:8080/ and you should see the commit
@jrgcubano
jrgcubano / RespuestasFiesta
Created February 27, 2015 08:26
Super gifts de respuestas al salir de fiesta para slides
http://www.cribeo.com/estilo_de_vida/6857/respuestas-al-salir-de-fiesta-a-los-18-vs-respuestas-salir-de-fiesta-a-los-25