Skip to content

Instantly share code, notes, and snippets.

@lchanmann
lchanmann / munin_apache.sh
Created August 4, 2016 22:17
Update apache configuration for munin
sudo vi /etc/munin/apache.conf
# Search and replace “Allow from localhost …” to “Allow from all”
sudo service apache2 restart
@lchanmann
lchanmann / index.html
Last active August 4, 2016 22:36
colorPicker and KnockoutJs integration
<!-- assume jQuery, KnockoutJs and index.js are already loaded -->
<input type="text" data-bind="colorPicker:color" />
<script>
ko.bindingHandlers.colorPicker = {
init: function(element, valueAccessor) {
var value = valueAccessor();
$(element).val(ko.utils.unwrapObservable(value));
$(element).colorPicker();
$(element).change(function() { value(this.value); });
@lchanmann
lchanmann / mysql_show_engine.txt
Created August 4, 2016 22:39
No InnoDB in mysql
+ — — — — — — + — — — — -+ — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — + — — — — — — — + — — — + — — — — — — +
| Engine | Support | Comment | Transactions | XA | Savepoints |
+ — — — — — — + — — — — -+ — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — + — — — — — — — + — — — + — — — — — — +
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
@lchanmann
lchanmann / thumbnail.rb
Created August 4, 2016 22:43
RMagick thumbnail
require 'RMagick'
img = Magick::Image.read("photo.jpg").first
scale_factor = 20.0 / [img.rows, img.columns].max
thumbnail = img.thumbnail(scale_factor)
thumbnail.border! 1, 1, 'gray60'
thumbnail.border! 1, 1, 'red'
thumbnail.write "photo_thumbnail.jpg"
Building native extensions. This could take a while…
ERROR: Error installing libxml-ruby:
 ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
checking for socket() in -lsocket… no
checking for gethostbyname() in -lnsl… yes
checking for atan() in -lm… no
checking for atan() in -lm… yes
checking for inflate() in -lz… no
@lchanmann
lchanmann / DatabaseFixture.cs
Created August 4, 2016 23:17
DatabaseFixture.cs
public class DatabaseFixture
{
public TransactionScope transactionScope;
public DatabaseFixture()
{
ConnectionString = "Your ConnectionString";
}
public string ConnectionString { get; set; }
@lchanmann
lchanmann / javac_error_1.txt
Created August 23, 2016 22:12
JMinitest: First failing test
Program.java:3: error: cannot find symbol
LinkedList list = new LinkedList();
^
symbol: class LinkedList
location: class Program
Program.java:3: error: cannot find symbol
LinkedList list = new LinkedList();
^
symbol: class LinkedList
location: class Program
@lchanmann
lchanmann / Program.java
Last active August 23, 2016 22:14
JMinitest: First failing test
public class Program {
public static void main(String[] args) {
LinkedList list = new LinkedList();
assert list.size() == 0 : "Expected 0 but was " + list.size();
// All tests are passed!
System.out.println("All tests are passed!");
}
}
@lchanmann
lchanmann / Program.java
Created August 23, 2016 22:35
JMinitest: assert linklist's head and tail
public class Program {
public static void main(String[] args) {
LinkedList list = new LinkedList();
assert list.size() == 0 : "Expected 0 but was " + list.size();
assert list.getHead() == null : "Expecte null but was " + list.getHead();
assert list.getTail() == null : "Expecte null but was " + list.getTail();
// All tests are passed!
System.out.println("All tests are passed!");
}
public class Program {
public static void main(String[] args) {
LinkedList list = new LinkedList();
// Previous test is hidden to save writing spaces
list.add(1); list.add(2); list.add(3);
assert list.size() == 3 : "Expected 3 but was " + list.size();
assert list.getHead().value == 1 : "Expecte 1 but was " + list.getHead().value;
assert list.getTail().value == 3 : "Expecte 3 but was " + list.getTail().value;
// All tests are passed!