Skip to content

Instantly share code, notes, and snippets.

@ynonp
ynonp / README.md
Last active July 28, 2017 07:10
react-rails and redux

react-rails and Redux

The main issue I found when integrating react-rails and flux/redux is managing application state. In redux I'd like to have a single application state serialized from the server and parsed in the client, and to use that state to initialize the main store. Something like:

initialState = JSON.parse(window.__APPSTATE__);

But that won't work since react-rails splits its work to 2 phases: it first reads all .js files in the renderer initialize phase and every call to the view helper only calls render.

Solution is described below by using a new renderer that:

@ynonp
ynonp / sub.pl
Created July 5, 2015 06:53
subroutine demo
use strict;
use warnings;
use v5.08;
sub say {
print @_, "\n";
}
say("Hello");
@ynonp
ynonp / main.cpp
Created June 20, 2015 15:42
Range iterator
#include <QCoreApplication>
#include "range.h"
#include <QDebug>
#include <QtCore>
#include <QtConcurrent>
static const char ab[] = "0123456789abcdefghijklmnopqrstuvwxyz";
@ynonp
ynonp / main.clj
Created June 20, 2015 08:08
clojure demo
(ns clojure-noob.core
(:gen-class))
(require 'digest)
(defn exp [x n]
(reduce * (repeat n x)))
(defn char_at [ab i d]
(ab (rem
#!/usr/bin/env csh -f
# Also supported: <, >, <=, >=
if ( $# > 2 ) echo "So many arguments"
# Also supported: +, -, *, /
if ( $# % 2 == 0 ) echo "Can also use math"

Unix Scripting Lab

Part 1: Getting Parameters

  1. Take a directory name and a file name. Create the directory and then create the file inside.
  2. Take a user name and print all processes from that user
  3. Write a shell script that reads a file name from the user, prints its contents and the number of lines in the file.

Part 2: Conditionals

@ynonp
ynonp / mojolicious-url-shortener.pl
Created March 5, 2015 21:13
A url shortener written in Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Util qw/b64_encode b64_decode/;
use DBI;
my $database = 'tinyurl.db';
my $data_source = "dbi:SQLite:dbname=$database";
my $dbh = DBI->connect(
$data_source,
#include "mainwindow.h"
#include <QApplication>
#include <QtWidgets>
void createFirstRow(QVBoxLayout *top)
{
QGroupBox *box = new QGroupBox();
QPushButton *b1 = new QPushButton("One", box);
QPushButton *b2 = new QPushButton("Two", box);
QPushButton *b3 = new QPushButton("Three", box);
myapp/
├── lib
│   ├── File
│   │   └── Slurp.pm
│   ├── MyModule.pm
│   └── Try
│   └── Tiny.pm
└── run.pl
3 directories, 4 files
package Critter;
use strict;
use warnings;
use v5.18;
# Critter
our $VERSION = '1.00';
#
# Inheritance
# our @ISA = qw/Animal/;