Skip to content

Instantly share code, notes, and snippets.

View zmilan's full-sized avatar

Milan Zivkovic zmilan

View GitHub Profile
@zmilan
zmilan / LICENSE.txt
Created August 7, 2011 16:07 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@zmilan
zmilan / Draggable.js
Created September 13, 2013 15:13 — forked from Rob-ot/Draggable.js
return View.extend({
initialize: function () {
this.el.attr("draggable", "true")
this.el.bind("dragstart", _.bind(this._dragStartEvent, this))
},
_dragStartEvent: function (e) {
var data
if (e.originalEvent) e = e.originalEvent
e.dataTransfer.effectAllowed = "copy" // default to copy

Converting libraries to Ember CLI addons

In this guide we will cover two main cases:

  • Ember specific library
  • vendor library

Ember library

The Ember library will assume that Ember has already ben loaded (higher in the loading order) and thus will assume it has access to the Ember API.

@zmilan
zmilan / js-micro.js
Created May 31, 2016 06:20 — forked from yuval-a/js-micro.js
Javascript micro-optimizations
// Array literal (= []) is faster than Array constructor (new Array())
// http://jsperf.com/new-array-vs-literal/15
var array = [];
// Object literal (={}) is faster than Object constructor (new Object())
// http://jsperf.com/new-array-vs-literal/26
var obj = {};
// property === undefined is faster than hasOwnProperty(property)
// http://jsperf.com/hasownproperty-vs-in-vs-undefined/17
@zmilan
zmilan / Db.php
Created June 11, 2016 04:58 — forked from cherifGsoul/Db.php
Proof of concept and example how to implement facades for yii2 components
<?php
namespace app\components\facades;
/**
* Example how to use the facade class
* uses yii\web\Connection
*/
class Db extends Facade
{
@zmilan
zmilan / design.md
Created January 7, 2019 17:37 — forked from arpit/design.md
@zmilan
zmilan / home.tmpl
Created April 18, 2019 19:00 — forked from campoy/home.tmpl
Electron-like html+golang app
<html>
<head>
<title>Hello, from Go</title>
</head>
<body>
<h1>Hello</h1>
<p>
This is Go code running, {{.}}
</p>
</body>
@zmilan
zmilan / nearest.php
Last active October 10, 2019 17:32
find the nearest key, value, and delta from provided array of data.
<?php
/**
* Example of usage and results
* $a = [ 7, -10, 13, 8, 4, -7.2, -12, -3.7, 3.5, -9.6, 6.5, -1.7, -6.2, 7 ];
* print_r(nearest(-3.1, $a)); // idx = 7, delta = 0.6, val = -3.7
* print_r(nearest(7, $a)); // idx = 0, delta = 0, val = 7
* print_r(nearest(0, $a)); // idx = 11, delta = 1.7, val = -1.7
*/
function nearest($needle, $haystack) {
// do some basic check of inputs
@zmilan
zmilan / postgres-cheatsheet.md
Created April 1, 2020 14:11 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)