Skip to content

Instantly share code, notes, and snippets.

View jostyee's full-sized avatar
💭
脑壳疼

Josta Yee jostyee

💭
脑壳疼
  • Singapore
View GitHub Profile
public int clearBits(int num, int i) {
int mask = (1 << i) - 1;
return num & mask;
}
int
binary_search_first_position(int *A, int n, int target) {
int end[2] = { -1, n };
while (end[0] + 1 < end[1]) {
int mid = (end[0] + end[1]) / 2;
int sign = (unsigned)(A[mid] - target) >> 31;
end[1-sign] = mid;
}
int high = end[1];
if (high >= n || A[high] != target)
@zzamboni
zzamboni / Evernote - List tags that have a single note.scpt
Created January 14, 2015 06:05
Find all single-note tags in Evernote
(*
Evernote -- Find all single-note tags
January 13, 2015, Diego Zamboni
http://zzamboni.postach.io/find-all-single-note-tags-in-evernote
Based on:
http://veritrope.com
Evernote -- Empty Tag Remover
http://veritrope.com/code/evernote-empty-tag-remover
*)
@Jamesits
Jamesits / discoveryd_checker.sh
Last active August 29, 2015 14:19
Check if discoveryd on OS X 10.10.3 has too high CPU usage and restart it.
#!/bin/bash
# Copyright (c) 2015, James Swineson <jamesswineson@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@github101
github101 / gist:3426232
Created August 22, 2012 14:39
提高MySQL数据的导出速度
在导出数据之前,先设置两个值 max_allowed_packet 128M~256M或者更大,参考内存的使用量;net_buffer_length 一般设置成16384。在使用mysqldump导出数据的时候增加两个三个参数 -e --max_allowed_packet=128M --=net_buffer_length=16384
@lg0
lg0 / gist:3481797
Last active October 9, 2015 09:37
解决 OSX 上原生 VPN (Cisco IPSec)每隔一小时要求输入密码的情况

解决方案来自:[Apple Support Communities] (https://discussions.apple.com/thread/3275811?start=0&tstart=0)

  1. 连接 VPN Cisco IPSec (让系统生成配置文件)
  2. 拷贝配置文件到/etc/racoon打开终端执行:
    $ sudo cp /var/run/racoon/xxx.xxx.xxx.xxx.conf /etc/racoon
  3. 修改 racoon 配置文件:
    $ sudo vim /etc/racoon/racoon.conf
  4. 将最后一行注释掉(目的是不使用系统生成配置):
    # include "/var/run/racoon/*.conf" ;
  5. 将下面一行添加到文件末尾,包含分号(使用定制的配置文件):
@than
than / userstyles.css
Last active July 31, 2016 12:58
Fluid userstyles for Overcast.fm
/**
* Userstyles for Overcast.fm Fluid app
* than.land
* Updated: 8/13/14
*/
/* Custom scroll bar */
html {
overflow: auto;
}
@nathany
nathany / checksum.go
Created August 11, 2016 23:09
Using MultiWriter to do two things at once
// copyAndChecksum calculates a checksum while writing to another output
func copyAndChecksum(w io.Writer, r io.Reader) (string, error) {
h := md5.New()
mw := io.MultiWriter(w, h)
if _, err := io.Copy(mw, r); err != nil {
return "", err
}
return hex.EncodeToString(h.Sum(nil)), nil
}
@ebuildy
ebuildy / ContainerImageRepository.php
Created February 1, 2017 10:43
Retrieve Gitlab projects with Docker container registry tags.
<?php
namespace AppBundle\Service;
class ContainerImageRepository
{
/**
* URL to container registry.
*
* @var string
@tsuna
tsuna / mysqlpool.scala
Created March 30, 2012 00:15
MySQL JDBC connection pool for Scala + Finagle
// Copyright (C) 2012 Benoit Sigoure
// Copyright (C) 2012 StumbleUpon, Inc.
// This library is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,