Skip to content

Instantly share code, notes, and snippets.

View hasyimibhar's full-sized avatar
🏠
Working from home

Hasyimi Bahrudin hasyimibhar

🏠
Working from home
View GitHub Profile
@hasyimibhar
hasyimibhar / dicttoxml
Created April 1, 2013 02:40
Convert NSDictionary to XML string
- (NSString *)convertToXml:(NSDictionary *)dictionary {
NSMutableString *xmlString = [[NSMutableString alloc] init];
for (NSString *key in [dictionary allKeys]) {
id value = [dictionary objectForKey:key];
[xmlString appendFormat:@"<%@>%@</%@>\n", key, value, key];
}
return [NSString stringWithString:xmlString];
void takeDamage(const int damage) {
assert(damage >= 0);
health -= damage;
if (health <= 0) {
// Do whatever a dead enemy should be doing
}
}
void take_damage(
const Enemy *enemy,
int damage) {
enemy->health -= damage;
if (enemy->health <= 0) {
// Do whatever a dead enemy should be doing
}
}
void take_damage(
const Enemy *enemy,
int damage) {
assert(enemy != NULL && "enemy must not be NULL!");
assert(damage > 0 && "damage must be more than 0!");
enemy->health -= damage;
if (enemy->health <= 0) {
// Do whatever a dead enemy should be doing
int thisIsAFunction(int foo) {
return 0;
}
#include <cstdio>
int main()
{
printf("Hello, world!\n");
return 0;
}
@hasyimibhar
hasyimibhar / reflection_method_get_parameters_benchmark.php
Created January 18, 2016 03:11
Benchmark of calling ReflectionMethod::getParameters
<?php
ini_set('memory_limit', '-1');
$n = 1000000;
class A {}
class B {}
class C {}
class D {}
@hasyimibhar
hasyimibhar / breakdown.out
Last active March 24, 2016 08:04
Gosafe G79 Sample Device Packet (HEX)
f8
16 04 013fb82257f676
^ ^ ^
version packetid imei
? time mask? SYS GPS COT ADC DTT
00 42 01 1e 83 c9 7b 00 3b 11 03 47 37 39 15 56 31 2e 31 31 26 56 31 2e 30 2e 32 13 00 3f 46 00 2f 74 22 06 0e db c0 00 00 00 00 00 48 00 db 08 03 60 84 a8 13 08 ce d3 04 03 33 11 78 06 03 02 00 02 41 00
00 42 01 1e 83 c9 85 00 3b 11 03 47 37 39 15 56 31 2e 31 31 26 56 31 2e 30 2e 32 13 00 3f 46 00 2f 74 22 06 0e db c0 00 00 00 00 00 48 00 db 08 03 60 84 a8 13 08 ce d3 04 03 32 11 78 06 03 02 00 02 41 00
@hasyimibhar
hasyimibhar / mykad.py
Created April 1, 2016 07:52
Simple MyKad Parsing
from collections import namedtuple
from datetime import date
import re
class InvalidMykadNumber(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
@hasyimibhar
hasyimibhar / index.js
Created November 6, 2020 06:47
formatjs/intl-datetimeformat with en-MY missing am/pm
require('@formatjs/intl-datetimeformat/polyfill-force');
require('@formatjs/intl-datetimeformat/locale-data/en');
require('@formatjs/intl-datetimeformat/locale-data/en-MY');
require('@formatjs/intl-datetimeformat/add-all-tz');
var date = new Date(Date.UTC(2020, 1, 1, 10, 10, 10, 0));
var format = new Intl.DateTimeFormat('en-MY', {
year: 'numeric',
month: 'short',
day: '2-digit',