Skip to content

Instantly share code, notes, and snippets.

View jesseky's full-sized avatar
🌴
On vacation

Jesse jesseky

🌴
On vacation
  • 中国 深圳
View GitHub Profile
@jesseky
jesseky / ip.js
Created July 15, 2021 02:38
js convert ip to int, int to ip
const ip2int = ip => ip.split('.').reverse().map((v, i) => +v << (8 * i)).reduce((s, a) => s | a);
const int2ip = it => it.toString(2).padStart(32, 0).match(/.{8}/g).map(v => parseInt(v, 2)).join('.');
// test
console.log(ip2int(`127.0.0.1`)); // 2130706433
console.log(int2ip(2130706433)); // 127.0.0.1
@jesseky
jesseky / CertificateGeneration.sh
Created January 10, 2018 03:25 — forked from sandfox/CertificateGeneration.sh
TLS certificate inspection example (using nodejs)
###
#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
@jesseky
jesseky / Excel.php
Created December 9, 2017 09:18 — forked from ihumanable/Excel.php
Simple Excel Writer in PHP
<?php
/**
* Simple excel writer class with no external dependencies, drop it in and have fun
* @author Matt Nowack
* @link https://gist.github.com/ihumanable/929039/edit
* @license Unlicensed
* @version 1.0
*/
class Excel {
@jesseky
jesseky / main.swift
Created November 5, 2016 17:10
swift3 post/upload file example
//
// main.swift
// test-swift3
//
// Created by jesse on 2016/11/5.
// Copyright © 2016年 jesse. All rights reserved.
//
// #!/usr/bin/env swift
import Foundation
@jesseky
jesseky / KFetch.swift
Created May 7, 2016 04:32
swift http请求类
import Foundation
class KFetch {
let session: NSURLSession = NSURLSession.sharedSession()
// url安全编码
func escape(str: String) -> String {
let characterSet = NSMutableCharacterSet.alphanumericCharacterSet()
characterSet.addCharactersInString("-._ ")
if #available(iOS 8.3, *) {
return str.stringByAddingPercentEncodingWithAllowedCharacters(characterSet)!.stringByReplacingOccurrencesOfString(" ", withString: "+")
@jesseky
jesseky / setting-wall.sh
Created April 20, 2016 07:48
Linux gnome设置壁纸
dir='/home/kirigayaloveyousei/Wallpaper/'
while :; do
for d in $(ls -F $dir|grep /); do
for f in $(ls $dir$d); do
gsettings set org.gnome.desktop.background picture-uri file://$dir$d$f
echo "正在设置壁纸,壁纸来自:" $dir$d$f
sleep 60
done
done
done
@jesseky
jesseky / escape.swift
Last active April 18, 2016 08:29
swift url or post data escape / swift post数据转义
func escape(str: String) -> String {
let characterSet = NSMutableCharacterSet.alphanumericCharacterSet()
characterSet.addCharactersInString("-._ ")
if #available(iOS 8.3, *) {
return str.stringByAddingPercentEncodingWithAllowedCharacters(characterSet)!.stringByReplacingOccurrencesOfString(" ", withString: "+")
}
let length = str.characters.count
let num = 50
let times = length > (length / num * num) ? length / num + 1 : length / num
var result = ""
@jesseky
jesseky / dataURItoBlob.js
Created March 6, 2016 12:26
Canvas DataURItoBlob
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
var ab = new ArrayBuffer(byteString.length);
var dw = new DataView(ab);
for (var i = 0; i < byteString.length; i++) {
dw.setUint8(i, byteString.charCodeAt(i));
}
return new Blob([ab], {type: mimeString});
}
@jesseky
jesseky / callbacks.js
Created December 21, 2015 07:19
node.js callback after all callbacks excuted
#!/usr/bin/env node
var FS = require('fs');
var pending = callback => {
var count = 0;
var returns = {};
console.log("Start cound: %d", count);
return key => { // a function done
count++;
@jesseky
jesseky / 0_reuse_code.js
Created December 21, 2015 06:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console