Skip to content

Instantly share code, notes, and snippets.

View rionmonster's full-sized avatar

Rion Williams rionmonster

View GitHub Profile
@rionmonster
rionmonster / GlyphClassCompletionListProvider.cs
Created January 30, 2017 16:06
Example of Manual Package Loading
[HtmlCompletionProvider(CompletionTypes.Values, "*", "class")]
[ContentType("htmlx")]
class GlyphClassCompletionListProvider : BaseClassCompletionProvider
{
private static bool _glyphsLoaded;
public override string CompletionType
{
get { return CompletionTypes.Values; }
}
@rionmonster
rionmonster / VSPackage.cs
Created December 29, 2016 22:31
Is this sufficient enough to load contents for MEF Components?
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class ExamplePackage : Package
{
protected override async task Initialize()
{
// Load necessary stuff for MEF Component here
base.Initialize();
}
}
[HtmlCompletionProvider(CompletionTypes.Values,"*", "class")]
[ContentType(HtmlContentTypeDefinition.HtmlContentType)]
class FooBarClassCompletion : BaseCompletionProvider
{
private static List<string> _classes = new List<string>()
{
"foo",
"bar",
};
@rionmonster
rionmonster / AuditAttribute.cs
Created December 2, 2016 20:22
Example with Possible NHibernate Implementation
public class AuditAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//Stores the Request in an Accessible object
var request = filterContext.HttpContext.Request;
//Generate an audit
Audit audit = new Audit()
{
//Your Audit Identifier
@rionmonster
rionmonster / IQueryableExtensions
Last active November 9, 2022 16:39
Resolve the SQL being executed behind the scenes in Entity Framework Core
public static class IQueryableExtensions
{
private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo();
private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.First(x => x.Name == "_queryCompiler");
private static readonly PropertyInfo NodeTypeProviderField = QueryCompilerTypeInfo.DeclaredProperties.Single(x => x.Name == "NodeTypeProvider");
private static readonly MethodInfo CreateQueryParserMethod = QueryCompilerTypeInfo.DeclaredMethods.First(x => x.Name == "CreateQueryParser");
// This indicates that this function is going to extend from jQuery
// and it accepts a jQuery selector as a parameter
$.fn.randomize = function(selector){
// This will attempt to find a selector if one exists (this.find(selector)) or it will use the current object (this)
// And it will target the parent of whatever is selected
(selector ? this.find(selector) : this).parent().each(function(){
// It will then target all of the children below this selector and sort each of them based off of a randomly generated value
// from Math.random(). This will apply the order to the elements
$(this).children(selector).sort(function(){
return Math.random() - 0.5;
// This accepts a string numbuer and will increment the numeric part by 1
function stringNumber(str){
// This will use a regular expression to match the last series of numbers that appear in
// your string (/\d+$/) and it will map that value to a function that will replace it with
// the result of the actual number it contains (Number(n)), which will do something like
// mapping "999" to 999 and then incrementing it by 1 (Number(n) + 1)
return str.replace(/\d+$/, function(n) { return Number(n) + 1; });
}
function stringNumber(str){
function Validation() {
var username = $("#username").val();
var password = $("#password").val();
var password2 = $("#password2").val();
var user_textLength = username.trim().length;
var pw_textLength = password.trim().length;
var x = email;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (user_textLength <= 7) {
' Build a Connection to use
Using connection = New OleDbConnection("{your-connection-string}")
' Open your connection
connection.Open()
' Build your query (using parameters)
Dim query = "UPDATE tb_kamar SET no_ktp = NULL WHERE no_kamar = ?"
' Build a command to execute
Using command = New OleDbCommand(query, connection)
' Add your parameters
command.Parameters.AddWithValue("@sed", cbnokam.Text)
<button class='Remove' data-id='42'>Click Me!</button>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script>
$(function(){
$('.Remove').click(function () {
debugger;
var myId = $(this).data('id');
$.ajax({
url: '@Url.Action("Remove", "ReadingNow")?Book_id=' + myId,
success: function (response) {