Skip to content

Instantly share code, notes, and snippets.

import 'dart:convert';
void main() {
// Json obtained through some api:
const jsonString = '[{"page":1, "items": [1, 2]}, {"page":2, "items": [3, 4]}]';
final items = json.decode(jsonString);
final x = items.expand((p) => p['items']);
//final x = items.expand((p) => p['items'] as List<int>);
//final x = items.expand((p) => p['items'].map((i) => i as int));
//final x = items.map((p) => p['items'] as List).toList().expand((i) => i).toList();
@charlieman
charlieman / wtiler.py
Last active March 1, 2022 01:32
Tool for tiling windows in X11
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The MIT License (MIT)
#
# Copyright (c) 2015 Carlos Zúñiga
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@charlieman
charlieman / WindowStateSaveHelper.cs
Created May 10, 2014 21:24
Save and restore a Window's Position, Size and State
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace WindowStateSave
{
/// <summary>
/// Helper class that saves the window's state to a User Settings string
@charlieman
charlieman / NumberToLocalizedStringTransformer.php
Created September 26, 2012 21:37
NumberType override to use 'en' locale in the NumberFormatter to allow for dot as the decimal separator
<?php
namespace Redeye\CuyBundle\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer as BaseTransformer;
class NumberToLocalizedStringTransformer extends BaseTransformer
{
/**
* {@inheritdoc}
*/
@charlieman
charlieman / .bash_completion
Created August 24, 2011 21:37
bash completion for Symfony2's console requires xmlstartlet to work
_symfony2()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(app/console list --xml | xmlstarlet sel -t -m "//namespaces//command" -v . -o " " | tr ":" "\:")
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
@charlieman
charlieman / sfconsole.sh
Created August 17, 2011 15:31
Run the Symfony2 console from anywhere inside your project
#!/bin/bash
#from http://vvv.tobiassjosten.net/symfony/symfony2-cli-bash-script
PWD=$(pwd)
while [ "$PWD" != '/' ]; do
if [ -f "$PWD/app/console" ]; then
php "$PWD/app/console" $@
exit
@charlieman
charlieman / oplop.py
Created August 15, 2011 22:34
One file command line version of oplop (http://oplop.googlecode.com/), added option to generate passphrases with -p
#!/usr/bin/env python
# "Generate account passwords based on an account name and a master password."
from __future__ import print_function
try:
import argparse
except ImportError:
from . import argparse
try:
@charlieman
charlieman / gitls.py
Created May 1, 2011 18:46
Script that shows a list of all files in a git repo and the date and message of the last commit on it
#!/usr/bin/env python
import git
from email.utils import parsedate_tz
from time import strftime
def tree_walk(tree, path=''):
for name, obj in tree.items():
if isinstance(obj, git.Tree):
for filename in tree_walk(obj, name):