Skip to content

Instantly share code, notes, and snippets.

@pepinho24
pepinho24 / load-js-via-bookmark-click.js
Created August 22, 2019 14:01
This gist shows how to use the browser's bookmarks to add a script in the current page
javascript: void ((function () {
andiScript = document.createElement('script');
andiScript.setAttribute('src', 'https://code.jquery.com/jquery-3.4.1.min.js');
document.body.appendChild(andiScript)
})());
// Description: The following script is configured to load jQuery on the page.
// Simply by changing the value of the "src" attribute, you can load your own scipts
// Setup:
@pepinho24
pepinho24 / replaceAll.js
Created February 21, 2019 09:32
ReplaceAll function that replaces all occurrences using Regular Expressions
String.prototype.replaceAll = function replaceAll(find, replace) {
return this.replace(new RegExp(find, 'g'), replace);
}
// Example: "a sdsds a sdsd".replaceAll("a", "2")
// result: "2 sdsds 2 sdsd"
// Another option is to use it just as a function:
function replaceAll(str, find, replace) {
@pepinho24
pepinho24 / visible-console.html
Last active May 1, 2020 15:15
A custom log method that adds a message to a custom div, so that it is visible with no DevTools
<!-- Example
function myFunc(){
log("some message");
// some logic
log("some other message");
} -->
<style>
#console {
@pepinho24
pepinho24 / connectionstrings-cheatsheet.txt
Created January 21, 2019 09:44
Sample ConnectionStrings in web.config and how to access them with C#
// How to get Connection string with C#
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;
// Declare in web.config a ConnectionString to VisualStudio's LocalDB
<configuration>
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
// Declare in web.config a ConnectionString to DB existing in SQL Server
@pepinho24
pepinho24 / Check-currently-active-element.js
Created December 20, 2018 15:48
Check the currently active DOM element, similar to adding document.activeElement in the Google Chrome's live expression
// Check the currently active DOM element, similar to adding document.activeElement in the Google Chrome's live expression
// Chrome DevTools live expression docs: https://developers.google.com/web/updates/2018/08/devtools#watch
var currentActiveElement = document.activeElement;
console.log(currentActiveElement);
var interval = setInterval(function(){
if(document.activeElement != currentActiveElement){
currentActiveElement = document.activeElement;
console.log(currentActiveElement);
}
@pepinho24
pepinho24 / JavaScript-StringFormat.js
Created December 12, 2018 12:55
C# string.Format() alternative for JavaScript
// https://stackoverflow.com/a/4256130/10759760
String.prototype.format = function () {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{' + i + '\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
// Sample usage:
@pepinho24
pepinho24 / remove-new-line-VS.txt
Created October 29, 2018 13:18
Remove empty new lines in Visual Studio
1. Open a file in Visual Studio
2. Press ctrl+H(shortcut for Find and replace)
3. Enable regex
4. Use the following expression ^\s*$\n and replace it with an empty string
@pepinho24
pepinho24 / Programmatic-Hierarchical-DataTable-Creation.cs
Created September 27, 2018 07:58
Create a Hierarchical DataTable with dummy data by only passing number of nodes per level
// Example how to use in RadTreeView and RadOrgChart at the end of file
private DataTable CreateHierarchicalDataTable(int[] nodesPerLevel)
{
var dataTable = new DataTable();
dataTable.Columns.Add("ID");
dataTable.Columns.Add("ParentID");
dataTable.Columns.Add("Text");
dataTable.Columns.Add("Collapsed");
@pepinho24
pepinho24 / Programmatic-DataTable-Creation.cs
Created September 26, 2018 13:59
Simplified Orders Table from Northwind database created in C# as a DataTable
public DataTable GetDataTableSource()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("OrderID", typeof(int)));
dataTable.Columns.Add(new DataColumn("OrderDate", typeof(DateTime)));
dataTable.Columns.Add(new DataColumn("Freight", typeof(decimal)));
dataTable.Columns.Add(new DataColumn("ShipName", typeof(string)));
dataTable.Columns.Add(new DataColumn("ShipCountry", typeof(string)));
@pepinho24
pepinho24 / Manipulate-JavaScript-Dates.js
Last active September 26, 2018 13:46
Manipulate-JavaScript-Dates
// created based on https://stackoverflow.com/a/563442
Date.prototype.addDays = function (days) {
days = days || 1;
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
Date.prototype.addMonths = function (months) {
months = months || 1;
var date = new Date(this.valueOf());