This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
#If VBA7 And Win64 Then | |
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _ | |
Alias "PlaySoundA" (ByVal lpszName As String, _ | |
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr | |
#Else | |
Private Declare Function PlaySound Lib "winmm.dll" _ | |
Alias "PlaySoundA" (ByVal lpszName As String, _ | |
ByVal hModule As Long, ByVal dwFlags As Long) As Long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on play_evil_laugh(filePath) | |
do shell script "afplay '" & filePath & "'" | |
end play_evil_laugh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Private Sub Worksheet_Calculate() | |
On Error GoTo ExitSub | |
Dim rng As Range | |
Set rng = Windows(1).VisibleRange.Cells.SpecialCells(xlCellTypeFormulas, xlErrors) | |
Dim cell As Range | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range) | |
On Error GoTo ExitSub | |
Application.EnableEvents = False | |
Dim rng As Range | |
Set rng = Windows(1).VisibleRange.Cells.SpecialCells(xlCellTypeConstants, xlNumbers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function LEFT(text As String, Optional num_of_chars As Long = 1) As String | |
LEFT = MID(text, 1, num_of_chars) | |
End Function | |
Public Function RIGHT(text As String, Optional num_of_chars As Long = 1) As String | |
RIGHT = MID(text, Len(text) - num_of_chars, num_of_chars) | |
End Function | |
Public Function MID(text As String, start_num As Long, num_of_chars As Long) As String | |
' Actual Implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Public Function GetSummary(text As String, num_of_words As Long) As String | |
If (num_of_words <= 0) Then | |
GetSummary = "" | |
Exit Function | |
End If | |
Dim words() As String | |
words = Split(text, " ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a = { "a", "A", "B" } | |
// b = { "b" } | |
// set = {} | |
// | |
// first, add items from `b` into a new set using the Comparer given | |
// (in this case, StringComparer.OrdinalIgnoreCase) | |
// | |
// 1. Can "b" go into the set? Yes, because it doesn't exist. | |
// set = { "b" } | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IEnumerable<TSource> ExceptIterator<TSource>( | |
IEnumerable<TSource> first, | |
IEnumerable<TSource> second, | |
IEqualityComparer<TSource> comparer) | |
{ | |
Set<TSource> set = new Set<TSource>(comparer); | |
foreach (TSource element in second) set.Add(element); | |
foreach (TSource element in first) | |
if (set.Add(element)) yield return element; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<TSource> Except<TSource>( | |
this IEnumerable<TSource> first, | |
IEnumerable<TSource> second) | |
{ | |
if (first == null) throw Error.ArgumentNull("first"); | |
if (second == null) throw Error.ArgumentNull("second"); | |
return ExceptIterator<TSource>(first, second, null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = new object(); | |
var b = new object(); | |
var aList = new List<object> { a, a, b }; | |
var bList = new List<object> { b }; | |
var aExceptB = aList.Except(bList); | |
Console.WriteLine(aExceptB.ToList().Count()); |