Skip to content

Instantly share code, notes, and snippets.

@krusynth
krusynth / rename.sh
Created December 6, 2014 17:54
file rename bash
# Find a *lot* of files with the wrong extension and fix the extension.
for myfile in $(find /var/www/releases/sanfranciscocode/*/production/current/htdocs/downloads/current/code-text -name "*..txt" -type f); do
filetrim=${myfile%????};
mv $myfile $filetrim"txt";
done;
@krusynth
krusynth / .bash_profile
Created December 8, 2014 00:49
Bash script to delete all documents from a Solr core.
# Put this at the end of your .bash_profile.
#
# Usage: clearsolr corename
clearsolr() {
curl http://localhost:8983/solr/$1/update -H "Content-type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
curl http://localhost:8983/solr/$1/update -H "Content-type: text/xml" --data-binary '<commit />'
curl http://localhost:8983/solr/$1/update -H "Content-type: text/xml" --data-binary '<optimize />'
curl http://localhost:8983/solr/$1/update -H "Content-type: text/xml" --data-binary '<commit />'
}
@krusynth
krusynth / DocumentController.js
Created December 8, 2014 21:56
Sails.js Controller using etherpad-lite-client
var etherpad_client = require('etherpad-lite-client');
module.exports = {
/**
* list() - list all docs
*/
list: function(req, res) {
etherpad_api = etherpad_client.connect({
apikey: sails.config.connections.etherpad.apikey,
host: sails.config.connections.etherpad.host,
@krusynth
krusynth / indexSpec.js
Created January 21, 2015 15:24
Example using Squire for Dependency injection.
define(['squire'], function (Squire) {
"use strict";
describe("DashboardIndexController", function () {
var context = {};
var ready = false;
beforeEach(function () {
runs(function () {
context.injector = new Squire();
@krusynth
krusynth / date-query.txt
Created May 12, 2015 13:52
Handling multifield dates. Please don't do this. It's bad - unmanageable, unreadable.
mysql> desc testdates;
+-------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| year | smallint(5) unsigned | YES | | NULL | |
| month | tinyint(3) unsigned | YES | | NULL | |
| day | tinyint(3) unsigned | YES | | NULL | |
+-------+----------------------+------+-----+---------+----------------+
#!/bin/bash
#
# solr APACHE SOLR 4.10
#
# chkconfig: 2345 85 15
# description: Startup Script for APACHE SOLR 4.10
#
# processname: solr
@krusynth
krusynth / example.php
Created June 7, 2015 21:54
Use Wordpress login system on a custom PHP page.
/**
* Example of php code using Wordpress' login.
*/
require_once '../pages/wp-blog-header.php';
// If the user is not authorized, redirect to the Wordpress login.
auth_redirect();
// Your code here
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
@krusynth
krusynth / gorky.txt
Created August 17, 2015 23:26
Maxim Gorky's Reminiscences of Leo Tolstoy
"You hammer away like a parrot at one word, freedom, freedom; but what is the sense of it? If you attained your freedom, what do you imagine would happen? In the philosophic sense, a bottomless void, and in actual life you would become an idler, a parasite. If you were free in your sense, what would bind you to life or to people? Now, birds are free, but still they build nests; you, however, wouldn't even build a nest, but would gratify your sexual feeling anywhere, like a dog. You think seriously, and you will come to see, you will come to feel, that this freedom is ultimately emptiness, boundlessness... Christ was free and so was Buddha, and both took on themselves the sins of the world and voluntarily entered the prison of earthly life. Further than that nobody has gone, nobody. And you—we—well, what's the good of talking—we are all looking for freedom from obligations towards our fellow men, whereas it is just that feeling of our obligations which has made us men, and, if those obligations were not there,
@krusynth
krusynth / style.less
Created March 28, 2012 01:45
CSS Responsive Framework Less
/*
NOTE: There's some magic going on in .cols() to add a negative right margin.
This resolves the the inline-block issue for uncompressed html. However,
it shouldn't be here - you should minify your html instead. This will
be removed in the immediate future.
This is the core framework for the site.
It implements the baseline LESS CSS Mixins and general style rules.