Skip to content

Instantly share code, notes, and snippets.

View shuson's full-sized avatar
🎯
Focusing

Nevermoi shuson

🎯
Focusing
View GitHub Profile
@shuson
shuson / Puppet&Chef.md
Last active August 29, 2015 14:21
New stuff on 14th May 2015

Puppet, from Puppet Labs

It is a configuration management tool that helps system administrators automate the provisioning, configuration, and management of a server infrastructure.

Chef

It is a systems and cloud infrastructure automation framework that makes it easy to deploy servers and applications to any physical, virtual, or cloud location, no matter the size of the infrastructure. Each organization is comprised of one (or more) workstations, a single server, and every node that will be configured and maintained by the chef-client. Cookbooks (and recipes) are used to tell the chef-client how each node in your organization should be configured. The chef-client (which is installed on every node) does the actual configuration.

@shuson
shuson / getSSLCertInfo.js
Created April 15, 2015 10:09
get ssl certificate information by nodejs
var https = require('https');
https.get('https://www.douban.com/', function(res) {
console.log("cert info: ", res.socket.getPeerCertificate());
}).on('error', function(e) {
console.error(e);
});
//that's it, but no Official API shows socket has ''getPeerCertificate'' function
@shuson
shuson / sample.js
Last active September 19, 2023 08:50
get base64 raw data of image from responseBody using jquery ajax
$.ajax({
type: "GET",
url: "imageURL",
beforeSend: function (xhr) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
},
success: function (result, textStatus, jqXHR) {
if(result.length < 1){
alert("The thumbnail doesn't exist");
$("#thumbnail").attr("src", "data:image/png;base64,");
@shuson
shuson / stopwords
Created December 26, 2014 10:26
StopWords list based on Rainbow statistical text
a
able
about
above
according
accordingly
across
actually
after
afterwards
@shuson
shuson / generateUUID
Created December 5, 2014 07:08
To generate a simple UUID using javascript
function generateUUID(){
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
});
return uuid;
};
@shuson
shuson / kmp_alg
Created October 29, 2014 08:16
The KMP Algorithm implementation in Python
def buildPMT(s):
"""
PartialMatchTable of string s
"""
prefix = [s[:i+1] for i in range(len(s)-1)]
postfix = [s[i+1:] for i in range(len(s)-1)]
intersection = list(set(prefix) & set(postfix))
if intersection:
return len(intersection[0])
return 0
@shuson
shuson / DatetimeDiffWithFormat
Created July 18, 2014 08:01
Calculate Datetime difference with output in this format "xx year(s) xx month(s) xx day(s)"
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.joda.time.Period;
class DatetimeDiffWithFormat{
/**
* @param DateTime start
* @param DateTime end
* @param UnitDMYENUM unit
@shuson
shuson / Trader.java
Created June 19, 2014 08:29
Merchant's Guide To The Galaxy Solution
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@shuson
shuson / description-mysql_weakly-referenced object
Last active April 26, 2024 13:04
weakly-referenced object when connect to mysql in python
I came across this issue using the following code file
the error message is ReferenceError: weakly-referenced object no longer exists
reason is in the mysql/connector/cursor.py file
see these lines:
def _set_connection(self, connection):
"""Set the connection"""
try:
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select