Tag Archives: hack

Override private methods in TypeScript

First things first: a word of caution – do this only if you absolutely have to. TypeScript has these checks for a reason, and probably in 99% of the cases you should respect and abide these restrictions. But if your scenario falls within the 1% where you must in a subclass override a private method of a superclass – this post shows a way to do this.

Let’s say we have a class that defines a generic starship, and what happens to it when it’s hit by a weapon:

type Hit = 'phaser' | 'antimatter spread' | 'photon torpedo'
 
class Starship {
    private totalDamage: number;
 
    constructor(private shipName: string) {
        this.totalDamage = 0;
    }
 
    private addDamage(damage: number) {
        this.totalDamage += damage;
    }
 
    public isHitBy(hit: Hit) {
        console.log(`${this.shipName} is hit by ${hit}!`)
 
        switch(hit) {
            case 'phaser':
                this.addDamage(100);
                break;
            case 'antimatter spread':
                this.addDamage(300);
                break;
            case 'photon torpedo':
                this.addDamage(500);
                break
        }
    }
}

You can create your own class of starship based on this generic class, then build a ship of the new class, and simulate it being hit by a weapon: Continue reading →

Flicker-Free IFRAME refresh

One of our projects consists of single parent page and “widgets” that display secondary (classic ASPX webform) pages. A recent feature request was to auto-refresh widget information at given intervals. On the surface it was pretty straghtforward:

<iframe id="xIfrWidget0"></iframe>
var ifr = document.getElementById('xIfrWidget');

setInterval(function () {
   ifr.src = 'widget.aspx';
}, 2000)

The problem with this approach – there’s an ugly flicker of white between page refresh and the goal was to keep displaying current IFRAME content up until refreshed content is ready. Yes, there’re various AJAX-ified methods (including ASP.NET UpdatePanel) – but they add unnecessary overhead and may cause other issues.

The solution was suggested by this Stack Overflow post. The idea is to have secondary, hidden IFRAME into which perform actual load. Once load complete – switch IFRAMES – currently visible with old content becomes hidden, and hidden one with new content becomes visible. It goes something like this: Continue reading →

Root your Android device without flashing custom recovery

HTC Rooted
It is fairly straightforward to root an Android phone using SDK platform tools (adb, fastboot), for example this is a very nice guide how to root HTC One M8. Basically you download SuperSU superuser manager to your device, download custom recovery image onto your computer and flash it to your device via command

fastboot flash recovery your_custom_recovery.img

then reboot into newly flashed recovery and flash the SuperSU. Boom, you’re done.

The problem with this approach, once you phone receives OTA (over the air) update (e.g. new version of Android) it needs original stock recovery to install it. If you have custom recovery (e.g. TWRP) – OTA update will fail. The solution is, when you root your phone, not to flash custom recovery, but just to reboot into it without flashing. Instead of above command, use

fastboot boot your_custom_recovery.img

This command will reboot your phone into custom recovery without flashing it. Then you can flash SuperSU and after reboot your phone will be rooted and original stock recovery remains.

You can even save the original stock recovery (after you rooted the phone) in case you do need to flash custom one. This way you can have a backup of stock recovery in case you need to flash it back to install OTA update. Below steps are for HTC One M8, but other devices will have similar approach:

Assuming that your phone is connected to PC, you have correct drivers installed and USB debugging mode enable.

run  "adb shell" command on your PC
"su" (watch your phone and grant permission if needed)
"dd if=/dev/block/mmcblk0p43 of=/sdcard/stock_recovery.img"

This will copy stock recovery of your HTC One M8 into file “stock_recovery.img” on the SD Card.

Credits go to this XDA thread

Display “Lose It!” data on Pebble watchface

Original Lose It!Lose It! on Pebble

Lose It! is an excellent service that helps people lose weight by monitoring calories intake. It integrates with variety of devices so I was curious if I can display my user data on Pebble smartwatch (to make sure I can have another piece of cake or not).

Unfortunately LoseIt doesn’t have a public API. There had to be another way. Continue reading →

FusionCharts.RenderChart and ASP.NET UpdatePanel

Fusion Charts

FusionCharts is a very cool cross-platform charting library – it offers huge variety of chart types and mind-blowing special effects. It also offers wide variety of chart rendering options both client- and server-side.

One such option is to render chart in an ASP.NET application. FusionCharts.dll that you get with the package offers handy FusionCharts.RenderChart method that generates all the client-side code you need to display a beautiful chart. Usually it is used something like this:

xLabel1.text = FusionCharts.RenderChart("FusionCharts/Pie2D.swf", "", sChartXmlData, sChartID, iChartWidth, iChartHeight, False, True)

where xLabel1 is a Label or Literal control in your ASPX page and FusionCharts.RenderChart is a function that accepts number of parameters, like chart type, chart XML data, dimensions etc.

It works very well until you want to render the chart inside of Microsoft Ajax UpdatePanel – then nothing works. This happens because FusionCharts.RenderChart function emits some HTML along with JavaScript that do not work during partial postback. FusionCharts suggest hooking up to UpdatePanel life-cycle events, but it’s seems like an overkill, and often doesn’t work (especially if you have a complex project, which this hookup can interfere with). But there’s an alternative solution.
Continue reading →

UltraWebGrid strange behavior in IE8 when IE=EmulateIE7

If you’re using Infragistics UltraWebGrid in Internet Explorer 8 you may experience strange visual (and other) issues if you have page compatibility set to emulate IE7, e.g.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Issues can range from column moving not working to weird distortion in grouped mode. According to Infragistics this combination is not supported as “unstable”, but you can still make it work.

Infragistics keeps internal flags of what browser is currently in use: ig_shared.IsIE7, ig_shared.IsIE8, etc. The trick is to detect IE8 and make it fall back to IE7:

if (ig_shared.IsIE8) {
    ig_shared.IsIE8 = false;
    ig_shared.IsIE7Compat = true;
}

Place this code on top of your page JavaScript code and when it sees IE8 it will tell grid to use IE7 rendering. This is most definitely a hack, but it works.

Excellent Freeware RAR password recovery utility

If you ever need to recover lost password to your RAR file (or, let’s be honest, unrar a file you got from the Internet), look no further than cRARk – beautifully done RAR password recoverer. It’s the only utility capable of using NVIDIA CUDA, which utilizes GPU for password permutations, and even without that it’s extremally fast. And it’s free!

You can download it at http://www.crark.net