Skip to content

Instantly share code, notes, and snippets.

View hagronnestad's full-sized avatar
👨‍💻
KTogIWJjcmUgNzMzMSBseiBhdiByaGZmdiBhbiByZ25yZVA=

Hein Andre Grønnestad hagronnestad

👨‍💻
KTogIWJjcmUgNzMzMSBseiBhdiByaGZmdiBhbiByZ25yZVA=
View GitHub Profile
var longString = "This is a long string.";
var iterations = 1000000;
var timer = new Stopwatch();
"\nTake()".Dump();
timer.Start();
for (int i = 0; i < iterations; i++) {
var newString = new string(longString.Take(10).ToArray());
if (i == 0) newString.Dump();
}
<script>console.log("xss");</script>
@hagronnestad
hagronnestad / WordPress: Wrap images in DIV.php
Last active September 27, 2021 19:09
WordPress: Wrap images in DIV.
// =======================
// = WRAP IMAGES IN DIVS =
// =======================
function wrapImagesInDiv($content) {
$pattern = '/(<img[^>]*class=\"([^>]*?)\"[^>]*>)/i';
$replacement = '<div class="image-container $2">$1</div>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
@hagronnestad
hagronnestad / URLtoData
Last active December 15, 2015 05:49
Converts all img src URLs to base64 data urls. Very crude, doesn't check the MIME type, probably som regex issues to.
function URLtoData($html) {
$imgTags = null;
preg_match_all("/<img.*?>/", $html, $imgTags);
foreach ($imgTags[0] as $imgTag) {
$src = null;
preg_match_all("/src=\"([^\"]*)/", $imgTag, $src);
$src = $src[1][0];
$data = base64_encode(file_get_contents($src));
@hagronnestad
hagronnestad / Twilight-HAG.tmTheme
Created March 20, 2013 13:20
My ST2 Theme. Based on Twilight.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>Michael Sheets</string>
<key>name</key>
<string>Twilight</string>
<key>settings</key>
<array>
{
"color_scheme": "Packages/Color Scheme - Default/Twilight-HAG.tmTheme",
"font_face": "Consolas",
"font_size": 10,
"ignored_packages":
[
"Vintage"
],
"theme": "Soda Dark.sublime-theme",
@hagronnestad
hagronnestad / WordPress: Hide some pages from admin to disable editing
Last active December 4, 2019 12:38
WordPress: Hide some pages from admin to disable editing
add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
global $pagenow, $post_type;
if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
$query->query_vars['post__not_in'] = array(2, 71);
}
}