Skip to content

Instantly share code, notes, and snippets.

View ztane's full-sized avatar

Antti Haapala ztane

View GitHub Profile
<?php
#Equivalent to this PHP codes:
$gmt_timezone = new DateTimeZone('GMT');
$obj_date = new DateTime(null,$gmt_timezone);
echo $obj_date->format('d/m/Y h:i:s');
#OR
date_default_timezone_set("GMT");
echo date('d/m/Y h:i:s', time());
?>
@ztane
ztane / millionaire5050.py
Created February 27, 2016 16:58
50/50 simulation of WWTBAM
% python3 millionaire.py
Out of 1000000 cases
Initial was eliminated in 499869 cases (49.9869 %)
Initial was not eliminated in 500131 cases (50.0131 %)
There answer was different from initial in 249818 cases
Thus changing is winning 49.95051296560301 % if initial was not eliminated
@ztane
ztane / typechecking.py
Last active September 19, 2016 10:46
Typing testing
import warnings
import inspect
NONE = object()
class TypingWarning(Warning):
pass
@ztane
ztane / flextest.l
Last active October 24, 2016 18:27
Simple flex
%{
#include <stdio.h>
int line_num = 1;
%}
%%
"(" { printf("a opening parenthesis\n"); }
")" { printf("a closing parenthesis\n"); }
[0-9]+ { printf("a number: %s\n", yytext); }
@ztane
ztane / keybase.md
Created November 13, 2016 12:59
keybase.md

Keybase proof

I hereby claim:

  • I am ztane on github.
  • I am anttihaapala (https://keybase.io/anttihaapala) on keybase.
  • I have a public key whose fingerprint is B811 2F0F ACC5 6F06 B79C 4E4D 69C6 71AF 0959 C672

To claim this, I am signing this object:

@ztane
ztane / aco.py
Created December 2, 2016 10:58
Advent of Code helpers for Python 3
# advent of code helpers for Python 3
def input_file(filename='input'):
"""
Read the input from current working directory,
return as a string stripped
"""
with open(input) as f:
return f.read().strip()
@ztane
ztane / jsonSerialize.js
Created September 7, 2017 22:17
jsonSerialize
(function ($) {
function doSerializeArrayItems($current, target) {
$current.children().each(function (i, e) {
var $e = $(e),
tmp;
if (e.hasAttribute('data-form-item')) {
var o = {};
target.push(o);
doSerialize($e, o);
}
@ztane
ztane / test.py
Last active October 9, 2018 11:52
dictionary merging test
from collections import defaultdict
import time
i = 100
for _ in range(3):
list_of_dictionaries = [{1: 1} for i in range(i)]
list_of_dictionaries.append(dict.fromkeys(range(i)))
n = sum(map(len, list_of_dictionaries))
int foo(int a, int b) {
if ((a-b)==0) {
return 1;
}
return 0;
}
int bar(int a, int b) {
if (a==b) {
return 1;
@ztane
ztane / clang.c
Created March 20, 2019 16:14
clang ub stuff
#include <stdio.h>
#define BUGGY
void funcA(int s, int g)
{
int i, j = 0, k;
int grp[4] = {-1, -1};
for (i = 0, k = 0; i < 1; ++i) {