Skip to content

Instantly share code, notes, and snippets.

@nkint
nkint / gist:6b25cfbe11e6a0eb6ccb
Created November 21, 2014 12:01
Python listen new tweet direct message and put on Yun Bridge as key-value
from twitter import *
auth = OAuth(
consumer_key='2yiyIW2qqGfwblk1Tk8BqiygP',
consumer_secret='1FWJu5810Gng0QdZylIMZlA0v1aGsLv9muTh8xn5kouE4ZE6EV',
token='2886635781-2mXPbGqS6x3szeUjdjB50DGEcI9P2OOVWVCX13z',
token_secret='1SMDFRZdHqea5sKEzNQTVHdnUdFh7s5jDab2qNL1zTqKB'
)
t = Twitter(auth=auth)
@nkint
nkint / gist:5702a2dd7fdd853bcdd3
Created November 21, 2014 11:59
Arduino read the key-value from Bridge
#include <Bridge.h>
unsigned long timer;
unsigned long counter = 0L;
void setup()
{
Serial.begin(9600);
Bridge.begin(); // this launches /usr/bin/run-bride on Linino
timer = millis();
@nkint
nkint / gist:24426093c5e29a62803a
Created August 20, 2014 21:11
javascript: timestamp to human readable (hours, minutes, seconds)
// http://www.epochconverter.com
function TimeCounter(t) {
var days = parseInt(t / 86400);
t = t - (days * 86400);
var hours = parseInt(t / 3600);
t = t - (hours * 3600);
var minutes = parseInt(t / 60);
t = t - (minutes * 60);
###
#Step 1 - Generate server certificates etc... (most of this code is horribly ripped off from nodejs docs currently -> http://nodejs.org/docs/latest/api/tls.html)
###
#Assuming your starting from a clean directory
mkdir server
cd server
#generate private key
@nkint
nkint / gist:9496912
Created March 11, 2014 23:06
shell as your desk: list all files with a complete path
find `pwd`
@nkint
nkint / gist:9089157
Last active April 11, 2022 12:35
opengl in qt: render string to QImage to texture
void displayText(const QString &text, const QColor &backgroundColor, const QColor &textColor, const Vec3D &pos)
{
// some magic number (margin, spacing, font size, etc..)
int fontSize = 15;
int text_width=text.size()*(fontSize/1.5)+5, text_height=fontSize+20;
// create the QImage and draw txt into it
QImage textimg(text_width, text_height, QImage::Format_RGB888);
{
QPainter painter(&textimg);
@nkint
nkint / gist:8576156
Created January 23, 2014 10:15
opencv and python: concatenate video
import numpy as np
import cv2
import os
# this two lines are for loading the videos.
# in this case the video are named as: cut1.mp4, cut2.mp4, ..., cut15.mp4
videofiles = [n for n in os.listdir('.') if n[0]=='c' and n[-4:]=='.mp4']
videofiles = sorted(videofiles, key=lambda item: int( item.partition('.')[0][3:]))
video_index = 0
@nkint
nkint / gist:8563954
Last active September 7, 2023 05:18
ffmpeg in the shell: extracting the first frame of video
i=1
for avi in *.mp4; do
name=`echo $avi | cut -f1 -d'.'`
jpg_ext='.jpg'
echo "$i": extracting the first frame of the video "$avi" into "$name$jpg_ext"
ffmpeg -loglevel panic -i $avi -vframes 1 -f image2 "$name$jpg_ext"
i=$((i+1))
done
@nkint
nkint / gist:8176516
Created December 30, 2013 00:41
opencv: draw a small mat inside a larger mat
cv::Rect roi( cv::Point( originX, originY ), smallImage.size() );
smallImage.copyTo( bigImage( roi ) );
@nkint
nkint / gist:8144791
Last active January 1, 2016 12:29
opencv: turn black pixels into alpha 0
displayDebug = ....
// turn black pixels into alpha 0
if(displayDebug.channels()==1)
cv::cvtColor(displayDebug, displayDebug, CV_GRAY2BGR);
cv::cvtColor(displayDebug, displayDebug, CV_BGR2BGRA);
for (cv::Mat4b::iterator it = displayDebug.begin<cv::Vec4b>(); it != displayDebug.end<cv::Vec4b>(); it++) {
if (*it == cv::Vec4b(0, 0, 0, 255)) {
*it = cv::Vec4b(0, 0, 0, 0);
}