Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
asm-jaime / index.html
Created November 22, 2017 11:38
d3+redux example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
</head>
<body>
<script>
const initialState = {
@asm-jaime
asm-jaime / get_tags.js
Created May 27, 2017 20:26
get all tags from a text (javascript), '#dfgdgf fgsdfg fgfgfgfg #gg' to ['#dfgdgf', '#gg'].
function get_tags(text) { //{{{
console.time('algs tags time');
const tags = [];
const txt = text.trim().split('');
let reg_tag = false;
let cur_tag = '';
for (let i = 0; i < txt.length; i++) {
if (reg_tag && txt[i] === '#') {
@asm-jaime
asm-jaime / go-gin-mgo.go
Last active February 20, 2021 21:13
go gin mgo, gin+mongo+test example
package main
import (
"encoding/base64"
"fmt"
rand "math/rand"
"time"
"github.com/gin-gonic/gin"
@asm-jaime
asm-jaime / obj_to_param.js
Created February 23, 2017 13:24
object to url parameter for get query
function obj_to_param(obj) {
return Object.keys(obj).map(function(key) {
return key + '=' + obj[key];
}).join('&');
}
function somef(obj) {
fetch(`${URL}/api/get/some?${obj_to_param(obj)}`)
.then((res) => res.json())
.then((json) => console.log('some: ', json.body))
@asm-jaime
asm-jaime / gin.dev.server.go
Created February 7, 2017 18:05
gin server for development which custom settings. (start inside frontend project: go run gin.dev.server.go start 9090 ./build)
package main
import (
"fmt"
"os"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
)
@asm-jaime
asm-jaime / molokai.vifm
Last active January 30, 2017 13:07
vifm config
" You can edit this file by hand.
" The " character at the beginning of a line comments out the line.
" Blank lines are ignored.
" The Default color scheme is used for any directory that does not have
" a specified scheme and for parts of user interface like menus. A
" color scheme set for a base directory will also
" be used for the sub directories.
" The standard ncurses colors are:
@asm-jaime
asm-jaime / object.merge.js
Created January 28, 2017 06:27
ways to merge objects (javascript)
'use strict';
function merge_arguments() {
let obj = {},
i = 0,
len = arguments.length,
key;
for (; i < len; i++) {
for (key in arguments[i]) {
if (arguments[i].hasOwnProperty(key)) {
@asm-jaime
asm-jaime / processing_http_error.go
Created January 4, 2017 12:56
Processing HTTP API errors
// #################### http error {{{
// ApiHttpError something
type ApiHttpError struct {
Code int `json:"errorCode"`
HttpCode int `json:"-"`
Message string `json:"errorMsg"`
Info string `json:"errorInfo"`
}
@asm-jaime
asm-jaime / processing_error.go
Created January 4, 2017 12:46
Easy Api Error
// ==================== easy error {{{
type EasyAPIError struct {
Errors []ErrorDetail `json:"errors"`
}
// ErrorDetail represents an individual item in an EasyAPIError.
type ErrorDetail struct {
Message string `json:"message"`
Code int `json:"code"`
}
@asm-jaime
asm-jaime / pthreads.c
Created December 30, 2016 17:15
ping pong (threads) c
#include <stdio.h>
#include <pthread.h>
void *ping_task(char *arg)
{
printf("ping %s", arg);
usleep(1);
return (NULL);