Skip to content

Instantly share code, notes, and snippets.

View humoyun's full-sized avatar
:atom:
Always Eager

Humoyun humoyun

:atom:
Always Eager
View GitHub Profile
@yumminhuang
yumminhuang / package_updates_check.py
Created March 18, 2015 20:39
Python script to check apt-get updates
#!/usr/bin/env python
#coding=utf-8
import apt
import apt_pkg
from time import strftime
import os
import subprocess
import sys
@davidtimmerman
davidtimmerman / RestProxyTemplate.java
Last active February 13, 2024 08:33
Spring RestTemplate with proxy settings
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
@ibussieres
ibussieres / upgrade_pg.sh
Last active May 26, 2021 04:29
Upgrade PostgreSQL 9.1 to 9.3 on Ubuntu 12.04
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
@joyrexus
joyrexus / README.md
Last active August 21, 2023 16:59
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.

@ichord
ichord / gist:9808444
Created March 27, 2014 14:12
demo of using pdf.js to extract pages to images
<script src="http://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing-api.min.js"></script><html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/pdfjs-helloworld-v2/8598/edit
-->
<body>
<canvas id="the-canvas" style="border:1px solid black"></canvas>
<input id='pdf' type='file'/>
<!-- Use latest PDF.js build from Github -->
@deandob
deandob / livestream
Created February 26, 2014 22:31
Node.JS function to remux mp4/h.264 video from an IP camera to a HTML5 video tag using FFMPEG
// Live video stream management for HTML5 video. Uses FFMPEG to connect to H.264 camera stream,
// Camera stream is remuxed to a MP4 stream for HTML5 video compatibility and segments are recorded for later playback
var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance
// For live streaming, create a fragmented MP4 file with empty moov (no seeking possible).
var reqUrl = url.parse(req.url, true)
var cameraName = typeof reqUrl.pathname === "string" ? reqUrl.pathname.substring(1) : undefined;
if (cameraName) {
try {
cameraName = decodeURIComponent(cameraName);
@pbojinov
pbojinov / README.md
Last active December 8, 2023 21:09
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@lengstrom
lengstrom / doSegmentsIntersect.js
Created January 19, 2014 01:46
Algorithm for checking whether two line segments intersect, written in Javascript.
function intersect(x1, y1, x2, y2, x3, y3, x4, y4){
var a1, a2, b1, b2, c1, c2;
var r1, r2 , r3, r4;
var denom, offset, num;
// Compute a1, b1, c1, where line joining points 1 and 2
// is "a1 x + b1 y + c1 = 0".
a1 = y2 - y1;
b1 = x1 - x2;
c1 = (x2 * y1) - (x1 * y2);
@tmcw
tmcw / json.md
Created August 15, 2013 20:27
Why JSONP is a terrible idea and I will never use it again

Moral Concerns

JSONP is not actually JSON with padding, it's Javascript code that's executed. JSON is not a real subset of Javascript and the way it is not is important to us: via UTFGrid, we are all UTF-8 masters.

JSONP is not safe: it's Javascript that's executed. It's trivial to XSS with JSONP, because JSONP is XSS. Just have a call like mapbox.load('foo.tilejson', …) and if foo.tilejson gets replaced with destroyYoursite(), it gets run. Compare to JSON.parse, which is, on purpose, not eval.

Practical Concerns

JSONP is questionable in terms of performance. To be fast, you want to have the same callback all the time so that you can cache the response. But this leads to a page like

@jackiekazil
jackiekazil / rounding_decimals.md
Last active January 17, 2024 12:29
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value