Skip to content

Instantly share code, notes, and snippets.

@jkeroes
jkeroes / perlbrew perl install with libs.markdown
Last active November 19, 2019 17:26
Build Perl with perlbrew, libs, and cpanm

Install Perlbrew with the system perl

curl -L http://install.perlbrew.pl | bash

Initialize Perlbrew

mkdir /opt/perlbrew
export PERLBREW_ROOT=/opt/perlbrew
export PERLBREW_HOME=/opt/perlbrew

perlbrew init # and follow the directions

@tmbdev
tmbdev / usb0
Created June 13, 2013 10:00
Use expect to connect to a serial port (e.g., for Arduino)
#!/usr/bin/expect -f
# device
set modem /dev/ttyUSB0
# keep it open
exec sh -c "sleep 3 < $modem" &
# serial port parameters
exec stty -F $modem 9600 raw -clocal -echo -istrip -hup
@yesmeck
yesmeck / core.sh
Last active December 26, 2018 14:30
Sunspot create solr core
# 假设新建一个叫 core1 的 core
mkdir -p /path/to/core1/data
cd /path/to/project
cp -r `bundle show sunspot_solr`/solr/solr/conf /path/to/core1
bundle exec rake sunspot:solr:start
@theapi
theapi / knock.py
Last active November 27, 2018 01:11
Simple demo to detect knocking from a piezo sensor on the Raspberry Pi.
#!/usr/bin/python
import time, signal, sys
from Adafruit_ADS1x15 import ADS1x15
def signal_handler(signal, frame):
print 'You pressed Ctrl+C!'
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
#print 'Press Ctrl+C to exit'
@stereoscott
stereoscott / active_admin.rb
Last active March 15, 2020 10:47
Stream CSV exports in ActiveAdmin in Rails 4
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
@backflip
backflip / config.rb
Last active July 11, 2017 14:53
Using Redcarpet and Middleman Syntax for Markdown and HAML files
class CustomMarkdown < Middleman::Extension
$markdown_options = {
autolink: true,
fenced_code_blocks: true,
no_intra_emphasis: true,
strikethrough: true,
tables: true,
hard_wrap: true,
with_toc_data: true
}
@datenimperator
datenimperator / sqlite.rb
Created November 22, 2013 16:19
Speed up your Rails sqlite database for large dataset. This should be a Rails initializer, goes into config/initializers.
if ::ActiveRecord::Base.connection_config[:adapter] == 'sqlite3'
if c = ::ActiveRecord::Base.connection
# see http://www.sqlite.org/pragma.html for details
# Page size of the database. The page size must be a power of two between 512 and 65536 inclusive
c.execute 'PRAGMA main.page_size=4096;'
# Suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file
c.execute 'PRAGMA main.cache_size=10000;'
@rothgar
rothgar / main.yml
Last active March 8, 2024 07:16
Generate /etc/hosts with Ansible
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']

Keybase proof

I hereby claim:

  • I am anantn on github.
  • I am anant (https://keybase.io/anant) on keybase.
  • I have the public key with fingerprint 42DD 4F90 7C5F 4576 D6F4  2202 C31C 2D8C 7B4B 6B02

To claim this, I am signing this object:

@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote