Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Chen vvasabi

View GitHub Profile
View longest-palindrome.js
var Substring = function(s, e) {
this.s = s;
this.e = e;
this.l = e - s;
};
var longestPalindromeFromOffset = function(s, i) {
var j,
long = new Substring(0, 1);
for (j = 1; (j <= (s.length - i)) && ((i - j) >= 0); j++) {
@vvasabi
vvasabi / passgen.sh
Last active Dec 31, 2015
A bash script that generates a random password and copies it to pastebook.
View passgen.sh
#!/bin/bash
LENGTH=16
if [ "$#" -gt 0 ]; then
LENGTH="$1"
fi
# from: https://gist.github.com/earthgecko/3089509
RESULT=`cat /dev/urandom \
| LC_CTYPE=C tr -dc 'a-zA-Z0-9-.?~!@#$%^&*' \
@vvasabi
vvasabi / Gemfile
Last active Oct 23, 2015
Use SassC in Middleman 3.x. (Also see: https://rubygems.org/gems/middleman3-sassc)
View Gemfile
gem 'sassc', '~> 1.7.1'
gem 'sassc-rails', '~> 1.1.0'
@vvasabi
vvasabi / antigremlin.php
Created Oct 7, 2014
Remove Photoshop gremlins. Use it like so: pbpaste | php antigremlin.php | pbcopy.
View antigremlin.php
<?php
function remove_gremlins($str) {
$cleaned = '';
for ($i = 0, $max = strlen($str); $i < $max; $i++) {
$char_str = substr($str, $i, 1);
$char = ord($char_str);
if (($char >= 32) || ($char == 13)) { // new line or printable chars
$cleaned .= $char_str;
}
@vvasabi
vvasabi / makefast.sh
Last active Aug 29, 2015
Emulate slower Internet speed. (Apple also provides a free Network Link Conditioner pref pane that does the same thing.)
View makefast.sh
#!/bin/bash
# Make Internet connection fast again
sudo ipfw delete 1
sudo ipfw delete 2
sudo ipfw delete 3
sudo ipfw delete 4
@vvasabi
vvasabi / capture-screenshots.sh
Created Jun 11, 2014
Automated CutyCapt site screenshots generation
View capture-screenshots.sh
#!/bin/bash
dir="$HOME/capture"
output="$dir/output"
urls=`cat "$dir/list.txt"`
i=1
for url in $urls; do
# Convert url to file name
path=`echo $url | sed -e 's/http:\/\/domain\.name\///g'`
@vvasabi
vvasabi / _font.scss
Last active Aug 29, 2015
IE8-compatible font style mixin that uses rem unit.
View _font.scss
$root-font-size: 16px;
@mixin font($size, $line-height, $weight: null) {
font-size: $size; // IE fix
font-size: ($size / $root-font-size) * 1rem;
@if $weight != null {
font-weight: $weight;
}
line-height: $line-height;
}
@vvasabi
vvasabi / BeanPropertyOverrideConfigurer.java
Created Mar 26, 2014
Instead of being able to override properties in any beans, this variant of PropertyOverrideConfigurer restricts property overriding to just 1 specified bean.
View BeanPropertyOverrideConfigurer.java
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
public class BeanPropertyOverrideConfigurer extends PropertyOverrideConfigurer {
private String beanName;
public String getBeanName() {
return beanName;
@vvasabi
vvasabi / CutyCapt.cpp.diff
Last active Feb 24, 2016
Make it possible to make CutyCapt output pngs with transparent background. Just add --no-background=on in parameter.
View CutyCapt.cpp.diff
Index: CutyCapt.cpp
===================================================================
--- CutyCapt.cpp (revision 10)
+++ CutyCapt.cpp (working copy)
@@ -363,6 +363,7 @@
" --js-can-access-clipboard=<on|off> Script clipboard privs (default: unknown)\n"
#if QT_VERSION >= 0x040500
" --print-backgrounds=<on|off> Backgrounds in PDF/PS output (default: off) \n"
+ " --no-background=<on|off> Transparent background (as opposed to white background) (default: off) \n"
" --zoom-factor=<float> Page zoom factor (default: no zooming) \n"
@vvasabi
vvasabi / mvn-ep.sh
Last active Dec 11, 2015
This script wraps around mvn -ep to take password without it being revealed.
View mvn-ep.sh
#!/bin/bash
# This script wraps around mvn -ep to take password without it being revealed.
echo -n "Password: "
read -s password
echo ""
mvn -ep "$password"