Skip to content

Instantly share code, notes, and snippets.

@LGM-AdrianHum
LGM-AdrianHum / AnimatedText.xaml
Created May 27, 2022 01:34
Simple Text Animation In WPF
<StackPanel Orientation="Horizontal" Margin="20">
<Button Content="Start" Height="20" Command="{Binding StartCommand}" VerticalAlignment="Top" Margin="5" />
<Button Content="Stop" Height="20" Command="{Binding StopCommand}" VerticalAlignment="Top" Margin="5" />
<TextBlock Text="{Binding Status}" Margin="5">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Running">
<DataTrigger.EnterActions>
<BeginStoryboard Name="animationRefresh">
#!/bin/bash
###
# usage: script.sh "magnet_link"
###
# magnet link should be enclosed in quotes.
# Example:
# bash /path/to/script.sh "magnet:?xt=urn:btih:8a42938cb7512c1aa722fab7d2e432422d432d9a"
@LGM-AdrianHum
LGM-AdrianHum / CreateLargeFile.cs
Last active May 21, 2022 03:12
MD5 For Files With Progress
//Is Also An Example Of Seeking Beyone Extent Of File.
var f = Path.Combine(Application.StartupPath, "temp.log");
File.Delete(f);
using (var fs = new FileStream(f, FileMode.Create))
{
fs.Seek(1L * 1024 * 1024 * 1024, SeekOrigin.Begin);
fs.WriteByte(0);
fs.Close();
}
@LGM-AdrianHum
LGM-AdrianHum / ReadEndTokens.cs
Created September 24, 2021 08:05
ReadEndTokens - Reads the last n tokens from very large files. Used for trimming the last records ...
public static string ReadEndTokens(string path, Int64 numberOfTokens, Encoding encoding, string tokenSeparator)
{
int sizeOfChar = encoding.GetByteCount("\n");
byte[] buffer = encoding.GetBytes(tokenSeparator);
using (FileStream fs = new FileStream(path, FileMode.Open))
{
@LGM-AdrianHum
LGM-AdrianHum / transfer file from S3.cs
Created August 30, 2021 11:31
Quick and easy transfer from S3...
TransferUtility fileTransferUtility =
new TransferUtility(
new AmazonS3Client(
"ACCESS-KEY-ID",
"SECRET-ACCESS-KEY",
Amazon.RegionEndpoint.APSouthEast1));
fileTransferUtility.Download(filePath,
"my-bucket-name and folder",
fileName);
@LGM-AdrianHum
LGM-AdrianHum / printContentsOfElement.js
Created August 13, 2021 05:38
Print the contents of a Div...
function printDiv()
{
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open('','Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
newWin.document.close();
setTimeout(function(){newWin.close();},1000);
}
@LGM-AdrianHum
LGM-AdrianHum / Clipboard.Jquery.js
Created July 15, 2021 15:27
Copy string to clipboard.
//Usage : copyStringToClipboard("abc123");
function copyStringToClipboard (str) {
// Create new element
var el = document.createElement('textarea');
// Set value (string to be copied)
el.value = str;
// Set non-editable to avoid focus and move outside of view
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
@LGM-AdrianHum
LGM-AdrianHum / FileDownloadController.cs
Created July 15, 2021 15:06
Dynamically create a hyperlink.
[HttpGet("files/{id:int}")]
public async Task<ActionResult> DownloadFile(int id)
{
var filePath = $"{id}.txt"; // Here, you should validate the request and the existance of the file.
var bytes = await System.IO.File.ReadAllBytesAsync(filePath);
return File(bytes, "text/plain", Path.GetFileName(filePath));
}
@LGM-AdrianHum
LGM-AdrianHum / dropdown.css
Last active July 15, 2021 14:25
Place A Dropdown At Caret In Editor
#target {
height: 100px;
border: 1px solid black;
margin-top: 50px;
}
#dummy {
display: inline-block;
}
@LGM-AdrianHum
LGM-AdrianHum / shadowbox.css
Created July 2, 2021 11:20
Deep Bevel Shadow Button
.shadowbox {
padding:10px 60px;
-webkit-border-radius: 25px 6px 6px 25px;
-moz-border-radius: 25px 6px 6px 25px;
border-radius: 25px 6px 6px 25px;
background: -moz-linear-gradient(top, #f6e6b4 0%, #ed9017 100%); /* firefox */
border: solid #ccc 3px;
box-shadow: 0 1px 2px #fff, 0 -1px 1px #666, inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.8);
-moz-box-shadow: 0 1px 2px #fff, 0 -1px 1px #666, inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.8);
-webkit-box-shadow: 0 1px 2px #fff, 0 -1px 1px #666, inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.8);