Skip to content

Instantly share code, notes, and snippets.

View arlm's full-sized avatar

Alexandre Rocha Lima e Marcondes arlm

View GitHub Profile
@arlm
arlm / re-encode.sh
Created October 13, 2016 10:13 — forked from sanssucre/re-encode.sh
Bash script to change the encoding of source files.
#!/bin/bash
# I wrote this script to change the encoding of a large
# source code repository with inconsistent file encoding
SOURCE_DIR=$1
FILE_MASK="*.$2"
DESTINATION_ROOT=$3
if [ $# -ne 3 ]; then
@arlm
arlm / encoding-helpers.ps1
Created October 13, 2016 10:14 — forked from jpoehls/encoding-helpers.ps1
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
@arlm
arlm / BrPhoneNumberFormatter.java
Created December 22, 2016 00:23 — forked from alfredbaudisch/BrPhoneNumberFormatter.java
Android EditText mask for Brazilian telephone numbers. It deals with the default format (xx) xxxx-xxxx as well the newer longer one (xx) xxxxx-xxxx. Máscara de telefones brasileiros para EditText do Android: formata tanto o telefone padrão (xx) xxxx-xxxx, quanto o novo formato (xx) xxxxx-xxxx.
/**
* Adapted to BR phone format from the class
* UsPhoneNumberFormatter by Samik Bandyopadhyay:
* http://stackoverflow.com/a/23659268/332839
*/
public class BrPhoneNumberFormatter implements TextWatcher {
final int MAX_LENGTH = 11;
//This TextWatcher sub-class formats entered numbers as (41) 1234(5)?-6789
@arlm
arlm / BigDecimal.cs
Created February 20, 2017 16:45 — forked from nberardi/BigDecimal.cs
BigDecimal type in .NET
using System;
using System.Linq;
namespace System.Numerics
{
public struct BigDecimal : IConvertible, IFormattable, IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
public static readonly BigDecimal MinusOne = new BigDecimal(BigInteger.MinusOne, 0);
public static readonly BigDecimal Zero = new BigDecimal(BigInteger.Zero, 0);
public static readonly BigDecimal One = new BigDecimal(BigInteger.One, 0);
@arlm
arlm / unzip.ps1
Created February 21, 2017 11:14 — forked from nachivpn/unzip.ps1
Unzip a file in powershell by overwriting existing files
function Unzip($zipfile, $outdir)
{
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile)
foreach ($entry in $archive.Entries)
{
$entryTargetFilePath = [System.IO.Path]::Combine($outdir, $entry.FullName)
$entryDir = [System.IO.Path]::GetDirectoryName($entryTargetFilePath)
#Ensure the directory of the archive entry exists
@arlm
arlm / GAME_API.lua
Created March 1, 2017 21:34 — forked from rndstr/GAME_API.lua
jserver API && example game
-- * attach functions to our existing cGame class. ('cGame:_blah') Use a preceeding underscore to make sure there is no name clash.
-- * access the game instance through 'g'
-- * access global exported C++ functions:
-- j_log( string )
-- write to jserver log stream (you may not use '\n', a newline is appended automatically on each function call)
-- NOTE: for tablelog use g:log() and g:log_debug()
-- j_stackdump() -- dumps the stack
--
-- * convention:
-- send_* - needs the client_idx as first argument (NOTE not id!)
@arlm
arlm / shareWithoutFacebook
Created March 2, 2017 05:36 — forked from suau/shareWithoutFacebook
share text to android applications except facebook
public static void shareWithoutFacebook(Context context, String text) {
// get available share intents
List<Intent> targets = new ArrayList<>();
Intent template = new Intent(Intent.ACTION_SEND);
template.setType("text/plain");
List<ResolveInfo> resolveInfos = context.getPackageManager().
queryIntentActivities(template, 0);
// remove facebook which has a broken share intent
for (ResolveInfo resolveInfo : resolveInfos) {
@arlm
arlm / gist:7e5d9b6b22c445f1bdce8497b6a35dc2
Created March 2, 2017 05:37 — forked from tajchert/gist:73422616624090851fa5
Due to Facebook not handling any text in share intent (ACTION_SEND), and not trying to fix it (it is a "feature"), lets remove it from share dialog - as otherwise it results in broken user experience and most likely users will blame us not the Facebook. Bug on Facebook issue tracker https://developers.facebook.com/bugs/332619626816423
// Usage:
// your share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a subject");
// invoke custom chooser that contains all apps just without Facebook
startActivity(Tools.customChooserIntentNoFb(intent, "Share using", context));
// Method:
Expression<Func<string, bool>> f = s => s.Length < 5;
ParameterExpression p = Expression.Parameter (typeof (string), "s");
MemberExpression stringLength = Expression.Property (p, "Length");
ConstantExpression five = Expression.Constant (5);
BinaryExpression comparison = Expression.LessThan(stringLength, five);
Expression<Func<string, bool>> lambda = Expression.Lambda<Func<string, bool>> (comparison, p);
Func<string, bool> runnable = lambda.Compile();
@arlm
arlm / IIS-Functions.ps1
Created March 7, 2017 12:56 — forked from sergejusb/IIS-Functions.ps1
Basic Power-Shell cmdlets to work with IIS 7+
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# IIS functions
Import-Module WebAdministration
function Test-WebAppPool($Name) {
return Test-Path "IIS:\AppPools\$Name"
}
function Get-WebAppPool($Name) {