Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View TangChr's full-sized avatar

Christian Tang TangChr

View GitHub Profile
@TangChr
TangChr / ArrayExtensions.cs
Created November 26, 2015 09:27
C#: Array Extension Methods
using System;
using System.Linq;
namespace TangChr
{
static class ArrayExtensions
{
public static TSource[] Remove<TSource>(this TSource[] source, TSource item)
{
var result = new TSource[source.Length - source.Count(s => s.Equals(item))];
@TangChr
TangChr / ExtendForEach.cs
Created November 21, 2015 12:48
C#: Add condition to Extension Method .ForEach
using System;
using System.Collections.Generic;
using System.Linq;
namespace TangChr
{
public static class ExtendForEach
{
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action, Func<T, bool> condition)
{
@TangChr
TangChr / underline.htm
Last active November 21, 2015 12:59
CSS: Link with different color for underline
<!DOCTYPE html>
<html>
<head>
<title>Link Color</title>
</head>
<style>
body {
background: #2c3e50;
font-family: Arial, Verdana, sans-serif;
}
@TangChr
TangChr / WildcardMatching.cs
Last active November 21, 2015 12:57
C#: Match string with wildcard
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace TangChr.Tools
{
public static class StringMatch
{
public static bool IsWildcardMatch(string search, string source)
{ // Wildcard: *
return Operators.LikeString(source, search, CompareMethod.Text);
@TangChr
TangChr / file_info.php
Last active November 21, 2015 12:58
PHP: Read comment-based file-info
<?php
function get_file_info( $file ) {
$fp = fopen( $file, 'r' );
$data = fread( $fp, 8192 ); // get first 8kb
fclose( $fp );
// Capture all the header within first comment block
if( !preg_match( '!.*?/\*(.*?)\*/!ms', $data, $matches ) )
return array();
@TangChr
TangChr / MyActivity.java
Last active September 25, 2018 18:49
Java: Simulate Home-button in Android
package dk.tcdev.android.gist;
import android.app.Activity;
import android.content.Intent;
public class MyActivity extends Activity {
public void exitApp() {
startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
}
@TangChr
TangChr / datepicker-da.js
Last active February 27, 2021 15:29
jQuery: Danish localization of the jQuery UI Datepicker
(function($){
$.ui.datepicker.regional['da'] = {
closeText: 'Luk',
prevText: '&#x3c;Forrige',
nextText: 'N&aelig;ste&#x3e;',
currentText: 'I dag',
monthNames: ['januar','februar','marts','april','maj','juni',
'juli','august','september','oktober','november','december'],
monthNamesShort: ['jan','feb','mar','apr','maj','jun',
'Jul','Aug','sep','okt','nov','dec'],
@TangChr
TangChr / parse_tweet.php
Last active November 21, 2015 13:03
PHP: Convert hastags, mentions & URLs to hyperlinks in a tweet.
<?php
require 'tweet_parser.php';
$userUrl = 'https://twitter.com/';
$tagUrl = 'https://twitter.com/hashtag/';
$my_tweet = "@TangChr: Here's a link: http://willitcompile.net, and here's a #hashtag.";
$formatted = parseTweet($my_tweet, $userUrl, $tagUrl);
$formatted2 = parseTweetPrefix($my_tweet, $userUrl, $tagUrl);
echo <<<HTML