Skip to content

Instantly share code, notes, and snippets.

var pr = new Promise(function(resolve, reject) {
var fn = function(event) {
console.log("Event type: %s, Event target.readyState: %d, Event target.status: %d, Event target.statusText: %s",
event.type,
event.target.readyState,
event.target.status,
event.target.statusText
);
if (event.type == "error" || event.type == "abort" || (event.type == "load" && (event.target.readyState != XMLHttpRequest.DONE || event.target.status != 200))) {
var test = (function() {
_this = 'test';
return function() {
console.log(_this);
};
})();
(function() {
_this = 'another';
@porfirion
porfirion / test.go
Last active August 29, 2015 14:27
golang fails to parse json for object, created by reflection
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Message struct {
Data string
@porfirion
porfirion / gist:320095c3306f6bf5b64a
Created December 21, 2015 20:24
Usefull SublimeText plugins
CaseConversion
Bracket Highlighter
Sidebar Enchancements
HTML/CSS/JS Prettify
Emmet
package main
import ("fmt"; "time")
func main() {
var distance float64 = 10.0
var speed float64 = 3.0
val := distance / speed * 1000000000
duration := time.Duration(val)
@porfirion
porfirion / watch and sync
Created October 18, 2017 08:45
Watch folder and rsync it on change
#!/bin/bash
cd /path/to/project
while [ 1 ]; do
inotifywait --exclude '.git' -r -e modify,moved_to,moved_from,move,create,delete ./
rsync -ah --exclude='.git/' ./ server:/dev/shm/projectname/ --delete
done
exit 0
@porfirion
porfirion / headers.fs
Last active November 9, 2018 12:52
Setting http headers under f# (fsharp)
resp.Content.Headers.ContentType <- MediaTypeHeaderValue.Parse "application/json"
// OR
resp.Content.Headers.Remove("Content-Type") |> ignore
resp.Content.Headers.Add("Content-Type", "application/json")
// Because Content-Type header has HttpHeaderKind.Content and there is an exception while setting
// it on response itself:
// resp.Headers.Add("Content-Type", "application/json")
let print (slots:(int * string * string * string * int * string) list) (token: string) =
// (article_id * slot_id * hash * realHash * options_count * slot_title)
[
"By title and hash:\n"
slots
|> List.groupBy (fun slot ->
let articleId, slotId, slotHash, slotRealHash, optionsCount, title = slot
title
)
|> List.map (fun (title, entries) ->
┌─────┬──────┐
│ │ │
├─────┼──────┤
│ │ │
└─────┴──────┘
╔═════╦══════╗
║ ║ ║
╠═════╬══════╣
║ ║ ║
@porfirion
porfirion / index.html
Created March 5, 2019 17:30
Empty favicon (valid PNG)
<link rel="icon" href="data:;base64,iVBORw0KGgo=">