Skip to content

Instantly share code, notes, and snippets.

View JohnLBevan's full-sized avatar
🏠
Working from home

John Bevan JohnLBevan

🏠
Working from home
View GitHub Profile
@jagregory
jagregory / gist:710671
Created November 22, 2010 21:01
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork git@github...my-fork.git
@victoroliv2
victoroliv2 / cross-site-xmlhttprequest.py
Created October 7, 2011 19:09
web.py server which allow cross-site xmlhttprequest
import web
urls = (
'/(.*)', 'Service'
)
app = web.application(urls, globals())
class Service:
def GET(self, name):
web.header('Access-Control-Allow-Origin', '*')
@zommarin
zommarin / Get-FileEncoding.ps1
Created December 15, 2011 12:43
Get-FileEncoding
function Get-FileEncoding($Path) {
$bytes = [byte[]](Get-Content $Path -Encoding byte -ReadCount 4 -TotalCount 4)
if(!$bytes) { return 'utf8' }
switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
'^efbbbf' { return 'utf8' }
'^2b2f76' { return 'utf7' }
'^fffe' { return 'unicode' }
'^feff' { return 'bigendianunicode' }
@jpoehls
jpoehls / encoding-helpers.ps1
Created April 17, 2012 14:54
Convert-FileEncoding and Get-FileEncoding
<#
.SYNOPSIS
Converts files to the given encoding.
Matches the include pattern recursively under the given path.
.EXAMPLE
Convert-FileEncoding -Include *.js -Path scripts -Encoding UTF8
#>
function Convert-FileEncoding([string]$Include, [string]$Path, [string]$Encoding='UTF8') {
$count = 0
@jpoehls
jpoehls / xpath-example.ps1
Created May 18, 2012 18:44
Use XPath to update XML using PowerShell
function Edit-XmlNodes {
param (
[xml] $doc = $(throw "doc is a required parameter"),
[string] $xpath = $(throw "xpath is a required parameter"),
[string] $value = $(throw "value is a required parameter"),
[bool] $condition = $true
)
if ($condition -eq $true) {
$nodes = $doc.SelectNodes($xpath)
@joefitzgerald
joefitzgerald / win-updates.ps1
Created December 31, 2013 23:18
Install All Windows Updates, Rebooting As Many Times As Required
param($global:RestartRequired=0,
$global:MoreUpdates=0,
$global:MaxCycles=10)
function Check-ContinueRestartOrEnd() {
$RegistryKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$RegistryEntry = "InstallWindowsUpdates"
switch ($global:RestartRequired) {
0 {
$prop = (Get-ItemProperty $RegistryKey).$RegistryEntry
@sayedihashimi
sayedihashimi / show-console-colors.ps1
Last active May 29, 2021 17:07
PowerShell loop through console colors to display different results for foreground color & background color
[enum]::getvalues([type]'ConsoleColor') | ForEach-Object{
$curForeground = $_
[enum]::getvalues([type]'ConsoleColor') | ForEach-Object{
$curBackground = $_
$msgStart= "Foreground={0}, Background={1}" -f $curForeground,$curBackground
$msgStart += (New-Object string -ArgumentList @(' ',(50-$msgStart.Length)))
$msgStart | Write-Host -NoNewline
@jonlabelle
jonlabelle / aspdotnet-razor-syntax-reference.md
Last active November 11, 2022 15:48
ASP.NET Razor Syntax Reference

ASP.NET Razor Syntax Reference

Code Block

@{
    int x = 123;
    string y = "because.";
}

Expression (Html Encoded)

@9to5IT
9to5IT / Script_Template.ps1
Last active April 9, 2024 14:01
PowerShell: Script Template
#requires -version 2
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
@ChristianWeyer
ChristianWeyer / MimeTypeLookup.cs
Last active July 13, 2023 09:17
.NET MIME type lookup - 1200 well known MIME types in a C# helper class - thx to https://github.com/PawelGerr !
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
/*
MIT License
Copyright (c) 2014 Christian Weyer