Skip to content

Instantly share code, notes, and snippets.

View icholy's full-sized avatar
💥
breaking things

Ilia Choly icholy

💥
breaking things
View GitHub Profile
@icholy
icholy / inline.md
Created December 10, 2012 18:15
inline functions

Even though overuse of getter and setter functions can be frowned upon, they can help a lot if you're looking to provide a intuitive api. However the overhead the additional function call introduces in undesirable. Thankfully, there's the inline keyword. It tells the compiler to replace each invokation of the function with the body of the function.

struct Foo {
  int m_number = 123;

There are still a few caveats to using cling as a repl. The first one is lack of support for recursive compilation. This is a limitation of the JIT compiler. It is a problem if you're trying to pass a lambda as a parameter.

void f (std::function<void(void)> cb) {
  cb();
}

f([](){});

For the past couple days I have been learning how to use autotools and friends. Compared to writing makefiles manually, the autofriends are awesome.

AutoTools

But I can't say I like it either. The problem isn't that it's limited or broken. The issue is that there is 100 different ways to do the same thing. Also, even though there's autoscan to help a bit, you still end up writing lots of boilerplate code just to get up and running.

@icholy
icholy / gist:4484920
Created January 8, 2013 15:58
time parser
#include <string>
#include <sstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <vector>
#include <memory>
#include <chrono>
#include <thread>
@icholy
icholy / compare.js
Last active December 11, 2015 12:09
deep compare
var compare = (function() {
var cmp, cmpObject, cmpArray;
cmpObject = function (v1, v2) {
var v1keys = Object.keys(v1),
v2keys = Object.keys(v2);
if (v2keys.length !== v1keys.length) return false;
return v1keys.every(function(key) { return cmp(v1[key], v2[key]); });
};
cmpArray = function (v1, v2) {
if (v1.length !== v2.length) return false;
-- BEFORE INSERT TRIGGER
CREATE OR REPLACE FUNCTION foo.before_insert()
RETURNS TRIGGER AS
$$
oid = TD["relid"]
if oid not in GD:
GD[oid] = []
function hashcheck1 (inputhash){
Object.keys(hashtable).filter(function (hashtype) {
return hashtype.length === inputhash.length
&& !iz.int(inputhash)
&& inputhash.match(/[0-9]/)
&& iz.alphaNumeric(inputhash);
}).map(function (key) {
return hashtable[key];
}).forEach(function (hashname) {
console.log(hashname);
@icholy
icholy / json-pointer-slice.md
Last active December 14, 2015 07:28
Json Pointer Slices

The json-pointer draft is missing a very important piece: slices.

Example Data:

var obj = {
  foo: [
    { bar: 1 },
    { bar: 2 },
 { bar: 3 }
[[42.773338317871094, -80.034881591796875], [43.773338317871094, -81.034881591796875], [44.773338317871094, -82.034881591796875]]
@icholy
icholy / routing.md
Last active December 15, 2015 00:29

Angular's built in router is lacking when you start trying to do nested layouts. When people bring this up as an issue, the common response is that you can use ngInclude to do whatever you want. The problem with that is that you're basically throwing away the $route functionality.

That's what I thought until I read Ben Nadel's Post. When you're defining your routes, you can use arbitrary properties and they will be available on $route.current

var App = angular.module('App', []);