Skip to content

Instantly share code, notes, and snippets.

@tonis2
tonis2 / gist:23ba5a12af009f25152a
Created July 30, 2015 14:47
Uninstall all npm modules
npm ls | grep -v 'npm@' | awk '/@/ {print $2}' | awk -F@ '{print $1}' | xargs npm rm
@tonis2
tonis2 / gist:0b222d4308457d611745
Last active October 15, 2015 13:54
es6 Map function
let numbers = [6, 3, 9];
function map(data,func){
let numbers = [];
for (let i in data){
let as = func(data[i]);
numbers.push(as);
}
return numbers;
}
@tonis2
tonis2 / gist:e39a16d198b689d80a8c
Created February 25, 2016 10:45
Pulling feed
const PULL_DATA= 'PULL_DATA'
import agent from 'superagent'
const initialState = {
apiFeed:[],
loaded:false
};
export default function Data(state = initialState, action) {
switch (action.type) {
@tonis2
tonis2 / gist:1fdcac7a986ad37f259fb6f887296e76
Created April 15, 2016 14:36
random draft.js experiments
import React, {PropTypes} from 'react';
import {Editor, AtomicBlockUtils, Entity, EditorState, Modifier, RichUtils, convertToRaw} from 'draft-js'
import isClient from 'check-client'
const colorStyleMap = {
red: {
color: 'rgba(255, 0, 0, 1.0)',
},
blue: {
color: 'rgba(0, 0, 255, 1.0)',
let style = {
transform: `translate(${index*2}px, 0 )`,
transform: `rotate(${index*2}px, 0 )`,
boxShadow:`1px 1px 1px 2px ${index}px`
};
return <section key={index} id="card-container" style={style}>
<div id="card">
<p>{card}</p>
</div>
</section>
server {
listen 443 ssl;
server_name url.pw www.url.pw;
ssl_certificate /etc/letsencrypt/live/scarystories.pw/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/scarystories.pw/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
@tonis2
tonis2 / gist:071e662ac50e809775e44ce93c1d426b
Created October 11, 2016 15:51
remove duplicates from array
const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
const count = names =>
names.reduce((a, b) =>
Object.assign(a, {[b]: (a[b] || 0) + 1}), {})
const duplicates = dict =>
Object.keys(dict).filter((a) => dict[a] > 1)
console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
@tonis2
tonis2 / gist:8b68e4034f22d619dc39a1f91b47fbdb
Last active October 23, 2016 17:32
mutate rust struct
#![allow(dead_code)]
struct Car {
name: String,
seats: i32,
speed: i32,
}
impl Car {
fn drive(&self) {
println!("{name} drives at speed: {speed} km/h", speed = self.speed, name = self.name);
@tonis2
tonis2 / convert_features_opencv_traincascade.py
Created December 26, 2016 19:47 — forked from mtschirs/convert_features_opencv_traincascade.py
Converting the new OpenCV haar cascades into the js-objectdetect format.
import xml.etree.ElementTree
'''
Classifier - array layout:
[width, height, threshold, num_simple_classifiers, tilted, num_features, f1, f2, f3, f4, f_weight, simple_threshold, left_val, right, val, ...]
'''
wrapper = "(function(module) {\n" + \
" \"use strict\";\n" + \
" \n" + \
@tonis2
tonis2 / index.html
Created March 5, 2017 12:50 — forked from tmichel/index.html
simple websocket example with golang
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<div>
<form>
<label for="numberfield">Number</label>
<input type="text" id="numberfield" placeholder="12"/><br />