Skip to content

Instantly share code, notes, and snippets.

@Grynn
Grynn / locale-fix.sh
Last active August 29, 2015 14:27
Fix Ubuntu locale issues
#!/bin/bash
#paranoid (in case the langguage-pack-en is not installed, which is rare)
sudo apt-get -q install language-pack-en.*
#write to /etc/default/locale
#changes only take effect after logout
sudo update-locale --reset LANG=en_US.UTF-8 LC_MESSAGES=POSIX LC_ALL=en_US.UTF-8
#generate locale files if required
@Grynn
Grynn / VBA functions for working with files
Created April 9, 2010 22:36
VBA functions for working with files
Option Explicit
Function FileDelete(Filename As String) As String
Dim fso As New FileSystemObject
On Error Resume Next
Err.Clear
Call fso.DeleteFile(Filename)
On Error GoTo 0
If Err.Number <> 0 Then
@Grynn
Grynn / .gitconfig
Created September 16, 2015 21:59
My .gitconfig
[alias]
st = status
co = checkout
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
br = branch -v
dt = difftool --dir-diff
gshow = !f() { git difftool --dir-diff $1^..$1; }; f
llg = !f() { git lg $(git branch --column | tr -d '*' | tr -s ' '); }; f
[user]
@Grynn
Grynn / reset_perms.bat
Created July 31, 2012 14:08
Reset Permissions on Folder Hierarchy in Windows
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET TGT=%1
SET TGT=%TGT:"=%
IF "%TGT%"=="" SET TGT=*
takeown /f "%TGT%" /R /D Y > nul
icacls "%TGT%" /reset /t /q
icacls "%TGT%" /grant %USERNAME%:F /t /q
attrib -r -h -s "%TGT%" /s /l /d
@Grynn
Grynn / ListDiff.cs
Created September 6, 2012 09:22 — forked from praeclarum/ListDiff.cs
Computes a diff between two different IEnumerables. It's better than anything you have ever seen. Ever.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace TheBestAppEver
{
/// <summary>
/// The type of <see cref="ListDiffAction{S,D}"/>.
@Grynn
Grynn / SafeEnumerateDirectory
Last active October 12, 2015 04:38
SafeEnumerateDirectory
struct FileNode
{
public string Name;
public bool IsDirectory;
public Exception Error;
public bool HasError { get { return this.Error!=null; } }
}
void Main()
@Grynn
Grynn / lsrecent
Last active November 18, 2015 18:23
List 10 most recently modified files (in a directory tree)
#!/bin/bash
# May not work if filename have spaces
# Inspired by this answer on StackOverflow
# http://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s
find . -type f -printf '%T@ %P\n' | sort -nr | cut -d ' ' -f2- | head
## Windows Version ##
# gfind . -type f -name "clean*.php" -printf "%T@ \"%P\"\n" | gsort -nr | cut -d ' ' -f2-
# Assumes gfind = Gnu find and gsort Gnu sort
/*
jquery.draghover.js
Emulates draghover event by tracking
dragenter / dragleave events of element + children.
https://gist.github.com/gists/3794126
http://stackoverflow.com/a/10310815/4196
@Grynn
Grynn / .gitignore
Last active December 19, 2015 16:48 — forked from LeeFlannery/.gitignore
# Personal files
*.user
#dev.config
#connections.config
# Build results
[Dd]ebug/
[Rr]elease/
[Bb]in/
[Oo]bj/
@Grynn
Grynn / free_port.php
Last active January 30, 2016 03:24
Show next available port
<?php
/* Create a socket, bind to port 0, kernel assigns a free port. Read port number, close socket
* This works *mostly* because the kernel tries hard to avoid re-using ports. So the port returned
* by this function should remain available for a bit after this process has terminated.
*/
echo "Available local port: " . getFreeLocalTcpPort();
function getFreeLocalTcpPort() {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);