Skip to content

Instantly share code, notes, and snippets.

View vvasabi's full-sized avatar

Brad Chen vvasabi

View GitHub Profile
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 December 31, 2015 16:36
A bash script that generates a random password and copies it to pastebook.
#!/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 October 23, 2015 15:27
Use SassC in Middleman 3.x. (Also see: https://rubygems.org/gems/middleman3-sassc)
gem 'sassc', '~> 1.7.1'
gem 'sassc-rails', '~> 1.1.0'
@vvasabi
vvasabi / antigremlin.php
Created October 7, 2014 18:30
Remove Photoshop gremlins. Use it like so: pbpaste | php antigremlin.php | pbcopy.
<?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 August 29, 2015 14:04
Emulate slower Internet speed. (Apple also provides a free Network Link Conditioner pref pane that does the same thing.)
#!/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 June 11, 2014 16:54
Automated CutyCapt site screenshots generation
#!/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 August 29, 2015 14:02
IE8-compatible font style mixin that uses rem unit.
$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 March 26, 2014 18:55
Instead of being able to override properties in any beans, this variant of PropertyOverrideConfigurer restricts property overriding to just 1 specified bean.
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 February 24, 2016 11:28
Make it possible to make CutyCapt output pngs with transparent background. Just add --no-background=on in parameter.
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 December 11, 2015 11:48
This script wraps around mvn -ep to take password without it being revealed.
#!/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"